Write APIs
Government Admin users can use Write APIs to automatically and programmatically publish data to data.gov.sg without needing to log into the UI
Prerequisites
You must be a government officer
Your email has admin permissions to manage datasets
Step 1 - Generate API Keys:
Create an API key from the admin dashboard.
Store the API key in a secure location. It will be used later.
Step by step details can be found here: How to generate API keys
Step 2 - Verify API Connectivity:
Run a get request against the above endpoint, using your admin api key in the header:
https://api-production.data.gov.sg/v2/admin/api/auth/whoami
A 200 response means that you're connected.
Common issues:
Check your API URL - did you use the correct URL above?
Check your API key - did you use the correct API key? Try regenerating the API key and testing again
Are the network configurations set up to connect to the internet? data.gov.sg is an internet platform and require internet connectivity
Step 3 - Publish Dataset:
To push data, an existing dataset must exist. The dataset can be created from the admin dashboard.
The dataset must already contain existing data.
The dataset must be published.
For more details on publishing data: How to publish data
Using Write APIs involves three steps:
Generating upload link
Uploading file to link
Polling for upload status
Step 4 - Create Upload / Append URL:
If you are creating a new dataset or replacing an existing dataset completely, then generate an upload link:
If you are appending rows to an existing dataset, then generate an append link. Please ensure the column data types and names are all the same and no new columns have been added. This append API only supports appending rows to an existing dataset and not appending columns:
Find the datasetId
within the dataset url
For example, for this url: https://beta.data.gov.sg/datasets/d_07c63be0f37e6e59c07a4ddc2fd87fcb/view
The datasetId is the following:
d_07c63be0f37e6e59c07a4ddc2fd87fcb
Hence, the endpoint used would be:
https://api-production.data.gov.sg/v2/admin/api/datasets/d_07c63be0f37e6e59c07a4ddc2fd87fcb/upload-link
Step 5 - Upload Tabular File:
It’s important to ensure that you are sending a PUT request with only the file data. While POST-ing form-data is allowed, the file received will not be the same and may cause errors.
Common issues:
Check that you're using a PUT request
Check that you're using the generated upload url instead of the one provided above
Step 6 - Get Latest Ingestion Status:
The validation and ingestion process of DataGovSG is asynchronous and long running. The upload request from the previous section will return before the process is complete. In order to get the status for validation and ingestion, manual polling is required.
Here are the possible validation and ingestion statuses:
Raw API Schema:
Updated as of 20th June 2024
For further queries feel free to reach out to us: Contact the Data.gov.sg team
Last updated