This documentation is for developers interested in using the GOV.UK Notify API to send emails, text messages or letters.
You can use it to integrate directly with the API if you cannot use one of our 6 client libraries.
https://api.notifications.service.gov.uk
The authorisation header is an API key that is encoded using JSON Web Tokens. You must include an authorisation header.
JSON Web Tokens have a standard header and a payload. The header consists of:
{
"typ": "JWT",
"alg": "HS256"
}
The payload consists of:
{
"iss": "26785a09-ab16-4eb0-8407-a37497a57506",
"iat": 1568818578
}
JSON Web Tokens are encoded using a secret key with the following format:
3d844edf-8d35-48ac-975b-e847b4f122b0
That secret key forms a part of your API key, which follows the format {key_name}-{iss-uuid}-{secret-key-uuid}
.
For example, if your API key is
my_test_key-26785a09-ab16-4eb0-8407-a37497a57506-3d844edf-8d35-48ac-975b-e847b4f122b0
:
- your API key name is
my_test_key
- your iss (your service id) is
26785a09-ab16-4eb0-8407-a37497a57506
- your secret key is
3d844edf-8d35-48ac-975b-e847b4f122b0
iat
(issued at) is the current time in UTC in epoch seconds. The token expires within 30 seconds of the current time.
Refer to the JSON Web Tokens website for more information on encoding your authorisation header.
When you have an encoded and signed token, add that token to a header as follows:
"Authorization": "Bearer encoded_jwt_token"
The content header is application/json
:
"Content-type": "application/json"
You can use GOV.UK Notify to send text messages, emails and letters.
POST /v2/notifications/sms
{
"phone_number": "+447900900123",
"template_id": "f33517ff-2a88-4f6e-b855-c550268ce08a"
}
The phone number of the recipient of the text message. This can be a UK or international number.
To find the template ID:
- Sign in to GOV.UK Notify.
- Go to the Templates page and select the relevant template.
- Select Copy template ID to clipboard.
If a template has placeholder fields for personalised information such as name or reference number, you must provide their values in a dictionary with key value pairs. For example:
"personalisation": {
"first_name": "Amala",
"application_date": "2018-01-01",
}
You can leave out this argument if a template does not have any placeholder fields for personalised information.
An identifier you can create if necessary. This reference identifies a single notification or a batch of notifications. It must not contain any personal information such as name or postal address. For example:
"reference": "STRING"
You can leave out this argument if you do not have a reference.
A unique identifier of the sender of the text message notification.
To find the text message sender:
- Sign in to GOV.UK Notify.
- Go to the Settings page.
- In the Text Messages section, select Manage on the Text Message sender row.
You can then either:
- copy the sender ID that you want to use and paste it into the method
- select Change to change the default sender that the service will use, and select Save
"sms_sender_id": "8e222534-7f05-4972-86e3-17c5d9f894e2"
You can leave out this argument if your service only has one text message sender, or if you want to use the default sender.
If the request is successful, the response body is json
with a status code of 201
:
{
"id": "740e5834-3a29-46b4-9a6f-16142fde533a",
"reference": "STRING",
"content": {
"body": "MESSAGE TEXT",
"from_number": "SENDER"
},
"uri": "https://api.notifications.service.gov.uk/v2/notifications/740e5834-3a29-46b4-9a6f-16142fde533a",
"template": {
"id": "f33517ff-2a88-4f6e-b855-c550268ce08a",
"version": 1,
"uri": "https://api.notifications.service.gov.uk/v2/template/ceb50d92-100d-4b8b-b559-14fa3b091cd"
}
}
If you are using the test API key, all your messages will come back with a delivered
status.
All messages sent using the team and guest list or live keys will appear on your dashboard.
If the request is not successful, the response body is json
, refer to the table below for details.
status_code | message | How to fix |
---|---|---|
400 |
[{ "error": "BadRequestError", "message": "Can't send to this recipient using a team-only API key" }] |
Use the correct type of API key |
400 |
[{ "error": "BadRequestError", "message": "Can't send to this recipient when service is in trial mode - see https://www.notifications.service.gov.uk/trial-mode" }] |
Your service cannot send this notification in trial mode |
403 |
[{ "error": "AuthError", "message": "Error: Your system clock must be accurate to within 30 seconds" }] |
Check your system clock |
403 |
[{ "error": "AuthError", "message": "Invalid token: API key not found" }] |
Use the correct API key. Refer to API keys for more information |
429 |
[{ "error": "RateLimitError", "message": "Exceeded rate limit for key type TEAM/TEST/LIVE of 3000 requests per 60 seconds" }] |
Refer to API rate limits for more information |
429 |
[{ "error": "TooManyRequestsError", "message": "Exceeded send limits (LIMIT NUMBER) for today" }] |
Refer to service limits for the limit number |
500 |
[{ "error": "Exception", "message": "Internal server error" }] |
Notify was unable to process the request, resend your notification. |
POST /v2/notifications/email
{
"email_address": "sender@something.com",
"template_id": "f33517ff-2a88-4f6e-b855-c550268ce08a"
}
The email address of the recipient.
To find the template ID:
- Sign in to GOV.UK Notify.
- Go to the Templates page and select the relevant template.
- Select Copy template ID to clipboard.
If a template has placeholder fields for personalised information such as name or reference number, you need to provide their values in a dictionary with key value pairs. For example:
"personalisation": {
"first_name": "Amala",
"application_date": "2018-01-01",
}
You can leave out this argument if a template does not have any placeholder fields for personalised information.
An identifier you can create if necessary. This reference identifies a single notification or a batch of notifications. It must not contain any personal information such as name or postal address. For example:
"reference": "STRING"
You can leave out this argument if you do not have a reference.
This is an email address specified by you to receive replies from your users. You must add at least one reply-to email address before your service can go live.
To add a reply-to email address:
- Sign in to GOV.UK Notify.
- Go to the Settings page.
- In the Email section, select Manage on the Reply-to email addresses row.
- Select Add reply-to address.
- Enter the email address you want to use, and select Add.
For example:
"email_reply_to_id": "8e222534-7f05-4972-86e3-17c5d9f894e2"
You can leave out this argument if your service only has one reply-to email address, or you want to use the default email address.
To send a file by email, add a placeholder to the template then upload a file. The placeholder will contain a secure link to download the file.
The file will be available for the recipient to download for 18 months.
The links are unique and unguessable. GOV.UK Notify cannot access or decrypt your file.
- Sign in to GOV.UK Notify.
- Go to the Settings page.
- In the Email section, select Manage on the Send files by email row.
- Enter the contact details you want to use, and select Save.
- Sign in to GOV.UK Notify.
- Go to the Templates page and select the relevant email template.
- Select Edit.
- Add a placeholder to the email template using double brackets. For example:
"Download your file at: ((link_to_file))"
You can upload the following file types:
- PDF (.pdf)
- CSV (.csv)
- Text (.odt, .txt, .rtf)
- MS Word Document (.doc, .docx)
- Ms Excel Spreadsheet (.xlsx)
Your file must be smaller than 2MB. Contact the GOV.UK Notify team if you need to send other file types. You’ll need to convert the file into a string that is base64 encoded.
Pass the encoded string into an object with a file
key, and put that in the personalisation argument. For example:
"personalisation":{
"first_name": "Amala",
"application_date": "2018-01-01",
"link_to_file": {"file": "file as base64 encoded string"}
}
Uploads for CSV files should set the is_csv
flag as true
to ensure it is downloaded as a .csv file. For example:
"personalisation":{
"first_name": "Amala",
"application_date": "2018-01-01",
"link_to_file": {"file": "CSV file as base64 encoded string", "is_csv": true}
}
If the request to the client is successful, the client returns a dict
:
{
"id": "740e5834-3a29-46b4-9a6f-16142fde533a",
"reference": "STRING",
"content": {
"subject": "SUBJECT TEXT",
"body": "MESSAGE TEXT",
"from_email": "SENDER EMAIL"
},
"uri": "https://api.notifications.service.gov.uk/v2/notifications/740e5834-3a29-46b4-9a6f-16142fde533a",
"template": {
"id": "f33517ff-2a88-4f6e-b855-c550268ce08a",
"version": 1,
"uri": "https://api.notifications.service.gov.uk/v2/template/f33517ff-2a88-4f6e-b855-c550268ce08a"
}
}
If the request is not successful, the response body is json
, refer to the table below for details.
status_code | message | How to fix |
---|---|---|
400 |
[{ "error": "BadRequestError", "message": "Can't send to this recipient using a team-only API key" }] |
Use the correct type of API key |
400 |
[{ "error": "BadRequestError", "message": "Can't send to this recipient when service is in trial mode - see https://www.notifications.service.gov.uk/trial-mode" }] |
Your service cannot send this notification in trial mode |
400 |
[{ "error": "BadRequestError", "message": "Unsupported file type '(FILE TYPE)'. Supported types are: '(ALLOWED TYPES)" }] |
Wrong file type. You can only upload certain file formats. |
400 |
[{ "error": "BadRequestError", "message": "File did not pass the virus scan" }] |
The file contains a virus |
400 |
[{ "error": "BadRequestError", "message": "Send files by email has not been set up - add contact details for your service at https://www.notifications.service.gov.uk/services/(SERVICE ID)/service-settings/send-files-by-email" }] |
See how to add contact details to the file download page |
403 |
[{ "error": "AuthError", "message": "Error: Your system clock must be accurate to within 30 seconds" }] |
Check your system clock |
403 |
[{ "error": "AuthError", "message": "Invalid token: API key not found" }] |
Use the correct API key. Refer to API keys for more information |
429 |
[{ "error": "RateLimitError", "message": "Exceeded rate limit for key type TEAM/TEST/LIVE of 3000 requests per 60 seconds" }] |
Refer to API rate limits for more information |
429 |
[{ "error": "TooManyRequestsError", "message": "Exceeded send limits (LIMIT NUMBER) for today" }] |
Refer to service limits for the limit number |
500 |
[{ "error": "Exception", "message": "Internal server error" }] |
Notify was unable to process the request, resend your notification. |
When you add a new service it will start in trial mode. You can only send letters when your service is live.
To send Notify a request to go live:
- Sign in to GOV.UK Notify.
- Go to the Settings page.
- In the Your service is in trial mode section, select request to go live.
POST /v2/notifications/letter
{
"template_id": "f33517ff-2a88-4f6e-b855-c550268ce08a",
"personalisation": {
"address_line_1": "The Occupier",
"address_line_2": "123 High Street",
"address_line_3": "SW14 6BH"
}
}
To find the template ID:
- Sign in to GOV.UK Notify.
- Go to the Templates page and select the relevant template.
- Select Copy template ID to clipboard.
The personalisation argument always contains the following parameters for the letter recipient’s address:
address_line_1
address_line_2
address_line_3
address_line_4
address_line_5
address_line_6
address_line_7
The address must have at least 3 lines.
The last line needs to be a real UK postcode or the name of a country outside the UK.
Notify checks for international addresses and will automatically charge you the correct postage.
The postcode
personalisation argument has been replaced. If your template still uses postcode
, Notify will treat it as the last line of the address.
Any other placeholder fields included in the letter template also count as required parameters. You need to provide their values in a dictionary with key value pairs. For example:
"personalisation":{
"address_line_1": "The Occupier",
"address_line_2": "123 High Street",
"address_line_3": "Richmond upon Thames",
"address_line_4": "Middlesex",
"address_line_5": "SW14 6BF",
"name": "John Smith",
"application_id": "4134325"
}
An identifier you can create if necessary. This reference identifies a single notification or a batch of notifications. It must not contain any personal information such as name or postal address. For example:
"reference":"STRING"
If the request is successful, the response body is json
and the status code is 201
:
{
"id": "740e5834-3a29-46b4-9a6f-16142fde533a",
"reference": "STRING",
"content": {
"subject": "SUBJECT TEXT",
"body": "LETTER TEXT"
},
"uri": "https://api.notifications.service.gov.uk/v2/notifications/740e5834-3a29-46b4-9a6f-16142fde533a",
"template": {
"id": "f33517ff-2a88-4f6e-b855-c550268ce08a",
"version": 1,
"uri": "https://api.notifications.service.gov.uk/v2/template/f33517ff-2a88-4f6e-b855-c550268ce08a"
},
"scheduled_for": ""
}
If the request is not successful, the response body is json, refer to the table below for details.
status_code | message | How to fix |
---|---|---|
400 |
[{ "error": "BadRequestError", "message": "Can't send letters with a team API key" }] |
Use the correct type of API key. |
400 |
[{ "error": "BadRequestError", "message": "Can't send letters when service is in trial mode - see https://www.notifications.service.gov.uk/trial-mode" }] |
Your service cannot send this notification in trial mode. |
400 |
[{ "error": "ValidationError", "message": "personalisation address_line_1 is a required property" }] |
Ensure that your template has a field for the first line of the address, check personalisation for more information. |
400 |
[{ "error": "ValidationError", "message": "Must be a real UK postcode" }] |
Ensure that the value for the last line of the address is a real UK postcode. |
400 |
[{ "error": "ValidationError", "message": "Last line of address must be a real UK postcode or another country" }] |
Ensure that the value for the last line of the address is a real UK postcode or the name of a country outside the UK. |
403 |
[{ "error": "AuthError", "message": "Error: Your system clock must be accurate to within 30 seconds" }] |
Check your system clock. |
403 |
[{ "error": "AuthError", "message": "Invalid token: API key not found" }] |
Use the correct API key. Refer to API keys for more information. |
429 |
[{ "error": "RateLimitError", "message": "Exceeded rate limit for key type TEAM/TEST/LIVE of 3000 requests per 60 seconds" }] |
Refer to API rate limits for more information. |
429 |
[{ "error": "TooManyRequestsError", "message": "Exceeded send limits (LIMIT NUMBER) for today" }] |
Refer to service limits for the limit number. |
500 |
[{ "error": "Exception", "message": "Internal server error" }] |
Notify was unable to process the request, resend your notification. |
POST /v2/notifications/letter
{
"reference": "STRING",
"content": "STRING"
}
An identifier you can create if necessary. This reference identifies a single notification or a batch of notifications. It must not contain any personal information such as name or postal address.
The precompiled letter must be a PDF file which meets the GOV.UK Notify letter specification. You’ll need to convert the file into a string that is base64 encoded.
"content": "base64EncodedPDFFile"
You can choose first or second class postage for your precompiled letter. Set the value to first
for first class, or second
for second class. If you do not pass in this argument, the postage will default to second class.
"postage": "second"
If the request is successful, the response body is json
and the status code is 201
:
{
"id": "740e5834-3a29-46b4-9a6f-16142fde533a",
"reference": "your-letter-reference",
"postage": "postage-you-have-set-or-None"
}
If the request is not successful, the response body is json, refer to the table below for details.
status_code | message | How to fix |
---|---|---|
400 |
[{ "error": "BadRequestError", "message": "Can't send letters with a team API key" }] |
Use the correct type of API key |
400 |
[{ "error": "BadRequestError", "message": "Letter content is not a valid PDF" }] |
PDF file format is required |
400 |
[{ "error": "BadRequestError", "message": "Can't send letters when service is in trial mode - see https://www.notifications.service.gov.uk/trial-mode" }] |
Your service cannot send this notification in trial mode |
400 |
[{ "error": "ValidationError", "message": "reference is a required property" }] |
Add a reference argument to the method call |
400 |
[{ "error": "ValidationError", "message": "postage invalid. It must be either first or second." }] |
Change the value of postage argument in the method call to either 'first' or 'second' |
429 |
[{ "error": "RateLimitError", "message": "Exceeded rate limit for key type live of 10 requests per 20 seconds" }] |
Use the correct API key. Refer to API keys for more information |
429 |
[{ "error": "TooManyRequestsError", "message": "Exceeded send limits (50) for today" }] |
Refer to service limits for the limit number |
Message status depends on the type of message you have sent.
You can only get the status of messages sent within the retention period. The default retention period is 7 days.
GET /v2/notifications/{notification_id}
The ID of the notification. You can find the notification ID in the response to the original notification method call.
You can also find it by signing in to GOV.UK Notify and going to the API integration page.
You can filter the returned messages by including the following optional parameters in the URL:
If the request is successful, the response body is json
and the status code is 200
:
{
"id": "740e5834-3a29-46b4-9a6f-16142fde533a", # required string - notification ID
"reference": "STRING", # optional string
"email_address": "sender@something.com", # required string for emails
"phone_number": "+447900900123", # required string for text messages
"line_1": "ADDRESS LINE 1", # required string for letter
"line_2": "ADDRESS LINE 2", # required string for letter
"line_3": "ADDRESS LINE 3", # required string for letter
"line_4": "ADDRESS LINE 4", # optional string for letter
"line_5": "ADDRESS LINE 5", # optional string for letter
"line_6": "ADDRESS LINE 6", # optional string for letter
"line_7": "ADDRESS LINE 7", # optional string for letter
"type": "sms / letter / email", # required string
"status": "sending / delivered / permanent-failure / temporary-failure / technical-failure", # required string
"template": {
"Version": 1
"id": "f33517ff-2a88-4f6e-b855-c550268ce08a" # required string - template ID
"uri": "/v2/template/{id}/{version}", # required
},
"body": "STRING", # required string - body of notification
"subject": "STRING" # required string for email - subject of email
"created_at": "STRING", # required string - date and time notification created
"created_by_name": "STRING", # optional string - name of the person who sent the notification if sent manually
"sent_at": "STRING", # optional string - date and time notification sent to provider
"completed_at:" "STRING" # optional string - date and time notification delivered or failed
}
If the request is not successful, the response body is json
, refer to the table below for details.
status_code | message | How to fix |
---|---|---|
400 |
[{ "error": "ValidationError", "message": "id is not a valid UUID" }] |
Check the notification ID |
403 |
[{ "error": "AuthError", "message": "Error: Your system clock must be accurate to within 30 seconds" }] |
Check your system clock |
403 |
[{ "error": "AuthError", "message": "Invalid token: API key not found" }] |
Use the correct API key. Refer to API keys for more information |
404 |
[{ "error": "NoResultFound", "message": "No result found" }] |
Check the notification ID |
This API call returns one page of up to 250 messages and statuses. You can get either the most recent messages, or get older messages by specifying a particular notification ID in the older_than
argument.
You can only get the status of messages that are 7 days old or newer.
GET /v2/notifications
This will return all your messages with statuses. They will display in pages of up to 250 messages each.
You can filter the returned messages by including the following optional arguments in the URL:
You can omit any of these arguments to ignore these filters.
You can filter by:
email
sms
letter
You can filter by each:
You can leave out this argument to ignore this filter.
An identifier you can create if necessary. This reference identifies a single notification or a batch of notifications. It must not contain any personal information such as name or postal address. For example:
"reference": "STRING"
Input the ID of a notification into this argument. If you use this argument, the method returns the next 250 received notifications older than the given ID.
"older_than":"740e5834-3a29-46b4-9a6f-16142fde533a"
If you leave out this argument, the method returns the most recent 250 notifications.
The client only returns notifications that are 7 days old or newer. If the notification specified in this argument is older than 7 days, the client returns an empty response.
If the request is successful, the response body is json
and the status code is 200
.
{
"notifications": [
{
"id": "740e5834-3a29-46b4-9a6f-16142fde533a", # required string - notification ID
"reference": "STRING", # optional string - client reference
"email_address": "sender@something.com", # required string for emails
"phone_number": "+447900900123", # required string for text messages
"line_1": "ADDRESS LINE 1", # required string for letter
"line_2": "ADDRESS LINE 2", # required string for letter
"line_3": "ADDRESS LINE 3", # optional string for letter
"line_4": "ADDRESS LINE 4", # optional string for letter
"line_5": "ADDRESS LINE 5", # optional string for letter
"line_6": "ADDRESS LINE 6", # optional string for letter
"postcode": "STRING", # required for string letter, must be a real UK postcode
"type": "sms / letter / email", # required string
"status": "sending / delivered / permanent-failure / temporary-failure / technical-failure", # required string
"template": {
"version": 1
"id": 'f33517ff-2a88-4f6e-b855-c550268ce08a' # required string - template ID
"uri": "/v2/template/{id}/{version}", # required
},
"body": "STRING", # required string - body of notification
"subject": "STRING" # required string for email - subject of email
"created_at": "STRING", # required string - date and time notification created
"created_by_name": "STRING", # optional string - name of the person who sent the notification if sent manually
"sent_at": " STRING", # optional string - date and time notification sent to provider
"completed_at": "STRING" # optional string - date and time notification delivered or failed
},
…
],
"links": {
"current": "/notifications?template_type=sms&status=delivered",
"next": "/notifications?other_than=last_id_in_list&template_type=sms&status=delivered"
}
}
If the request is not successful, the response body is json
, refer to the table below for details.
status_code | message | How to fix |
---|---|---|
400 |
[{ "error": "ValidationError", "message": "id is not a valid UUID" }] |
Check the notification ID |
403 |
[{ "error": "AuthError", "message": "Error: Your system clock must be accurate to within 30 seconds" }] |
Check your system clock |
403 |
[{ "error": "AuthError", "message": "Invalid token: API key not found" }] |
Use the correct API key. Refer to API keys for more information |
404 |
[{ "error": "NoResultFound", "message": "No result found" }] |
Check the notification ID |
Status | Description |
---|---|
#created |
GOV.UK Notify has placed the message in a queue, ready to be sent to the provider. It should only remain in this state for a few seconds. |
#sending |
GOV.UK Notify has sent the message to the provider. The provider will try to deliver the message to the recipient for up to 72 hours. GOV.UK Notify is waiting for delivery information. |
#delivered |
The message was successfully delivered. |
#permanent-failure |
The provider could not deliver the message because the email address was wrong. You should remove these email addresses from your database. |
#temporary-failure |
The provider could not deliver the message. This can happen when the recipient’s inbox is full or their anti-spam filter rejects your email. Check your content does not look like spam before you try to send the message again. |
#technical-failure |
Your message was not sent because there was a problem between Notify and the provider. You’ll have to try sending your messages again. |
Status | Description |
---|---|
#created |
GOV.UK Notify has placed the message in a queue, ready to be sent to the provider. It should only remain in this state for a few seconds. |
#sending |
GOV.UK Notify has sent the message to the provider. The provider will try to deliver the message to the recipient for up to 72 hours. GOV.UK Notify is waiting for delivery information. |
#pending |
GOV.UK Notify is waiting for more delivery information. GOV.UK Notify received a callback from the provider but the recipient’s device has not yet responded. Another callback from the provider determines the final status of the text message. |
#sent |
The message was sent to an international number. The mobile networks in some countries do not provide any more delivery information. The GOV.UK Notify website displays this status as 'Sent to an international number'. |
#delivered |
The message was successfully delivered. |
#permanent-failure |
The provider could not deliver the message. This can happen if the phone number was wrong or if the network operator rejects the message. If you’re sure that these phone numbers are correct, you should contact GOV.UK Notify support. If not, you should remove them from your database. You’ll still be charged for text messages that cannot be delivered. |
#temporary-failure |
The provider could not deliver the message. This can happen when the recipient’s phone is off, has no signal, or their text message inbox is full. You can try to send the message again. You’ll still be charged for text messages to phones that are not accepting messages. |
#technical-failure |
Your message was not sent because there was a problem between Notify and the provider. You’ll have to try sending your messages again. You will not be charged for text messages that are affected by a technical failure. |
Status | Description |
---|---|
#accepted |
GOV.UK Notify has sent the letter to the provider to be printed. |
#received |
The provider has printed and dispatched the letter. |
#cancelled |
Sending cancelled. The letter will not be printed or dispatched. |
#technical-failure |
GOV.UK Notify had an unexpected error while sending the letter to our printing provider. |
#permanent-failure |
The provider cannot print the letter. Your letter will not be dispatched. |
Status | Description |
---|---|
#accepted |
GOV.UK Notify has sent the letter to the provider to be printed. |
#received |
The provider has printed and dispatched the letter. |
#cancelled |
Sending cancelled. The letter will not be printed or dispatched. |
#pending-virus-check |
GOV.UK Notify has not completed a virus scan of the precompiled letter file. |
#virus-scan-failed |
GOV.UK Notify found a potential virus in the precompiled letter file. |
#validation-failed |
Content in the precompiled letter file is outside the printable area. See the GOV.UK Notify letter specification for more information. |
#technical-failure |
GOV.UK Notify had an unexpected error while sending the letter to our printing provider. |
#permanent-failure |
The provider cannot print the letter. Your letter will not be dispatched. |