📨
LetterSG Guide
Official websiteContact us
  • About LetterSG
  • Updates & Releases
  • For Agency Users
    • 🔏Accessing LetterSG
    • 🏃‍♂️Creating Letter Templates
    • 🛫Bulk Generating Letters
    • 📲Sending Out Letters
    • 🤝Sharing Access to Templates & Letters
    • 📝Editing Letter Templates
    • 👬Cloning Letter Templates
    • 📂Archiving Letter Templates
    • 📚Viewing Previously Generated Letters
    • ⬇️Downloading Letters as PDF
    • ❓FAQs
  • For Citizens
    • 🗄️Downloading your letter as PDF
    • 🏅Add your certificate to LinkedIn
    • ❓FAQs
  • Developer Guide
    • API Documentation
  • Legal
    • Terms of Use
    • Privacy Policy
Powered by GitBook
On this page
  • Bearer Token & API Key Generation
  • Authentication
  • Errors
  • Rate Limits
  • Endpoints
  • Get All Templates
  • Get Template Details by ID
  • (Single) Create Letter
  • (Bulk) Create letters
  • Get Letter Metadata
  • Get Batch Metadata
  • Get Downloadable Letter PDF (Beta)
  • Others
  • Keen on APIs?

Was this helpful?

  1. Developer Guide

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 create/send and fetch status of letters.

PreviousFAQsNextTerms of Use

Last updated 1 month ago

Was this helpful?

Bearer Token & API Key Generation

Bearer authentication (also called token authentication) is an HTTP authentication scheme that involves security tokens called bearer tokens. LetterSG 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 LetterSG's API.

Authentication

LetterSG's API uses APIKey for authentication. User can view and manage API Keys in LetterSG 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.

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

To verify that your API key is working, send a curl request:

curl --location \
--request GET 'https://letters.gov.sg/api/v1/templates/155' \
--header 'Authorization: Bearer live_v1_YOUR_API_KEY'

This request gets the template details for template 155, our sample template OGP - Certificate of Curiosity.

You should see a response containing the details for template 155:

{
    "templateId": 155,
    "fields": [
        "recipient_name"
    ],
    "name": "OGP - Certificate of Curiosity",
    "createdAt": "2023-11-09T04:17:49.631Z",
    "updatedAt": "2023-11-09T04:17:50.000Z"
}

Errors

LetterSG API uses conventional API Error to indicate the success or failure of an API request.

Status Codes
Description

200 - OK

Everything worked as expected.

302 - Redirect

(PDF endpoint) Redirects to the presigned URL for PDF.

400 - Bad Request

The request was unacceptable, often due to missing a required parameter.

401 - Unauthorized

No valid API key provided.

402 - Request Failed

The parameters were valid but the request failed.

404 - Not Found

The requested resource doesn't exist.

429 - Too Many Requests

Too many requests hit the API too quickly. We recommend an exponential backoff of your requests.

500, 502, 503, 504 - Server Errors

Something went wrong on LetterSG's API end.

Rate Limits

Unless otherwise stated, LetterSG allows up to 20 requests per second per user (subject to change).

Endpoints

Environment
Endpoint

Production

https://letters.gov.sg/api/

Staging

https://staging.letters.gov.sg/api/

Get All Templates

To see all templates that you have access to, send a GET request to list all templates. This endpoint also returns template fields that you will need to provide when generating the letters for each template.

GET /v1/templates

Request body:

Parameter
Type
Default value
Required?
Description

limit

number

100

No, optional

Maximum number of templates to be returned at once

offset

number

0

No, optional

Offset of the first template returned in the collection.

Returns:

// list of all templates that the user has access to
[
    templates: {
      templateId: number
      fields: string[]
      name: string
      createdAt: string
      updatedAt: string
    }[],
    count: number
]

Sample request:

# replace live_v1_YOUR_API_KEY with your actual API key
curl --location \
--request GET 'https://letters.gov.sg/api/v1/templates?limit=2&offset=5' \
--header 'Authorization: Bearer live_v1_YOUR_API_KEY'

Response:

