API Documentation

This page is meant for developers, vendors, and IT administrators to understand how to generate the bearer token to access our API to get/create/update shortlinks.

Bearer Token & API Key Generation

Bearer authentication (also called token authentication) is an HTTP authentication scheme that involves security tokens called bearer tokens. ForEduSG uses bearer authentication.

To generate the token, click on "API Integration" in the navigation bar. From there, click on Generate API key and copy the token. Use this key to start using ForEduSG's API.

Keep the bearer token safe: You should not share the bearer token with anyone. Use services like 1Password to store it.

Authentication

ForEduSG's API uses APIKey for authentication. User can view and manage API Keys in ForEduSG's API Dashboard.

Staging secret keys will have test_v1_version prefix.

Production secret keys will have live_v1_version prefix.

Authentication to the API is performed via bearer auth.

curl --location --request POST 'https://for.edu.sg/api/v1/urls' \
--header 'Authorization: Bearer live_v1_YOUR_API_KEY'

All API requests must be made over HTTPS. Calls made over plain HTTP will fail and requests without authentication will also fail.

Errors

ForEduSG's API uses conventional API Error to indicate the success or failure of an API request.

{
  "message": "Unauthorized"
}

Rate Limits

ForEduSG supports a default rate limit of 5 requests per second for each user. If you require higher rate limits, please write to us at go@open.gov.sg with more details.

If you have exceeded your rate limit, your incoming requests will be blocked for 10 seconds as a cooling off period. We recommend throttling your requests and implementing exponential backoff for retries to ensure that your requests can be accepted.

Endpoints

Get Urls

GET /v1/urls?...

Request Query Parameters:

Note: Max values for limit = 1000

Returns:

{
  "urls": [
    {
      "shortUrl": "197abc",
      "longUrl": "https://link.com",
      "state": "ACTIVE",
      "clicks": 0,
      "createdAt": "2022-09-19T03:31:00.131Z",
      "updatedAt": "2022-09-19T03:31:00.131Z"
    }
  ],
  "count": 1
}

Explanation of fields returned:

Create Url

POST /v1/urls

Request body:

  • longUrl has to start with https://

  • If no shortUrl is provided, then a random 8 character alphanumeric shortUrl name will be generated for the link.

Returns:

{
  "shortUrl": "197abc",
  "longUrl": "https://link.com",
  "state": "ACTIVE",
  "clicks": 0,
  "createdAt": "2022-09-19T03:31:00.131Z",
  "updatedAt": "2022-09-19T03:31:00.131Z"
}
{
  "message": "Short link \\"asd\\" is already used.",
  "type": "ShortUrlError"
}

Update Url

PATCH /v1/urls/{shortUrl}

Note: Indicate shortUrl name you wish to update in above PATCH request, ie. {shortUrl}

Request body:

  • longUrl has to start with https://

Returns:

{
  "shortUrl": "197abc",
  "longUrl": "https://link.com",
  "state": "ACTIVE",
  "clicks": 0,
  "createdAt": "2022-09-19T03:31:00.131Z",
  "updatedAt": "2022-09-19T03:31:00.131Z"
}

Last updated