Dataset APIs
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.
ID or alias of the resource to be searched against. This corresponds to the dataset_id (resource_id is a legacy reference)
Maximum number of rows to return (optional, default: 100)
100
Offset this number of rows (optional)
Fields to return (optional, default: all fields in original order)
Dictionary of matching conditions, e.g {"key1": "a", "key2": "b"}
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.
Comma-separated field names with ordering, eg.: "fieldname1, fieldname2 desc"
{"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 /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
Page number (optional, must be 1 or more)
GET /v2/public/api/datasets HTTP/1.1
Host: api-production.data.gov.sg
Accept: */*
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
The unique identifier of the dataset
GET /v2/public/api/datasets/{datasetId}/metadata HTTP/1.1
Host: api-production.data.gov.sg
Accept: */*
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
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.
ID of the dataset
List of selected columns in filtered dataset.
["name","title","address","email_address"]
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.
{"fitlers":[{"columnName":"epi_week","type":"EQ","value":2},{"columnName":"status","type":"ILIKE","value":"covid"},{"columnName":"epi_year","type":"LIKE","value":23}]}
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.
ID of the dataset
List of selected columns in filtered dataset.
["name","title","address","email_address"]
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.
{"fitlers":[{"columnName":"epi_week","type":"EQ","value":2},{"columnName":"status","type":"ILIKE","value":"covid"},{"columnName":"epi_year","type":"LIKE","value":23}]}
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?