OKhub.org API Methods and Calls

Get Methods

Retrieve all items

This method allows you to retrieve all items – currently the first 10 records are displayed (with a link to the next 10)

Parameters: 

item_type
An item type (e.g. documents, themes, countries) Example values

  • documents
  • themes
  • countries
  • regions
  • organisations
  • subject
e.g. /hub/get_all/{item_type}

Retrieve single item

This method allows you to retrieve a single item

Parameters: 

item_id
An ID of single item Example values

  • 7111
e.g. /hub/get/documents/{item_id}

Search Methods

Search

This method allows you to search content across all fields. Note the search is not case-sensitive, although some other queries are case-sensitive. Results are returned in relevance rank sort order.

Parameters:

search_query
A search term Example values

  • UNDP
  • conflict
 e.g. /hub/search/documents/?q=governance

Field Search

This method allows you to search content within a specific field.

Parameters:

field
A specific field to search on Example values

  • country
search_query
A search term Example values

  • Kenya
e.g. /hub/search/documents/?{field}={search_query}

Wildcard searching

This method allows you to search content using a substitute character or wildcard. Note that you can use * in your query, but not as the first character.

Parameters:

field
A specific field to search on Example values

  • country
search_query
A search term Example values

  •  af*

 

but not *ca

e.g. /hub/search/documents/?{field}={search_query}

Search by date

This method allows you to search by date.

Parameters:

date_type
The date field to be queried on. Example values

  • timestamp
  • hub_timestamp
  • publication_year
  • date_created
date
The date Example values

  •  2014-01-01
e.g. /hub/search/documents/?q=UNDP&{date_type}={date}

Combining query fields

Query fields may be combined, so for example a free text search for ‘malaria’ could be combined with a country search for ‘Angola’. Note that query fields are always ANDed together as they use the query string.

Parameters:

search_query_1
A search term for the first field to be searched. Example values

  • malaria
field
The field to be queried on Example values

  •  country
search_query_2
A search term for the second field to be searched Example values

  •  Kenya
e.g. /hub/search/documents/?q={search_query_1}&{field}={search_query_2}

Combining query terms

Within each query field you can combine terms using either AND or OR using the & and | characters respectively. These characters must be URL encoded.
In this case & becomes %26 and | becomes %7C.

Parameters:

field
A field to be queried on. Example values

  • country
search_query_1
A search term for the first field to be searched. Example values

  • Angola
operator
Operator – url encoded values for AND / & (%26) or OR / | (%7C), Example values

  • %26
  • %7C
search_query_2
A search term for the second field to be searched Example values

  •  Kenya
e.g. /hub/search/documents/?{field}={search_query_1}{operator}{search_query_2}

Number of results

By default, the first 10 results are returned for any query. Additional query Parameters can be added to change this.
Note that the metadata section of the results will have links to the next and previous pages (assuming they exist). Also the maximum value for num_results is 500 .,

Parameters:

value
The number of results to return. If not specified then a value of 10 is used. Example values

  • 50
e.g. /hub/search/documents/?q=UNDP&num_results={value}

Offset start of results

By default, the results are returned at the first result for any query. Additional query parameters can be added to change this.
Note that the metadata section of the results will have links to the next and previous pages (assuming they exist).

Parameters:

value
The index of the result to start from. If not specified then a value of 0 is used. Example values

  • 50
e.g. /hub/search/documents/?q=UNDP&start_offset={value}

Sort Order

For general q= searching, the results are returned in relevance rank order. For all other searches the default sort order is date_created descending, which displays the most recently added object first. Sort order may be overridden, using the following parameters;

Parameters:

field
The fields which may be used for sorting. Example values

  • title
  • name
  • date_created
  • date_updatedNEW
  • publication_date
sort_order
 The method for sorting the results in order of the field named (e.g. ascending or descending. Example values

  • sort_asc
  • sort_desc
e.g. /hub/search/documents/?q=gender&{sort_order}={field}

 Response formats

Short or Full

Display the full or short version of the item

Parameters: 

short_full
The short or full version of the item Example values

  • short
  • full
e.g. /hub/search/documents/[short_full}?q=UNDP

Formats available

The data can be returned as JSON or as XML, with JSON as the default.

Parameters: 

format
The method for specifying the response format. Example values

  • xml
  • json
e.g. /hub/search/documents/?q=India&format={format}