For the complete documentation index, see llms.txt. This page is also available as Markdown.

Search and filter within dataset

This API allows you to search for data within a dataset or scan through the rows of the dataset in a paginated manner.

Note that the following API uses the domain: https://data.gov.sg

For example:

https://data.gov.sg/api/action/datastore_search

If you're looking to query the following dataset: https://data.gov.sg/datasets/d_8b84c4ee58e3cfc0ece0d773c8ca6abc/view Please refer to the URL from the dataset page, taking the dataset_id (starting with d_...), and passing that into your datastore search API query as shown below: https://data.gov.sg/api/action/datastore_search?resource_id=d_8b84c4ee58e3cfc0ece0d773c8ca6abc

For staging, note that the dataset_id on production and staging might differ:

Search Rows in Dataset

get
Query parameters
resource_idstringRequired

ID or alias of the resource to be searched against. This corresponds to the dataset_id (resource_id is a legacy reference)

limitintegerOptional

Maximum number of rows to return (optional, default: 100)

Default: 100
offsetintegerOptional

Offset this number of rows (optional)

fieldsstringOptional

Fields to return (optional, default: all fields in original order)

filtersstringOptional

Dictionary of matching conditions, e.g {"key1": "a", "key2": "b"}

qstringOptional

Example: {"columnName": "columnValue"}

sortstringOptional

Comma-separated field names with ordering, eg.: "fieldname1, fieldname2 desc"

Responses
200

Fetched data

application/json
successbooleanRequired

Whether fetch is succesfully

get/api/action/datastore_search
GET /api/action/datastore_search?resource_id=text HTTP/1.1
Host: data.gov.sg
Accept: */*
{
  "success": true,
  "result": {
    "resource_id": "f9dbfc75-a2dc-42af-9f50-425e4107ae84",
    "fields": [
      {
        "type": "numeric",
        "id": "year"
      },
      {
        "type": "text",
        "id": "level_1"
      },
      {
        "type": "numeric",
        "id": "value"
      }
    ],
    "records": [
      {
        "year": 1960,
        "level_1": "Total Residents",
        "value": 1646400
      },
      {
        "year": 1960,
        "level_1": "Total Male Residents",
        "value": 859600
      },
      {
        "year": 1960,
        "level_1": "Total Female Residents",
        "value": 786800
      },
      {
        "year": 1961,
        "level_1": "Total Residents",
        "value": 1646400
      },
      {
        "year": 1961,
        "level_1": "Total Male Residents",
        "value": 859600
      }
    ],
    "limit": 5,
    "total": 870,
    "_links": {
      "start": "/api/action/datastore_search?limit=5&resource_id=f9dbfc75-a2dc-42af-9f50-425e4107ae84",
      "next": "/api/action/datastore_search?offset=5&limit=5&resource_id=f9dbfc75-a2dc-42af-9f50-425e4107ae84"
    }
  }
}

Last updated

Was this helpful?