data.gov.sg
  • Introduction to data.gov.sg
  • ๐Ÿ†•What's new
    • Release Notes: Feburary 2025
    • Release Notes: October 2024
    • Release Notes: September 2024
  • USER GUIDE
    • Content quality guidelines
      • Data types
      • Data principles
    • For data consumers
      • How to search for data
      • How to raise a data request
      • How to embed the dataset explorer on your site
    • How to search for real-time APIs
    • For data owners
      • How to onboard as an admin
      • How to login
      • How to publish data
      • How to unpublish and/or delete datasets
      • How to edit datasets
      • How to generate API keys
      • Write APIs
  • DEVELOPER GUIDE
    • API overview
    • Collection APIs
    • Dataset APIs
Powered by GitBook
On this page

Was this helpful?

  1. DEVELOPER GUIDE

Dataset APIs

PreviousCollection APIs

Last updated 8 months ago

Was this helpful?

To find the datasetId, refer to the URL of dataset. For this dataset: or The datasetId is: d_11e68bba3b3c76733475a72d09759eeb

Dataset Search

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:

If you're looking to query the following dataset: 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:

Datasets Listing

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

Dataset Metadata

This API returns the metadata of a single dataset

Downloads

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.

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

As 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

Data.gov
https://beta.data.gov.sg/collections/522/datasets/d_11e68bba3b3c76733475a72d09759eeb/view
https://beta.data.gov.sg/datasets/d_11e68bba3b3c76733475a72d09759eeb/view
https://data.gov.sg/api/action/datastore_search
https://beta.data.gov.sg/datasets/d_8b84c4ee58e3cfc0ece0d773c8ca6abc/view
https://data.gov.sg/api/action/datastore_search?resource_id=d_8b84c4ee58e3cfc0ece0d773c8ca6abc

Search rows in a 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

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"}}}
default
Error information
application/json
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"
    }
  }
}
  • Dataset Search
  • GETSearch rows in a dataset
  • Datasets Listing
  • GETGet datasets
  • Dataset Metadata
  • GETGet metadata for a dataset
  • Downloads
  • GETInitiates download for a dataset
  • GETPoll download for a dataset after download has been initiated

Get datasets

get
Query parameters
pageinteger ยท min: 1Optional

Page number (optional, must be 1 or more)

Responses
200
Successful response
application/json
get
200

Successful response

Get metadata for a dataset

get
Path parameters
datasetIdstringRequired

The unique identifier of the dataset

Responses
200
Successful response
application/json
get
200

Successful response

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
400
Request Failure
  • Contains invalid column name.
  • Invalid filters.
  • Event object validation failed.
  • 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"
    }

    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
    400
    Request Failure
  • Contains invalid column name.
  • Invalid filters.
  • Event object validation failed.
  • 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"
    }
    GET /v2/public/api/datasets HTTP/1.1
    Host: api-production.data.gov.sg
    Accept: */*
    
    {
      "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"
    }
    GET /v2/public/api/datasets/{datasetId}/metadata HTTP/1.1
    Host: api-production.data.gov.sg
    Accept: */*
    
    {
      "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"
    }