[
    "templates": [
      {
        "templateId": 234,
        "fields": ["name", "name_2"],
        "name": "Template Name 1",
        "createdAt": "2022-09-19T03:31:00.131Z",
        "updatedAt": "2022-09-19T03:31:00.131Z"
      },
      {
        "templateId": 45,
        "fields": ["name", "name_2"],
        "name": "Template Name 2",
        "createdAt": "2022-09-19T03:31:00.131Z",
        "updatedAt": "2022-09-19T03:31:00.131Z"
     }
    ],
    "count": 40
]

Get Template Details by ID

To see the details of a template, send a GET request with the template ID of the template. This endpoint returns the template fields you need to provide when generating a letter.

GET /v1/templates/:id

Request body

Parameter
Type
Required?

id

number

Yes, required

ID of the template

Returns:

// details of template
{
    templateId: number
    fields: string[] 
    name: string
    createdAt: string
    updatedAt: string
}

Sample request:

# replace live_v1_YOUR_API_KEY with your actual API key
curl --location \
--request GET 'https://letters.gov.sg/api/v1/templates/155' \
--header 'Authorization: Bearer live_v1_YOUR_API_KEY'

Response:

{
    "templateId": 155,
    "fields": [
        "recipient_name"
    ],
    "name": "OGP - Certificate of Curiosity",
    "createdAt": "2023-11-09T04:17:49.631Z",
    "updatedAt": "2023-11-09T04:17:50.000Z"
}

(Single) Create Letter

POST /v1/letters

Request body:

Property
Type
Required?
Description

templateId

number

Yes, required

ID of the template

letterParams

JSON

Yes, required

Key-value pairs of the letter, based on the params contained in the template. If params values are not available, param must still be provided but you may use an empty space to indicate that the param is not available e.g."name": " "

notificationParams

JSON

No, optional

See below for notificationParams object format

  • Notification params, if provided, should look like so:

Property
Type
Required
Description

recipient

string

Yes, required

Contact of recipient, can be either phone number or email, provided as string. Phone numbers should start with either 8 or 9. Only local phone numbers supported for now.

notificationMethod

ENUM ("SMS" or "EMAIL")

Yes, required

Case sensitive

Returns:

// created letter
{
    publicId: string
    issuedLetter: string
    letterLink: string
    createdAt: string
    firstReadAt: string
    notificationStatus?: NotificationStatus
    recipient?: string
}

Sample request:

# replace live_v1_YOUR_API_KEY with your actual API key

# sample request to create a letter only, without SMS or EMAIL notification
curl --location 'https://letters.gov.sg/api/v1/letters' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer live_v1_YOUR_API_KEY' \
--data '{
    "templateId": 155,
    "letterParams": {
        "recipient_name": "Maxine Marcella"
    }
}'

# sample request with SMS notification
# replace YOUR_PHONE_NUMBER_STARTING_WITH_8_OR_9 with your phone number
# this sends a real SMS out, please test with your own phone number
curl --location 'https://letters.gov.sg/api/v1/letters' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer live_v1_YOUR_API_KEY' \
--data '{
    "templateId": 155,
    "letterParams": {
        "recipient_name": "Maxine Marcella"
    },
    "notificationParams": {
        "recipient": "YOUR_PHONE_NUMBER_STARTING_WITH_8_OR_9",
        "notificationMethod": "SMS"
    }
}'

# sample request with EMAIL notification
# replace YOUR_EMAIL with your email address
# this sends a real email out, please test with your own email address
curl --location 'https://letters.gov.sg/api/v1/letters' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer live_v1_YOUR_API_KEY' \
--data '{
    "templateId": 155,
    "letterParams": {
        "recipient_name": "Maxine Marcella"
    },
    "notificationParams": {
        "recipient": "YOUR_EMAIL",
        "notificationMethod": "EMAIL"
    }
}'

Response:

