Dataset APIs

To find the datasetId, refer to the URL of dataset. For this dataset: https://data.gov.sg/collections/522/datasets/d_11e68bba3b3c76733475a72d09759eeb/view or https://data.gov.sg/datasets/d_11e68bba3b3c76733475a72d09759eeb/view The datasetId is: d_11e68bba3b3c76733475a72d09759eeb

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

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

Full text query. If it’s a string, it’ll search on all fields on each row. If it’s a dictionary as {“key1”: “a”, “key2”: “b”}, it’ll search on each specific field. This is recommended rather than searching the full table as the latter will slow down queries significantly.

sortstringOptional

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

Responses
200
Fetched data
application/json
Responseall of
and
anyOptionalExample: {"help":"https://data.gov.sg/api/3/action/help_show?name=datastore_search","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"}}}
get
GET /api/action/datastore_search HTTP/1.1
Host: data.gov.sg
Accept: */*
{
  "help": "https://data.gov.sg/api/3/action/help_show?name=datastore_search",
  "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"
    }
  }
}

Datasets Listing

This API returns a list of all the datasets available on data.gov.sg

Get datasets

get
Query parameters
pageinteger · min: 1Optional

Page number (optional, must be 1 or more)

Responses
200
Successful response
application/json
get
GET /v2/public/api/datasets HTTP/1.1
Host: api-production.data.gov.sg
Accept: */*
200

Successful response

{
  "code": 1,
  "data": {
    "datasets": [
      {
        "datasetId": "text",
        "createdAt": "2023-02-17T18:54:57+08:00",
        "name": "text",
        "status": "text",
        "format": "text",
        "lastUpdatedAt": "2023-02-17T18:54:57+08:00",
        "managedByAgencyName": "text",
        "coverageStart": "2023-02-17T18:54:57+08:00",
        "coverageEnd": "2023-02-17T18:54:57+08:00"
      }
    ],
    "pages": 1
  },
  "errorMsg": "text"
}

Dataset Metadata

This API returns the metadata of a single dataset

Get metadata for a dataset

get
Path parameters
datasetIdstringRequired

The unique identifier of the dataset

Responses
200
Successful response
application/json
get
GET /v2/public/api/datasets/{datasetId}/metadata HTTP/1.1
Host: api-production.data.gov.sg
Accept: */*
200

Successful response

{
  "code": 1,
  "data": {
    "datasetId": "text",
    "createdAt": "2023-02-17T18:54:57+08:00",
    "name": "text",
    "format": "text",
    "lastUpdatedAt": "2023-02-17T18:54:57+08:00",
    "managedBy": "text",
    "coverageStart": "2023-02-17T18:54:57+08:00",
    "coverageEnd": "2023-02-17T18:54:57+08:00",
    "columnMetadata": {
      "order": [
        "text"
      ],
      "map": {
        "ANY_ADDITIONAL_PROPERTY": "text"
      },
      "metaMapping": {
        "ANY_ADDITIONAL_PROPERTY": {
          "name": "text",
          "columnTitle": "text",
          "dataType": 1,
          "index": "text"
        }
      }
    }
  },
  "errorMsg": "text"
}

Downloads

As Data.gov is a public shared service, we will apply quotas to ensure that they are fairly used by all users. If you exceed the quota of 5 requests per minute, you’ll likely receive a 429 Error

This API initiates the download of a single dataset, with optional filtering by columns and rows. For datasets that do not have the CSV extension (ie GeoJSON, KML, PDF etc.), you may skip this endpoint and proceed to the Poll Download API below.

Initiates download for a dataset

get
Path parameters
datasetIdstringRequired

ID of the dataset

Body
columnNamesstring[]Optional

List of selected columns in filtered dataset.

Example: ["name","title","address","email_address"]
filtersarrayOptional

Filters defines how users want to filter their dataset. Filters is an array of objects which have columnName,type and value attributes. columnName refers to the column where the filter is to be applied. The values for type can be EQ, LIKE, or ILIKE. EQ is direct comparison for filter and is case sensitive. LIKE is similar to EQ but includes partial matching. Any words containing the string in the value attribute will be matched. ILIKE is the case-insensitive version of LIKE.

Example: {"fitlers":[{"columnName":"epi_week","type":"EQ","value":2},{"columnName":"status","type":"ILIKE","value":"covid"},{"columnName":"epi_year","type":"LIKE","value":23}]}
Responses
201
Successful response
application/json
get
GET /v1/public/api/datasets/{datasetId}/initiate-download HTTP/1.1
Host: api-open.data.gov.sg
Content-Type: application/json
Accept: */*
Content-Length: 236

{
  "columnNames": [
    "name",
    "title",
    "address",
    "email_address"
  ],
  "filters": {
    "fitlers": [
      {
        "columnName": "epi_week",
        "type": "EQ",
        "value": 2
      },
      {
        "columnName": "status",
        "type": "ILIKE",
        "value": "covid"
      },
      {
        "columnName": "epi_year",
        "type": "LIKE",
        "value": 23
      }
    ]
  }
}
{
  "code": 1,
  "data": {
    "message": "text"
  },
  "errorMsg": "text"
}

After initiating the download of a dataset, this endpoint below returns a link to access the dataset.

Poll download for a dataset after download has been initiated

get
Path parameters
datasetIdstringRequired

ID of the dataset

Body
columnNamesstring[]Optional

List of selected columns in filtered dataset.

Example: ["name","title","address","email_address"]
filtersarrayOptional

Filters defines how users want to filter their dataset. Filters is an array of objects which have columnName,type and value attributes. columnName refers to the column where the filter is to be applied. The values for type can be EQ, LIKE, or ILIKE. EQ is direct comparison for filter and is case sensitive. LIKE is similar to EQ but includes partial matching. Any words containing the string in the value attribute will be matched. ILIKE is the case-insensitive version of LIKE.

Example: {"fitlers":[{"columnName":"epi_week","type":"EQ","value":2},{"columnName":"status","type":"ILIKE","value":"covid"},{"columnName":"epi_year","type":"LIKE","value":23}]}
Responses
201
Successful response
application/json
get
GET /v1/public/api/datasets/{datasetId}/poll-download HTTP/1.1
Host: api-open.data.gov.sg
Content-Type: application/json
Accept: */*
Content-Length: 236

{
  "columnNames": [
    "name",
    "title",
    "address",
    "email_address"
  ],
  "filters": {
    "fitlers": [
      {
        "columnName": "epi_week",
        "type": "EQ",
        "value": 2
      },
      {
        "columnName": "status",
        "type": "ILIKE",
        "value": "covid"
      },
      {
        "columnName": "epi_year",
        "type": "LIKE",
        "value": 23
      }
    ]
  }
}
{
  "code": 1,
  "data": {
    "status": "text",
    "url": "text"
  },
  "errorMsg": "text"
}

Last updated

Was this helpful?