A Singapore Government Agency Website

Testing APIs with cURL

To test APIs within the intranet zone, you can use cURL commands on a virtual machine hosted on the intranet.

Prerequisite

Authentication

Authenticate your backend application using the following sample code.

curl --location --request POST ‘https://api.in.cft.stack.gov.sg/v2/auth?application_type=backend’
--header ‘workflowID: {workflowID}’
--header ‘Authorization: Basic {Basic auth of Application Client ID and Client Secret}’

Replace the values for the workflowID and the Basic auth of the application Client ID and Client Secret with the appropriate values.

Note: Basic auth of Application Client ID and Client Secret is the Base64 encoding of the application Client ID and Client Secret.

The successful response provides an auth access token.

Send files

To send a file, refer to the following sample code. Replace the values for the access_token, workflowID, and key with the appropriate values.

curl --location --request PUT “https://api.in.cft.stack.gov.sg/v2/workflows/{workflowID}/files/{key}” \
--header “Content-Type: application/octet-stream” \
--header “Authorization: Bearer {access_token}” \
--header “Content-Length: $(stat -c%s {key})” \
--data-binary “@{key}”

Important: Always include the content-length header in your HTTPS uploads with the correct file size in bytes. This ensures that the system can capture the file size accurately for reporting and invoicing.

Receive files

To receive a file, use the following code. Replace the values for access_token and fileID with the appropriate values.

curl --location --request GET ‘https://api.in.cft.stack.gov.sg/v2/files/{fileID}/download’ 
--header ‘Content-Type: application/octet-stream’ 
--header ‘Authorization: Bearer {access_token}’
Chat with me!
Bot Launcher