{
    "publicId": "2here-8o5td-9g4b6-xfd86",
    "letterLink": "https://letters.gov.sg/2here-8o5td-9g4b6-xfd86",
    "createdAt": "Fri May 17 2024",
    "issuedLetter": "<div style=\"background-image: url('https://file.go.gov.sg/3f5f3u.png'); background-size: cover; aspect-ratio: 1/1.435; color: black;\">\n<div style=\"position: absolute; text-align: center; width: 100%; top: 45.8%; transform: translate(0, -50%);\">\n<div style=\"font-family: georgia, palatino, serif; font-size: 26px; line-height: 1.5; letter-spacing: 0.05rem;\"><span style=\"font-size: 36px;\">CERTIFICATE OF</span><br><span style=\"font-size: 36px;\">CURIOSITY</span></div>\n<br>\n<div style=\"margin-top: 10px; font-family: verdana, geneva, sans-serif; letter-spacing: 0.2rem; color: #666c7a; font-size: 12px;\"><span style=\"font-size: 14px;\">AWARDED TO</span></div>\n<div style=\"font-family: symbol; font-size: 45px; margin-top: 50px; margin-left: 3rem; margin-right: 3rem;\"><span style=\"font-size: 58px; font-family: 'times new roman', times, serif;\"><em>Maxine Marcella</em></span></div>\n<br>\n<div style=\"font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 1.5; margin-top: 15px;\"><span style=\"font-size: 18px;\">for the successful completion of sending out your e-letter</span><br><span style=\"font-size: 18px;\">from <strong>LetterSG</strong></span></div>\n<br>\n<table style=\"width: 100%; text-align: center; margin-top: 15px;\"><colgroup> <col width=\"10%\"> <col width=\"10%\"> <col width=\"10%\"> <col width=\"10%\"> <col width=\"10%\"> </colgroup>\n<tbody>\n<tr style=\"font-family: 'Brush Script MT', cursive; font-size: 24px;\">\n<td>&nbsp;</td>\n<td style=\"border-bottom: 2px solid black; padding-bottom: 3px;\"><span style=\"color: rgb(0, 0, 0); font-size: 36px;\">Yung</span></td>\n<td>&nbsp;</td>\n<td style=\"border-bottom: 2px solid black;\"><span style=\"color: rgb(0, 0, 0); font-size: 36px;\">A</span></td>\n<td>&nbsp;</td>\n</tr>\n<tr>\n<td>&nbsp;</td>\n<td style=\"vertical-align: top; padding-top: 12px; font-family: Arial, Helvetica, sans-serif; font-size: 12px;\"><span style=\"font-size: 16px;\">Yung Guo En</span><br>\n<div style=\"font-family: verdana, geneva, sans-serif; letter-spacing: 0.1rem; font-size: 8px; padding-top: 5px;\"><span style=\"font-size: 10px;\">LETTERSG TRAINER</span></div>\n</td>\n<td colspan=\"3\" style=\"vertical-align: top; padding-top: 12px; font-family: Arial, Helvetica, sans-serif; font-size: 12px;\"><span style=\"font-size: 16px;\">Abbas Noor Bin Naqib Riduan</span><br>\n<div style=\"font-family: verdana, geneva, sans-serif; letter-spacing: 0.1rem; font-size: 8px; padding-top: 5px;\"><span style=\"font-size: 10px;\">LETTERSG ASSISTANT TRAINER</span></div>\n</td>\n</tr>\n</tbody>\n</table>\n</div>\n</div>"
}

Potential error responses (non-exhaustive):

{
    "statusCode": 404,
    "message": "Template not found",
    "error": "Not Found"
}
// extra letter param in request, serial_number
{
    "message": "Invalid letter params.",
    "error": [
        {
            "id": 0,
            "param": "serial_number",
            "message": "Invalid attribute in param",
            "displayedErrorMessage": " is an extra field"
        }
    ]
}

// missing letter param in request, recipient_name
{
    "message": "Invalid letter params.",
    "error": [
        {
            "id": 0,
            "param": "recipient_name",
            "message": "Missing param",
            "displayedErrorMessage": " field is missing"
        }
    ]
}

(Bulk) Create letters

This endpoint is generates a max of 500 letters at one time. Supported TPS: 1 transaction per second per user.

Please contact us if you need us to increase the rate limits.

POST /v1/letters/bulks

Request body:

