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:

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:

  1. Check your API URL - did you use the correct URL above?

  2. Check your API key - did you use the correct API key? Try regenerating the API key and testing again

  3. 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 URL:

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:

  1. Check that you're using a PUT request

  2. 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:

OrderStatusDescription

1

Pending

The validation and ingestion process has been started

2

Pending Validation

The dataset has been queued for validation

2.1

Validation Failed

The dataset contains invalid values causing validation failures. Please review the reported errors, make the necessary changes and try again.

2.2

Validation Passed

The dataset has been validated successfully, but not yet ingested.

3

Pending Ingestion

The dataset has been queued for ingestion.

3.1

Ingestion Failed

The dataset failed to be ingested. Please try again later.

3.2

Ingestion Success

The dataset has been ingested successfully.

Raw API Schema:

Updated as of 16th Feb 2024

Last updated