Dataset APIs

To find the datasetId, refer to the URL of dataset. For this dataset: https://beta.data.gov.sg/collections/522/datasets/d_11e68bba3b3c76733475a72d09759eeb/view or https://beta.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://beta.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

GEThttps://data.gov.sg/api/action/datastore_search
Query parameters
Response

Fetched data

Body
help*string

URL that returns a help string for the API action

success*boolean

Whether fetch is succesfully

result*object

Resource

any
Request
const response = await fetch('https://data.gov.sg/api/action/datastore_search?resource_id=text', {
    method: 'GET',
    headers: {},
});
const data = await response.json();
Response
{
  "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

GEThttps://api-production.data.gov.sg/v2/public/api/datasets
Query parameters
Response

Successful response

Body
codeinteger
dataobject
errorMsgstring
Request
const response = await fetch('https://api-production.data.gov.sg/v2/public/api/datasets', {
    method: 'GET',
    headers: {},
});
const data = await response.json();
Response
{
  "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"
      }
    ]
  },
  "errorMsg": "text"
}

Dataset Metadata

This API returns the metadata of a single dataset

Get metadata for a dataset

GEThttps://api-production.data.gov.sg/v2/public/api/datasets/{datasetId}/metadata
Path parameters
datasetId*string

The unique identifier of the dataset

Response

Successful response

Body
codeinteger
dataobject
errorMsgstring
Request
const response = await fetch('https://api-production.data.gov.sg/v2/public/api/datasets/{datasetId}/metadata', {
    method: 'GET',
    headers: {},
});
const data = await response.json();
Response
{
  "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"
      ]
    }
  },
  "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

GEThttps://api-open.data.gov.sg/v1/public/api/datasets/{datasetId}/initiate-download
Path parameters
datasetId*string

ID of the dataset

Body

Optional request body for filtering dataset

columnNamesarray of string

List of selected columns in filtered dataset.

filtersarray

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.

Response

Successful response

Body
codeinteger

Response code

dataobject
errorMsgstring

Error message (if any)

Request
const response = await fetch('https://api-open.data.gov.sg/v1/public/api/datasets/{datasetId}/initiate-download', {
    method: 'GET',
    headers: {
      "Content-Type": "application/json"
    },
    body: JSON.stringify({}),
});
const data = await response.json();
Response
{
  "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

GEThttps://api-open.data.gov.sg/v1/public/api/datasets/{datasetId}/poll-download
Path parameters
datasetId*string

ID of the dataset

Body

Optional request body for filtering dataset

columnNamesarray of string

List of selected columns in filtered dataset.

filtersarray

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.

Response

Successful response

Body
codeinteger

Response code

dataobject
errorMsgstring

Error message (if any)

Request
const response = await fetch('https://api-open.data.gov.sg/v1/public/api/datasets/{datasetId}/poll-download', {
    method: 'GET',
    headers: {
      "Content-Type": "application/json"
    },
    body: JSON.stringify({}),
});
const data = await response.json();
Response
{
  "data": {
    "status": "text",
    "url": "text"
  },
  "errorMsg": "text"
}

Last updated