Property
Type
Required?

templateId

number

Yes, required

ID of the template

lettersParams

JSON

Yes, required

An array containing key-value pairs for each letter, based on the params contained in the template. If param values are not available, param must still be provided but you may use an empty space to indicate that the param is not available e.g."name": " "

notificationMethod

string

No, optional

If provided, it specifies the notification channel for all recipients in the batch. Must be one of the following: "EMAIL", "SMS"

recipients

JSON

No, optional

An array of recipients that correspond to the letters. This list is required if a notification is to be sent. Each recipient will be notified via the method specified at the batch level.

If notificationMethod is "EMAIL" or "SMS", recipients must be provided. Contact of recipient can be either phone number or email, provided as strings. Phone numbers should start with either 8 or 9. Only local phone numbers supported for now.

Returns:

// created letter
{ batchId: number }

Sample request:

# sample request to create letters only, without SMS or EMAIL notification
curl --location 'https://letters.gov.sg/api/v1/letters' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer live_v1_YOUR_API_KEY' \
--data '{
    "templateId": 155,
    "lettersParams": [
        {
            "recipient_name": "Test1"
        },
        {
            "recipient_name": "Test2"
        }
    ]
}'

# sample request with SMS notifications
# replace YOUR_PHONE_NUMBER with your phone numbers
# this sends a real sms out, please test with your own phone numbers
curl --location 'https://letters.gov.sg/api/v1/letters' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer live_v1_YOUR_API_KEY' \
--data '{
    "templateId": 155,
    "lettersParams": [
        {
            "recipient_name": "Test1"
        },
        {
            "recipient_name": "Test2"
        }
    ],
    "notificationMethod": "SMS",
    "recipients": ["YOUR_PHONE_NUMBER", "YOUR_PHONE_NUMBER"]
}'


# sample request with EMAIL notification
# replace YOUR_EMAIL with your email address
# this sends a real email out, please test with your own email address
curl --location 'https://letters.gov.sg/api/v1/letters' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer live_v1_YOUR_API_KEY' \
--data '{
    "templateId": 155,
    "lettersParams": [
        {
            "recipient_name": "Test1"
        },
        {
            "recipient_name": "Test2"
        }
    ],
    "notificationMethod": "EMAIL",
    "recipients": ["YOUR_EMAIL", "YOUR_EMAIL"]
}'

Response:

{
    batchId: 3
}

Potential error responses (non-exhaustive):

// 404 Not Found errors 

// template does not exist
{
    "message": "Template not found",
}

// 400 Bad Request errors 

// invalid, missing or extra params
{
    "message": "Invalid letter params/ recipients",
    "errors": [
        {
            "id": 0,
            "errorType": "Invalid attribute in param",
            "message": "hello is an extra field"
        },
        {
            "id": 0,
            "errorType": "Missing param",
            "message": "recipient_name field is missing"
        },
        {
            "id": 1,
            "errorType": "Missing param",
            "message": "serial_number field is missing"
        }
    ]
}

{
    "message": "Notification method must be one of 'EMAIL', 'SMS'",
}

// invalid recipients or missing recipients
{
    "message": "Invalid letter params/ recipients",
    "errors": [
        {
            "id": 1,
            "errorType": "Invalid phone number",
            "message": "Phone Number should be local SG handphone number"
        },
        {
            "id": 2,
            "errorType": "Missing param",
            "message": "Phone Number field is missing"
        },
}

Get Letter Metadata

To retrieve the status of the letter, send a GET request with the public id of the letter that you would like to retrieve metadata for. You are only able to retrieve the metadata of letters that you have access to.

GET /v1/letters/:publicId 

Request Query Parameters:

Parameter
Type
Required?
Description

publicId

string

Yes, required

Letter ID for fetching the status e.g. xxyyy-12345-ddsss-d3454

Returned object:

// letter metadata
{
     publicId: string
     issuedLetter: string
     letterLink: string
     createdAt: string
     firstReadAt?: string
     notificationStatus?: NotificationStatus
     recipient?: string
}

Explanation of fields returned:

Field Returned
What it means
Example

publicId

Letter ID for fetching the read status

xxyyy-12345-ddsss-d3454

letterLink

Original link of the letter

https://letters.gov.sg/letters/public-letter-id

createdAt

Timestamp of letter creation

firstReadAt

(Optional) Timestamp of first read of letter, if letter is read

notificationStatus

(Optional) Status of the notification that was sent, this could be "SENT", "FAILED", "INVALID_RECIPIENT", "PENDING"

"SENT"

recipient

(Optional) String of the recipient's info

abcss@example.com

Sample Request:

# replace live_v1_YOUR_API_KEY with your actual API key
curl --location \
--request GET 'https://letters.gov.sg/api/v1/letters/2here-8o5td-9g4b6-xfd86' \
--header 'Authorization: Bearer live_v1_YOUR_API_KEY'

Returns:

{
    "publicId": "2here-8o5td-9g4b6-xfd86",
    "letterLink": "https://letters.gov.sg/2here-8o5td-9g4b6-xfd86",
    "createdAt": "Fri May 17 2024",
    "issuedLetter": "<div style=\"background-image: url('https://file.go.gov.sg/3f5f3u.png'); background-size: cover; aspect-ratio: 1/1.435; color: black;\">\n<div style=\"position: absolute; text-align: center; width: 100%; top: 45.8%; transform: translate(0, -50%);\">\n<div style=\"font-family: georgia, palatino, serif; font-size: 26px; line-height: 1.5; letter-spacing: 0.05rem;\"><span style=\"font-size: 36px;\">CERTIFICATE OF</span><br><span style=\"font-size: 36px;\">CURIOSITY</span></div>\n<br>\n<div style=\"margin-top: 10px; font-family: verdana, geneva, sans-serif; letter-spacing: 0.2rem; color: #666c7a; font-size: 12px;\"><span style=\"font-size: 14px;\">AWARDED TO</span></div>\n<div style=\"font-family: symbol; font-size: 45px; margin-top: 50px; margin-left: 3rem; margin-right: 3rem;\"><span style=\"font-size: 58px; font-family: 'times new roman', times, serif;\"><em>Maxine Marcella</em></span></div>\n<br>\n<div style=\"font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 1.5; margin-top: 15px;\"><span style=\"font-size: 18px;\">for the successful completion of sending out your e-letter</span><br><span style=\"font-size: 18px;\">from <strong>LetterSG</strong></span></div>\n<br>\n<table style=\"width: 100%; text-align: center; margin-top: 15px;\"><colgroup> <col width=\"10%\"> <col width=\"10%\"> <col width=\"10%\"> <col width=\"10%\"> <col width=\"10%\"> </colgroup>\n<tbody>\n<tr style=\"font-family: 'Brush Script MT', cursive; font-size: 24px;\">\n<td>&nbsp;</td>\n<td style=\"border-bottom: 2px solid black; padding-bottom: 3px;\"><span style=\"color: rgb(0, 0, 0); font-size: 36px;\">Yung</span></td>\n<td>&nbsp;</td>\n<td style=\"border-bottom: 2px solid black;\"><span style=\"color: rgb(0, 0, 0); font-size: 36px;\">A</span></td>\n<td>&nbsp;</td>\n</tr>\n<tr>\n<td>&nbsp;</td>\n<td style=\"vertical-align: top; padding-top: 12px; font-family: Arial, Helvetica, sans-serif; font-size: 12px;\"><span style=\"font-size: 16px;\">Yung Guo En</span><br>\n<div style=\"font-family: verdana, geneva, sans-serif; letter-spacing: 0.1rem; font-size: 8px; padding-top: 5px;\"><span style=\"font-size: 10px;\">LETTERSG TRAINER</span></div>\n</td>\n<td colspan=\"3\" style=\"vertical-align: top; padding-top: 12px; font-family: Arial, Helvetica, sans-serif; font-size: 12px;\"><span style=\"font-size: 16px;\">Abbas Noor Bin Naqib Riduan</span><br>\n<div style=\"font-family: verdana, geneva, sans-serif; letter-spacing: 0.1rem; font-size: 8px; padding-top: 5px;\"><span style=\"font-size: 10px;\">LETTERSG ASSISTANT TRAINER</span></div>\n</td>\n</tr>\n</tbody>\n</table>\n</div>\n</div>",
    "firstReadAt": "Fri May 17 2024"
}

Get Batch Metadata

To retrieve the status of the letter batch, send a GET request with the batch id that you would like to retrieve metadata for. You are only able to retrieve the metadata of batches that you have access to.

GET /v1/batches/:id 

Request Query Parameters:

Parameter
Type
Required?
Description

id

number

Yes, required

ID of batch

Returned object:

// letter metadata
{
    batchId: number,
    templateId: number,
    createdAt: Date,
    totalCount: number,
    readCount: number,
    notificationMethod: enum("SMS", "EMAIL"),
    "letterPublicIds": string[]
}

Explanation of fields returned:

Field Returned
What it means
Example

batchId

ID of batch issued

40091

templateId

ID of template used to issue batch

155

totalCount

Total number of letters in batch

readCount

Number of letters that have been read in batch

notificationMethod

(Optional) Method that letters sent via, could be "SMS", "EMAIL"

"SMS"

letterPublicIds

Array of public id of the letters in the batch.

Sample request:

curl --location \
--request GET 'https://letters.gov.sg/api/v1/batches/40091' \
--header 'Authorization: Bearer live_v1_YOUR_API_KEY'

Response:

{
    "batchId": 40091,
    "templateId": 155,
    "createdAt": "Mon, 27 Jan 2025 09:37:24 GMT",
    "totalCount": 1,
    "readCount": 0,
    "notificationMethod": "EMAIL",
    "letterPublicIds": [
        "lkq15-8w7ur-rznn5-kigvo"
    ]
}

Get Downloadable Letter PDF (Beta)

To download the issued letter as a PDF for archiving, send a GET request with the publicId of the letter.

Note: We may choose to further rate limit this endpoint in the future. This endpoint currently is offered in beta, and may not be always offered as a synchronous response.

GET /v1/letters/:publicId/pdfs

Request Query Parameters:

Parameter
Type
Default value
Required?

publicId

string

nil

Yes, required

Returns:

Redirects to presigned URL link with a 1-hour expiry (returning a 302 status).

// url to download link
{
  presignedUrl: string
}

Sample request:

# downloads PDF as 2here-8o5td-9g4b6-xfd86.pdf on your device
# replace live_v1_YOUR_API_KEY with your actual API key
curl --location \
--request GET 'https://letters.gov.sg/api/v1/letters/2here-8o5td-9g4b6-xfd86/pdfs' \
--header 'Authorization: Bearer live_v1_YOUR_API_KEY' --output 2here-8o5td-9g4b6-xfd86.pdf

Others

Keen on APIs?

For more information on integrating your systems with LetterSG, reach out to us at support@letters.gov.sg

To create a new letter, send a POST request specifying the template you would like to use, and the provide the relevant template fields for the letter. If you are unsure which template fields are required for the template, see .

The endpoint returns the link to the created letter, the public id of the letter, and the html of the created letter. If you need to , please store the public id of the letter as this is the unique identifier for this letter.

To create a batch of letters, send a POST request specifying the template you would like to use, and the provide a list of template fields, one set of template fields for each letter to be generated. If you are unsure which template fields are required for the template, see .

The endpoint returns the id of the created batch of letters. If you need to , please store the id of the batch as this is the identifier for this batch.

You may use letter publicId to

How can I whitelist LetterSG / What is LetterSG's IP address? LetterSG endpoints reside in the internet zone, so you can make the request with your API key. As we are being served by Cloudflare DNS, you may whitelist this range of Cloudflare's IP addresses ().

2022-09-19T03:31:00.131Z
2022-09-19T03:31:00.131Z
2022-09-19T03:31:00.131Z
2022-09-19T03:31:00.131Z
["lkq15-8w7ur-rznn5-kigvo"]
query the status of the batch
see here
Get Template Details By Id
query the status of the letter or retrieve information about the letter
Get Template Details By Id
retrieve metadata about the letter