Java client documentation

This documentation is for developers interested in using the GOV.UK Notify Java client to send emails, text messages or letters.

.NET client documentation

This documentation is for developers interested in using the GOV.UK Notify .NET client to send emails (including documents), text messages or letters. GOV.UK Notify supports .NET framework 4.6.2 and .NET Core 2.0.

Node.js client documentation

This documentation is for developers interested in using the GOV.UK Notify Node.js client to send emails, text messages or letters.

PHP client documentation

This documentation is for developers interested in using the GOV.UK Notify PHP client to send emails, text messages or letters.

Python client documentation

This documentation is for developers interested in using the GOV.UK Notify Python client to send emails, text messages or letters. Notify supports Python 3.7 and higher.

Ruby client documentation

This documentation is for developers interested in using the GOV.UK Notify Ruby client to send emails, text messages or letters.

REST API documentation

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.

Set up the client

Set up the client

Set up the client

Set up the client

The Notify PHP Client is based on a PSR-7 HTTP model [external link]. To install it, you must select your preferred PSR-7 compatible HTTP client. You can follow these instructions to use Guzzle v7[external link].

Set up the client

Set up the client

Base URL

https://api.notifications.service.gov.uk

Install the client

The notifications-java-client deploys to Maven Central.

Go to the GOV.UK Notify Java client page on Maven Central [external link]:

  1. Select the most recent version.
  2. Copy the dependency configuration snippet for your build tool.

Refer to the client changelog for the version number and the latest updates.

Prerequisites

This documentation assumes you are using Microsoft Visual Studio [external link] with the NuGet Package Manager [external link].

Refer to the client changelog for the version number and the latest updates.

Install the client

Run the following in the command line:

npm install --save notifications-node-client

Guzzle v7

  1. Use Composer [external link] to install the GOV.UK Notify PHP client. Run the following in the command line:

    composer require php-http/guzzle7-adapter alphagov/notifications-php-client
    

    You can now use the autoloader [external link] to download the GOV.UK Notify PHP client.

  2. Add the following code to your application to create a new instance of the client:

    $notifyClient = new \Alphagov\Notifications\Client([
        'apiKey' => '{your api key}',
        'httpClient' => new \Http\Adapter\Guzzle7\Client
    ]);
    

To get an API key, sign in to GOV.UK Notify and go to the API integration page. You can find more information in the API keys section of this documentation.

Install the client

Run the following code in the command line:

pip install notifications-python-client

Refer to the client changelog for the client version number and the latest updates.

Install the client

Run the following in the command line:

gem install 'notifications-ruby-client'

Refer to the client changelog for the version number and the latest updates.

Create a new instance of the client

Add this code to your application:

import uk.gov.service.notify.NotificationClient;
NotificationClient client = new NotificationClient(apiKey);

To get an API key, sign in to GOV.UK Notify and go to the API integration page. You can find more information in the API keys section of this documentation.

If you use a proxy you can pass it into the NotificationClient constructor.

import uk.gov.service.notify.NotificationClient;
NotificationClient client = new NotificationClient(apiKey, proxy);

Install the client

The GOV.UK Notify client can be installed from Nuget.org [external link].

You can install the GOV.UK Notify client package using either the command line or Microsoft Visual Studio.

Warning If you need a version of our API client older than 4.0.0, you should download it from Github [external link]

Create a new instance of the client

Add this code to your application:

var NotifyClient = require('notifications-node-client').NotifyClient

var notifyClient = new NotifyClient(apiKey)

To get an API key, sign in to GOV.UK Notify and go to the API integration page. You can find more information in the API keys section of this documentation.

Create a new instance of the client

Add this code to your application:

from notifications_python_client.notifications import NotificationsAPIClient

notifications_client = NotificationsAPIClient(api_key)

Create a new instance of the client

Add this code to your application:

require 'notifications/client'
client = Notifications::Client.new(api_key)

To get an API key, sign in to GOV.UK Notify and go to the API integration page. You can find more information in the API keys section of this documentation.

Use the dotnet command line interface

Go to your project directory and run the following in the command line to install the client package:

dotnet add package GovukNotify

Connect through a proxy (optional)

Add this code to your application:

proxyConfig = {
  host: proxyHost,
  port: proxyPort
}

notifyClient.setProxy(proxyConfig)

where the proxyConfig should be an object supported by axios.

Arguments

api_key (required)

To get an API key, sign in to GOV.UK Notify and go to the API integration page. You can find more information in the API keys section of this documentation.

timeout (optional)

The default timeout is 30 seconds. For more information about timeouts see https://docs.python-requests.org/en/latest/user/advanced/#timeouts.

Use Microsoft Visual Studio

Use the NuGet Package Manager [external link] to install the GovukNotify client package in Visual Studio.

You can use either the console [external link] or the UI [external link].

Provide your own underlying Axios client (optional)

You can provide your own Axios client to the Notify client. This is useful if you want to use a custom Axios client with specific settings, like custom interceptors.

Add this code to your application:

notifyClient.setClient(customAxiosClient)

where customAxiosClient is an instance of Axios.

Console

Run the following in the NuGet package manager console to install the client package:

nuget install GovukNotify
UI

Use the Package Manager UI to search for and install the client package [external link].

Create a new instance of the client

Add this code to your application:

using Notify.Client;
using Notify.Models;
using Notify.Models.Responses;

var client = new NotificationClient(apiKey);

To get an API key, sign in to GOV.UK Notify and go to the API integration page. You can find more information in the API keys section of this documentation.

If you use a proxy, you must set the proxy configuration in the web.config file. Refer to the Microsoft documentation on proxy configuration for more information.

using Notify.Client;
using Notify.Models;
using Notify.Models.Responses;
using System.Net.Http;

var httpClientWithProxy = new HttpClientWrapper(new HttpClient(...));
var client = new NotificationClient(httpClientWithProxy, apiKey);

Send a message

You can use GOV.UK Notify to send emails, text messages and letters.

Send a message

You can use GOV.UK Notify to send emails, text messages and letters.

Send a message

You can use GOV.UK Notify to send emails, text messages and letters.

Send a message

You can use GOV.UK Notify to send text messages, emails and letters.

Send a message

You can use GOV.UK Notify to send emails, text messages and letters.

Send a message

You can use GOV.UK Notify to send emails, text messages and letters.

Headers

Send a text message

Send a text message

Send a text message

Send a text message

Send a text message

Send a text message

Authorisation header

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"

Method

SendSmsResponse response = client.sendSms(
    templateId,
    phoneNumber,
    personalisation,
    reference,
    smsSenderId
);

Method

SmsNotificationResponse response = client.SendSms(
  mobileNumber: "+447900900123",
  templateId: "f33517ff-2a88-4f6e-b855-c550268ce08a",
  );

Method

notifyClient
  .sendSms(templateId, phoneNumber, {
    personalisation: personalisation,
    reference: reference,
    smsSenderId: smsSenderId
  })
  .then(response => console.log(response))
  .catch(err => console.error(err))

The method returns a promise [external link]. The promise will either:

  • resolve with a response if successful
  • fail with an err if unsuccessful

Method

sendSms( $phoneNumber, $templateId, array $personalisation = array(), $reference = '', $smsSenderId = NULL  )

For example:

try {
    $response = $notifyClient->sendSms(
        '+447777111222',
        'df10a23e-2c6d-4ea5-87fb-82e520cbf93a', [
            'name' => 'Betty Smith',
            'dob'  => '12 July 1968'
        ],
        'unique_ref123',
        '862bfaaf-9f89-43dd-aafa-2868ce2926a9'
    );

} catch (ApiException $e){}

Method

response = notifications_client.send_sms_notification(
    phone_number='+447900900123', # required string
    template_id='f33517ff-2a88-4f6e-b855-c550268ce08a', # required UUID string
)

Method

smsresponse = client.send_sms(
  phone_number: "+447900900123",
  template_id: "f33517ff-2a88-4f6e-b855-c550268ce08a",
)

Arguments

Arguments

Arguments

Arguments

Arguments

Arguments

templateId (required)

To find the template ID:

  1. Sign in to GOV.UK Notify.
  2. Go to the Templates page and select the relevant template.
  3. Select Copy template ID to clipboard.

For example:

String templateId="f33517ff-2a88-4f6e-b855-c550268ce08a";
mobileNumber (required)

The phone number of the recipient of the text message. This can be a UK or international number.

string mobileNumber: "+447900900123";
templateId (required)

To find the template ID:

  1. Sign in to GOV.UK Notify.
  2. Go to the Templates page and select the relevant template.
  3. Select Copy template ID to clipboard.

For example:

'f33517ff-2a88-4f6e-b855-c550268ce08a'
phoneNumber (required)

The phone number of the recipient of the text message. This can be a UK or international number.

phone_number (required)

The phone number of the recipient of the text message. This can be a UK or international number.

phone_number (required)

The phone number of the text message recipient. This can be a UK or international number. For example:

phone_number:"+447900900123"
phoneNumber (required)

The phone number of the recipient of the text message. This number can be a UK or international number.

String phoneNumber="+447900900123";
templateId (required)

To find the template ID:

  1. Sign in to GOV.UK Notify.
  2. Go to the Templates page and select the relevant template.
  3. Select Copy template ID to clipboard.

For example:

string templateId: "f33517ff-2a88-4f6e-b855-c550268ce08a";
phoneNumber (required)

The phone number of the recipient of the text message. This number can be a UK or international number. For example:

'+447900900123'
templateId (required)

To find the template ID:

  1. Sign in to GOV.UK Notify.
  2. Go to the Templates page and select the relevant template.
  3. Select Copy template ID to clipboard.
template_id (required)

To find the template ID:

  1. Sign in to GOV.UK Notify.
  2. Go to the Templates page and select the relevant template.
  3. Select Copy template ID to clipboard.
template_id (required)

To find the template ID:

  1. Sign in to GOV.UK Notify.
  2. Go to the Templates page and select the relevant template.
  3. Select Copy template ID to clipboard.

For example:

template_id:"f33517ff-2a88-4f6e-b855-c550268ce08a"
personalisation (required)

If a template has placeholder fields for personalised information such as name or reference number, you must provide their values in a map. For example:

Map<String, Object> personalisation = new HashMap<>();
personalisation.put("first_name", "Amala");
personalisation.put("application_date", "2018-01-01");
personalisation.put("list", listOfItems); // Will appear as a comma separated list in the message

If a template does not have any placeholder fields for personalised information, you must pass in an empty map or null.

personalisation (optional)

If a template has placeholder fields for personalised information such as name or reference number, you need to provide their values in a Dictionary. For example:

Dictionary<String, dynamic> personalisation = new Dictionary<String, dynamic>
{
    {"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.

personalisation (required)

If a template has placeholder fields for personalised information such as name or reference number, you must provide their values in an object. For example:

{
  'first_name': 'Amala',
  'reference_number': '300241'
}
personalisation (optional)

If a template has placeholder fields for personalised information such as name or application date, you must provide their values in a dictionary with key value pairs. For example:

$personalisation = [
    '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.

personalisation (optional)

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.

personalisation (optional)

If a template has placeholder fields for personalised information such as name or reference number, you must provide their values in a hash. For example:

personalisation: {
  name: "John Smith",
  ID: "300241",
}

You can leave out this argument if a template does not have any placeholder fields for personalised information.

reference (required)

A unique identifier you create. This reference identifies a single unique notification or a batch of notifications. It must not contain any personal information such as name or postal address. If you do not have a reference, you must pass in an empty string or null.

String reference='STRING';
reference (optional)

A unique identifier you can create if you need to. This reference identifies a single unique notification or a batch of notifications. It must not contain any personal information such as name or postal address. For example:

string reference: "STRING";

You can leave out this argument if you do not have a reference.

reference (required)

A unique identifier you create. This reference identifies a single unique notification or a batch of notifications. It must not contain any personal information such as name or postal address. If you do not have a reference, you must pass in an empty string or null. For example:

'your_reference_here'
reference (optional)

A unique identifier you can create if necessary. This reference identifies a single unique 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.

reference (optional)

A unique identifier you can create if necessary. This reference identifies a single unique message or a batch of messages. It must not contain any personal information such as name or postal address. For example:

reference='STRING', # optional string - identifies notification(s)

You can leave out this argument if you do not have a reference.

reference (optional)

A unique identifier you can create if necessary. This reference identifies a single unique notification or a batch of notifications. It must not contain any personal information such as name or postal address. For example:

reference: "your_reference_string"

You can leave out this argument if you do not have a reference.

smsSenderId (optional)

A unique identifier of the sender of the text message notification.

To find the text message sender:

  1. Sign in to GOV.UK Notify.
  2. Go to the Settings page.
  3. 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
String smsSenderId='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.

smsSenderId (optional)

A unique identifier of the sender of the text message notification.

To find the text message sender:

  1. Sign in to GOV.UK Notify.
  2. Go to the Settings page.
  3. 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 uses, and select Save

For example:

string smsSenderId: "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.

smsSenderId (optional)

A unique identifier of the sender of the text message notification. For example:

'8e222534-7f05-4972-86e3-17c5d9f894e2'

To find the text message sender:

  1. Sign in to GOV.UK Notify.
  2. Go to the Settings page.
  3. In the Text Messages section, select Manage on the Text Message sender row.

In this screen, you can 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

You can leave out this argument if your service only has one text message sender, or if you want to use the default sender.

smsSenderId (optional)

A unique identifier of the sender of the text message notification.

To find the text message sender:

  1. Sign in to GOV.UK Notify.
  2. Go to the Settings page.
  3. 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
$smsSenderId='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.

sms_sender_id (optional)

A unique identifier of the sender of the text message.

To find the text message sender:

  1. Sign in to GOV.UK Notify.
  2. Go to the Settings page.
  3. 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' # optional UUID string

You can leave out this argument if your service only has one text message sender, or if you want to use the default sender.

sms_sender_id (optional)

A unique identifier of the sender of the text message notification.

To find the text message sender:

  1. Sign in to GOV.UK Notify.
  2. Go to the Settings page.
  3. 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 uses, and select Save

For example:

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.

Response

If the request to the client is successful, the client returns a SendSmsResponse:

UUID notificationId;
Optional<String> reference;
UUID templateId;
int templateVersion;
String templateUri;
String body;
Optional<String> fromNumber;

If you are using the test API key, all your messages come back with a delivered status.

All messages sent using the team and guest list or live keys appear on your dashboard.

Response

If the request to the client is successful, the client returns an SmsNotificationResponse:

public String id;
public String reference;
public String uri;
public Template template;
public SmsResponseContent;

public class Template {
    public String id;
    public String uri;
    public Int32 version;
}
public class SmsResponseContent{
    public string body;
    public string fromNumber;
}

If you use the test API key, all your messages come back with a delivered status.

All messages sent using the team and guest list or live keys appear on your dashboard.

Response

If the request is successful, the promise resolves with a response object. For example, the response.data property will look like this:

{
  'id': 'bfb50d92-100d-4b8b-b559-14fa3b091cda',
  'reference': null,
  'content': {
    'body': 'Some words',
    'from_number': '40604'
  },
  'uri': 'https://api.notifications.service.gov.uk/v2/notifications/ceb50d92-100d-4b8b-b559-14fa3b091cd',
  'template': {
    'id': 'ceb50d92-100d-4b8b-b559-14fa3b091cda',
    'version': 1,
    'uri': 'https://api.notifications.service.gov.uk/v2/templates/bfb50d92-100d-4b8b-b559-14fa3b091cda'
  }
}

If you are using the test API key, all your messages come back with a delivered status.

All messages sent using the team and guest list or live keys appear on your dashboard.

Response

If the request to the client is successful, the client returns an array:

[
    "id" => "bfb50d92-100d-4b8b-b559-14fa3b091cda",
    "reference" => None,
    "content" => [
        "body" => "Some words",
        "from_number" => "40604"
    ],
    "uri" => "https =>//api.notifications.service.gov.uk/v2/notifications/ceb50d92-100d-4b8b-b559-14fa3b091cd",
    "template" => [
        "id" => "ceb50d92-100d-4b8b-b559-14fa3b091cda",
       "version" => 1,
       "uri" => "https://api.notifications.service.gov.uk/v2/templates/bfb50d92-100d-4b8b-b559-14fa3b091cda"
    ]
];

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.

Response

If the request to the client is successful, the client returns a dict:

{
  "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": INTEGER,
    "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.

Response

If the request to the client is successful, the client returns a Notifications::Client:ResponseNotification object. In the example shown in the Method section, the object is named smsresponse.

You can then call different methods on this object:

Method Information Type
smsresponse.id Notification UUID String
smsresponse.reference reference argument String
smsresponse.content - body: Message body sent to the recipient
- from_number: SMS sender number of your service
Hash
smsresponse.template Contains the id, version and uri of the template Hash
smsresponse.uri Notification URL String

If you are using the test API key, all your messages come back with a delivered status.

All messages sent using the team and guest list or live keys appear on your GOV.UK Notify dashboard.

Error codes

If the request is not successful, the client returns a NotificationClientException containing the relevant error code:

httpResult 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

Error codes

If the request is not successful, the client returns a Notify.Exceptions.NotifyClientException containing the relevant error code.

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

Error codes

If the request is not successful, the promise fails with an err.

err.response.data.status_code err.response.data.errors 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

Error codes

If the request is not successful, the client returns an Alphagov\Notifications\Exception\ApiException object containing the relevant error code.

exc->getCode() exc->getErrors() 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.

Error codes

If the request is not successful, the client returns an HTTPError containing the relevant error code.

error.status_code error.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 text message 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 text message.

Error codes

If the request is not successful, the client raises a Notifications::Client::RequestError exception (or a subclass), which contains a code:

error.code error.message class How to fix
400 BadRequestError: Can't send to this recipient using a team-only API key BadRequestError Use the correct type of API key
400 BadRequestError: Can't send to this recipient when service is in trial mode - see https://www.notifications.service.gov.uk/trial-mode BadRequestError Your service cannot send this notification in trial mode
403 AuthError: Error: Your system clock must be accurate to within 30 seconds AuthError Check your system clock
403 AuthError: Invalid token: API key not found AuthError Use the correct API key. Refer to API keys for more information
429 RateLimitError: Exceeded rate limit for key type TEAM/TEST/LIVE of 3000 requests per 60 seconds RateLimitError Refer to API rate limits for more information
429 TooManyRequestsError: Exceeded send limits (LIMIT NUMBER) for today ClientError Refer to service limits for the limit number
500 Exception: Internal server error ServerError Notify was unable to process the request, resend your notification

Send an email

Send an email

Send an email

Send an email

Send an email

Send an email

Content header

The content header is application/json:

"Content-type": "application/json"

Method

SendEmailResponse response = client.sendEmail(
    templateId,
    emailAddress,
    personalisation,
    reference,
    emailReplyToId
);

Method

EmailNotificationResponse response = client.SendEmail(emailAddress, templateId, personalisation, reference, emailReplyToId);
client.SendEmail(
    emailAddress: "sender@something.com",
    templateId: "f33517ff-2a88-4f6e-b855-c550268ce08a"
);

Method

notifyClient
  .sendEmail(templateId, emailAddress, {
    personalisation: personalisation,
    reference: reference,
    oneClickUnsubscribeURL: oneClickUnsubscribeURL,
    emailReplyToId: emailReplyToId
  })
  .then(response => console.log(response))
  .catch(err => console.error(err))

The method returns a promise [external link]. The promise will either:

  • resolve with a response if successful
  • fail with an err if unsuccessful

Method

sendEmail( $emailAddress, $templateId, array $personalisation = array(), $reference = '', $emailReplyToId = NULL, $oneClickUnsubscribeURL = NULL )

For example:

try {

    $response = $notifyClient->sendEmail(
        'betty@example.com',
        'df10a23e-2c0d-4ea5-87fb-82e520cbf93c', [
            'name' => 'Betty Smith',
            'dob'  => '12 July 1968'
        ],
        'unique_ref123',
        '862bfaaf-9f89-43dd-aafa-2868ce2926a9',
        );

} catch (ApiException $e){}

Method

response = notifications_client.send_email_notification(
    email_address='sender@something.com', # required string
    template_id='f33517ff-2a88-4f6e-b855-c550268ce08a', # required UUID string
)

Method

emailresponse = client.send_email(
  email_address: "sender@something.com",
  template_id: "f33517ff-2a88-4f6e-b855-c550268ce08a",
)

Arguments

Arguments

Arguments

Arguments

Arguments

Arguments

templateId (required)

To find the template ID:

  1. Sign in to GOV.UK Notify.
  2. Go to the Templates page and select the relevant template.
  3. Select Copy template ID to clipboard.

For example:

String templateId="f33517ff-2a88-4f6e-b855-c550268ce08a";
emailAddress (required)

The email address of the recipient. For example:

string emailAddress: "sender@something.com";
templateId (required)

To find the template ID:

  1. Sign in to GOV.UK Notify.
  2. Go to the Templates page and select the relevant template.
  3. Select Copy template ID to clipboard.

For example:

"f33517ff-2a88-4f6e-b855-c550268ce08a"
emailAddress (required)

The email address of the recipient.

email_address (required)

The email address of the recipient.

email_address (required)

The email address of the recipient. For example:

email_address: "sender@something.com"
emailAddress (required)

The email address of the recipient.

String emailAddress='sender@something.com';
templateId (required)

To find the template ID:

  1. Sign in to GOV.UK Notify.
  2. Go to the Templates page and select the relevant template.
  3. Select Copy template ID to clipboard.

For example:

string templateId: "f33517ff-2a88-4f6e-b855-c550268ce08a";
emailAddress (required)

The email address of the recipient. For example:

"sender@something.com"
templateId (required)

To find the template ID:

  1. Sign in to GOV.UK Notify.
  2. Go to the Templates page and select the relevant template.
  3. Select Copy template ID to clipboard.
template_id (required)

To find the template ID:

  1. Sign in to GOV.UK Notify.
  2. Go to the Templates page and select the relevant template.
  3. Select Copy template ID to clipboard.
template_id (required)

To find the template ID:

  1. Sign in to GOV.UK Notify.
  2. Go to the Templates page and select the relevant template.
  3. Select Copy template ID to clipboard.

For example:

template_id: "f33517ff-2a88-4f6e-b855-c550268ce08a"
personalisation (required)

If a template has placeholder fields for personalised information such as name or application date, you must provide their values in a map. For example:

Map<String, Object> personalisation = new HashMap<>();
personalisation.put("first_name", "Amala");
personalisation.put("application_date", "2018-01-01");
// pass in a list and it will appear as bullet points in the message:
personalisation.put("list", listOfItems);

If a template does not have any placeholder fields for personalised information, you must pass in an empty map or null.

personalisation (optional)

If a template has placeholder fields for personalised information such as name or reference number, you need to provide their values in a Dictionary. For example:

Dictionary<String, dynamic> personalisation = new Dictionary<String, dynamic>
{
    {"first_name", "Amala"},
    {"application_date", "2018-01-01"},
    // pass in a list and it will appear as bullet points in the message:
    {"required_documents", new List<string> {"passport", "utility bill", "other id"}}
};

You can leave out this argument if a template does not have any placeholder fields for personalised information.

personalisation (required)

If a template has placeholder fields for personalised information such as name or application date, you must provide their values in an object. For example:

{
  personalisation: {
    'first_name': 'Amala',
    'application_number': '300241',
    // pass in an array and it will appear as bullet points in the message:
    'required_documents': ['passport', 'utility bill', 'other id']
  }
}
personalisation (optional)

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 = [
    'name' => 'Amala',
    'application_date'  => '2018-01-01',
    # pass in an array and it will appear as bullet points in the message:
    'required_documents' => ['passport', 'utility bill', 'other id']
];

You can leave out this argument if a template does not have any placeholder fields for personalised information.

personalisation (optional)

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",
    # pass in a list and it will appear as bullet points in the message:
    "required_documents": ["passport", "utility bill", "other id"],
}

You can leave out this argument if a template does not have any placeholder fields for personalised information.

personalisation (optional)

If a template has placeholder fields for personalised information such as name or reference number, you must provide their values in a hash. For example:

personalisation: {
  name: "John Smith",
  year: "2016",
  # pass in an array and it will appear as bullet points in the message:
  required_documents: ["passport", "utility bill", "other id"],
}

You can leave out this argument if a template does not have any placeholder fields for personalised information.

reference (required)

A unique identifier you create. This reference identifies a single unique notification or a batch of notifications. It must not contain any personal information such as name or postal address. If you do not have a reference, you must pass in an empty string or null.

String reference='STRING';
reference (optional)

A unique identifier you can create if you need to. This reference identifies a single unique notification or a batch of notifications. It must not contain any personal information such as name or postal address. For example:

string reference: "STRING";

You can leave out this argument if you do not have a reference.

reference (required)

A unique identifier you create. This reference identifies a single unique notification or a batch of notifications. It must not contain any personal information such as name or postal address. If you do not have a reference, you must pass in an empty string or null. For example:

"your_reference_here"
reference (optional)

A unique identifier you can create if necessary. This reference identifies a single unique notification or a batch of notifications. It must not contain any personal information such as name or postal address.

$reference = 'STRING';

You can leave out this argument if you do not have a reference.

reference (optional)

A unique identifier you can create if necessary. This reference identifies a single unique email or a batch of emails. It must not contain any personal information such as name or postal address. For example:

reference='STRING', # optional string - identifies notification(s)

You can leave out this argument if you do not have a reference.

reference (optional)

A unique identifier you can create if necessary. This reference identifies a single unique notification or a batch of notifications. It must not contain any personal information such as name or postal address. For example:

reference: "your_reference_string"

You can leave out this argument if you do not have a reference.

oneClickUnsubscribeURL (optional)

The one-click unsubscribe URL will be added to the headers of your email. Email clients will use it to add an unsubscribe button.

Read our Using Notify page for more information about unsubscribe links.

URI oneClickUnsubscribeURL = 'https://example.com/unsubscribe.html?opaque=123456789'

The one-click unsubscribe URL must respond to an empty POST request by unsubscribing the user from your emails. You can include query parameters to help you identify the user.

Your unsubscribe URL and response must comply with the guidance specified in Section 3.1 of IETF RFC 8058.

You can leave out this argument if the email being sent is not a subscription email.

oneClickUnsubscribeURL (optional)

The one-click unsubscribe URL will be added to the headers of your email. Email clients will use it to add an unsubscribe button.

Read our Using Notify page for more information about unsubscribe links.

string oneClickUnsubscribeURL : 'https://example.com/unsubscribe.html?opaque=123456789';

The one-click unsubscribe URL must respond to an empty POST request by unsubscribing the user from your emails. You can include query parameters to help you identify the user.

Your unsubscribe URL and response must comply with the guidance specified in Section 3.1 of IETF RFC 8058.

You can leave out this argument if the email being sent is not a subscription email.

oneClickUnsubscribeURL (optional)

The one-click unsubscribe URL will be added to the headers of your email. Email clients will use it to add an unsubscribe button.

Read our Using Notify page for more information about unsubscribe links.

oneClickUnsubscribeURL = 'https://example.com/unsubscribe.html?opaque=123456789'

The one-click unsubscribe URL must respond to an empty POST request by unsubscribing the user from your emails. You can include query parameters to help you identify the user.

Your unsubscribe URL and response must comply with the guidance specified in Section 3.1 of IETF RFC 8058.

You can leave out this argument if the email being sent is not a subscription email.

one_click_unsubscribe_url (optional)

The one-click unsubscribe URL will be added to the headers of your email. Email clients will use it to add an unsubscribe button.

Read our Using Notify page for more information about unsubscribe links.

$one_click_unsubscribe_url = 'https://example.com/unsubscribe.html?opaque=123456789'

The one-click unsubscribe URL must respond to an empty POST request by unsubscribing the user from your emails. You can include query parameters to help you identify the user.

Your unsubscribe URL and response must comply with the guidance specified in Section 3.1 of IETF RFC 8058.

one_click_unsubscribe_url (optional)

The one-click unsubscribe URL will be added to the headers of your email. Email clients will use it to add an unsubscribe button.

Read our Using Notify page for more information about unsubscribe links.

one_click_unsubscribe_url = 'https://example.com/unsubscribe.html?opaque=123456789'

The one-click unsubscribe URL must respond to an empty POST request by unsubscribing the user from your emails. You can include query parameters to help you identify the user.

Your unsubscribe URL and response must comply with the guidance specified in Section 3.1 of IETF RFC 8058.

You can leave out this argument if the email being sent is not a subscription email.

one_click_unsubscribe_url (optional)

The one-click unsubscribe URL will be added to the headers of your email. Email clients will use it to add an unsubscribe button.

Read our Using Notify page for more information about unsubscribe links.

one_click_unsubscribe_url: "https://example.com/unsubscribe.html?opaque=123456789"

The one-click unsubscribe URL must respond to an empty POST request by unsubscribing the user from your emails. You can include query parameters to help you identify the user.

Your unsubscribe URL and response must comply with the guidance specified in Section 3.1 of IETF RFC 8058.

You can leave out this argument if the email being sent is not a subscription email.

emailReplyToId (optional)

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:

  1. Sign in to GOV.UK Notify.
  2. Go to the Settings page.
  3. In the Email section, select Manage on the Reply-to email addresses row.
  4. Select Add reply-to address.
  5. Enter the email address you want to use, and select Add.
String emailReplyToId='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.

emailReplyToId (optional)

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:

  1. Sign in to GOV.UK Notify.
  2. Go to the Settings page.
  3. In the Email section, select Manage on the Reply-to email addresses row.
  4. Select Add reply-to address.
  5. Enter the email address you want to use, and select Add.

For example:

string emailReplyToId: "8e222534-7f05-4972-86e3-17c5d9f894e2";

You can leave out this argument if your service only has one email reply-to address, or you want to use the default email address.

emailReplyToId (optional)

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:

  1. Sign in to GOV.UK Notify.
  2. Go to the Settings page.
  3. In the Email section, select Manage on the Reply-to email addresses row.
  4. Select Add reply-to address.
  5. Enter the email address you want to use, and select Add.
emailReplyToId='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.

emailReplyToId (optional)

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:

  1. Sign in to GOV.UK Notify.
  2. Go to the Settings page.
  3. In the Email section, select Manage on the Reply-to email addresses row.
  4. Select Add reply-to address.
  5. Enter the email address you want to use, and select Add.

For example:

$emailReplyToId='8e222534-7f05-4972-86e3-17c5d9f894e2'

You can leave out this argument if your service only has one email reply-to address, or you want to use the default email address.

email_reply_to_id (optional)

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:

  1. Sign in to GOV.UK Notify.
  2. Go to the Settings page.
  3. In the Email section, select Manage on the Reply-to email addresses row.
  4. Select Add reply-to address.
  5. Enter the email address you want to use, and select Add.

For example:

email_reply_to_id='8e222534-7f05-4972-86e3-17c5d9f894e2' # optional UUID string

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.

email_reply_to_id (optional)

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:

  1. Sign in to GOV.UK Notify.
  2. Go to the Settings page.
  3. In the Email section, select Manage on the Reply-to email addresses row.
  4. Select Add reply-to address.
  5. 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 email reply-to address, or you want to use the default email address.

Response

If the request to the client is successful, the client returns a SendEmailResponse:

UUID notificationId;
Optional<String> reference;
Optional<URI> oneClickUnsubscribeURL;
UUID templateId;
int templateVersion;
String templateUri;
String body;
String subject;
Optional<String> fromEmail;

Response

If the request to the client is successful, the client returns an EmailNotificationResponse:

public String id;
public String reference;
public String oneClickUnsubscribeURL;
public String uri;
public Template template;
public EmailResponseContent content;

public class Template{
    public String id;
    public String uri;
    public Int32 version;
}
public class EmailResponseContent{
  public String fromEmail;
  public String body;
  public String subject;
}

Response

If the request is successful, the promise resolves with a response object. For example, the response.data property will look like this:

{
  'id': 'bfb50d92-100d-4b8b-b559-14fa3b091cda',
  'reference': null,
  'oneClickUnsubscribeURL': null,
  'content': {
    'subject': 'Licence renewal',
    'body': 'Dear Bill, your licence is due for renewal on 3 January 2016.',
    'from_email': 'the_service@gov.uk'
  },
  'uri': 'https://api.notifications.service.gov.uk/v2/notifications/ceb50d92-100d-4b8b-b559-14fa3b091cd',
  'template': {
    'id': 'ceb50d92-100d-4b8b-b559-14fa3b091cda',
    'version': 1,
    'uri': 'https://api.notificaitons.service.gov.uk/service/your_service_id/templates/bfb50d92-100d-4b8b-b559-14fa3b091cda'
  }
}

Error codes

If the request is not successful, the client returns a NotificationClientException containing the relevant error code:

httpResult 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

Error codes

If the request is not successful, the client returns a Notify.Exceptions.NotifyClientException containing the relevant error code.

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": "File did not pass the virus scan"
}]
The file contains a virus
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 daily limits for the limit number
500 [{
"error": "Exception",
"message": "Internal server error"
}]
Notify was unable to process the request, resend your notification.

Error codes

If the request is not successful, the promise fails with an err.

err.response.data.status_code err.response.data.errors 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

Send a file by email

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 links are unique and unguessable. GOV.UK Notify cannot access or decrypt your file.

Your file will be available to download for a default period of 26 weeks (6 months).

To help protect your files you can also:

  • ask recipients to confirm their email address before downloading
  • choose the length of time that a file is available to download

Send a file by email

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 links are unique and unguessable. GOV.UK Notify cannot access or decrypt your file.

Your file will be available to download for a default period of 26 weeks (6 months).

To help protect your files you can also:

  • ask recipients to confirm their email address before downloading
  • choose the length of time that a file is available to download

Send a file by email

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 links are unique and unguessable. GOV.UK Notify cannot access or decrypt your file.

Your file will be available to download for a default period of 26 weeks (6 months).

To help protect your files you can also:

  • ask recipients to confirm their email address before downloading
  • choose the length of time that a file is available to download

Send a file by email

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 links are unique and unguessable. GOV.UK Notify cannot access or decrypt your file.

Your file will be available to download for a default period of 26 weeks (6 months).

To help protect your files you can also:

  • ask recipients to confirm their email address before downloading
  • choose the length of time that a file is available to download

Send a file by email

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 links are unique and unguessable. GOV.UK Notify cannot access or decrypt your file.

Your file will be available to download for a default period of 26 weeks (6 months).

To help protect your files you can also:

  • ask recipients to confirm their email address before downloading
  • choose the length of time that a file is available to download

Send a file by email

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 links are unique and unguessable. GOV.UK Notify cannot access or decrypt your file.

Your file will be available to download for a default period of 26 weeks (6 months).

To help protect your files you can also:

  • ask recipients to confirm their email address before downloading
  • choose the length of time that a file is available to download

Add contact details to the file download page

  1. Sign in to GOV.UK Notify.
  2. Go to the Settings page.
  3. In the Email section, select Manage on the Send files by email row.
  4. Enter the contact details you want to use, and select Save.

Add contact details to the file download page

  1. Sign in to GOV.UK Notify.
  2. Go to the Settings page.
  3. In the Email section, select Manage on the Send files by email row.
  4. Enter the contact details you want to use, and select Save.

Add contact details to the file download page

  1. Sign in to GOV.UK Notify.
  2. Go to the Settings page.
  3. In the Email section, select Manage on the Send files by email row.
  4. Enter the contact details you want to use, and select Save.

Add contact details to the file download page

  1. Sign in to GOV.UK Notify.
  2. Go to the Settings page.
  3. In the Email section, select Manage on the Send files by email row.
  4. Enter the contact details you want to use, and select Save.

Add contact details to the file download page

  1. Sign in to GOV.UK Notify.
  2. Go to the Settings page.
  3. In the Email section, select Manage on the Send files by email row.
  4. Enter the contact details you want to use, and select Save.

Add contact details to the file download page

  1. Sign in to GOV.UK Notify.
  2. Go to the Settings page.
  3. In the Email section, select Manage on the Send files by email row.
  4. Enter the contact details you want to use, and select Save.

Add a placeholder to the template

  1. Sign in to GOV.UK Notify.
  2. Go to the Templates page and select the relevant email template.
  3. Select Edit.
  4. Add a placeholder to the email template using double brackets. For example: “Download your file at: ((link_to_file))”

Your email should also tell recipients how long the file will be available to download.

Add a placeholder to the template

  1. Sign in to GOV.UK Notify.
  2. Go to the Templates page and select the relevant email template.
  3. Select Edit.
  4. Add a placeholder to the email template using double brackets. For example: “Download your file at: ((link_to_file))”

Your email should also tell recipients how long the file will be available to download.

Add a placeholder to the template

  1. Sign in to GOV.UK Notify.
  2. Go to the Templates page and select the relevant email template.
  3. Select Edit.
  4. Add a placeholder to the email template using double brackets. For example: “Download your file at: ((link_to_file))”

Your email should also tell recipients how long the file will be available to download.

Add a placeholder to the template

  1. Sign in to GOV.UK Notify.
  2. Go to the Templates page and select the relevant email template.
  3. Select Edit.
  4. Add a placeholder to the email template using double brackets. For example: “Download your file at: ((link_to_file))”

Your email should also tell recipients how long the file will be available to download.

Add a placeholder to the template

  1. Sign in to GOV.UK Notify.
  2. Go to the Templates page and select the relevant email template.
  3. Select Edit.
  4. Add a placeholder to the email template using double brackets. For example: “Download your file at: ((link_to_file))”

Your email should also tell recipients how long the file will be available to download.

Add a placeholder to the template

  1. Sign in to GOV.UK Notify.
  2. Go to the Templates page and select the relevant email template.
  3. Select Edit.
  4. Add a placeholder to the email template using double brackets. For example: “Download your file at: ((link_to_file))”

Your email should also tell recipients how long the file will be available to download.

Upload your file

You can upload PDF, CSV, JSON, .odt, .txt, .rtf, .xlsx and MS Word Document files. Your file must be smaller than 2MB. Contact the GOV.UK Notify team if you need to send other file types.

  1. Convert the PDF to a byte[].
  2. Pass the byte[] to the personalisation argument.
  3. Call the sendEmail method.

For example:

ClassLoader classLoader = getClass().getClassLoader();
File file = new File(classLoader.getResource("document_to_upload.pdf").getFile());
byte [] fileContents = FileUtils.readFileToByteArray(file);

HashMap<String, Object> personalisation = new HashMap();
personalisation.put("link_to_file", client.prepareUpload(fileContents));
client.sendEmail(templateId,
                 emailAddress,
                 personalisation,
                 reference,
                 emailReplyToId);

Upload your file

You can upload PDF, CSV, JSON, .odt, .txt, .rtf, .xlsx and MS Word Document files. Your file must be smaller than 2MB. Contact the GOV.UK Notify team if you need to send other file types.

  1. Convert the PDF to a byte[].
  2. Pass the byte[] to the personalisation argument.
  3. Call the sendEmail method.

For example:


byte[] documentContents = File.ReadAllBytes("<file path>");

Dictionary<String, dynamic> personalisation = new Dictionary<String, dynamic>
{
    { "name", "Foo" },
    { "link_to_file", NotificationClient.PrepareUpload(documentContents)}
};

Upload your file

You can upload PDF, CSV, JSON, .odt, .txt, .rtf, .xlsx and MS Word Document files. Your file must be smaller than 2MB. Contact the GOV.UK Notify team if you need to send other file types.

Pass the file object as a value into the personalisation argument. For example:

var fs = require('fs')

fs.readFile('path/to/document.pdf', function (err, pdfFile) {
  console.log(err)
  notifyClient.sendEmail(templateId, emailAddress, {
    personalisation: {
      first_name: 'Amala',
      application_date: '2018-01-01',
      link_to_file: notifyClient.prepareUpload(pdfFile)
    }
  }).then(response => console.log(response)).catch(err => console.error(err))
})

The method returns a promise [external link]. The promise will either:

  • resolve with a response if successful
  • fail with an err if unsuccessful

Upload your file

You can upload PDF, CSV, JSON, .odt, .txt, .rtf, .xlsx and MS Word Document files. Your file must be smaller than 2MB.. Contact the GOV.UK Notify team if you need to send other file types.

Pass the file object as a value into the personalisation argument. For example:

try {
    $file_data = file_get_contents('/path/to/my/file.pdf');

    $response = $notifyClient->sendEmail(
        'betty@example.com',
        'df10a23e-2c0d-4ea5-87fb-82e520cbf93c',
        [
            'name' => 'Betty Smith',
            'dob'  => '12 July 1968',
            'link_to_file' => $notifyClient->prepareUpload( $file_data )
        ]
    );
}
catch (ApiException $e){}
catch (InvalidArgumentException $e){}

Upload your file

You can upload PDF, CSV, JSON, .odt, .txt, .rtf, .xlsx and MS Word Document files. Your file must be smaller than 2MB. Contact the GOV.UK Notify team if you need to send other file types.

Pass the file object as a value into the personalisation argument. For example:

from notifications_python_client import prepare_upload

with open('file.pdf', 'rb') as f:
    ...
    personalisation={
      'first_name': 'Amala',
      'application_date': '2018-01-01',
      'link_to_file': prepare_upload(f),
    }

Upload your file

You can upload PDF, CSV, JSON, .odt, .txt, .rtf, .xlsx and MS Word Document files. Your file must be smaller than 2MB. Contact the GOV.UK Notify team if you need to send other file types.

  1. Pass the file object as an argument to the Notifications.prepare_upload helper method.
  2. Pass the result into the personalisation argument.

For example:

File.open("file.pdf", "rb") do |f|
    ...
    personalisation: {
      first_name: "Amala",
      application_date: "2018-01-01",
      link_to_file: Notifications.prepare_upload(f),
    }
end

Set the filename

To do this you will need version 5.0.0-RELEASE of the Java client library, or a more recent version.

You should provide a filename when you upload your file.

The filename should tell the recipient what the file contains. A memorable filename can help the recipient to find the file again later.

The filename must end with a file extension. For example, .csv for a CSV file. If you include the wrong file extension, recipients may not be able to open your file.

If you do not provide a filename for your file, Notify will:

  • generate a random filename
  • try to add the correct file extension

If Notify cannot add the correct file extension, recipients may not be able to open your file.

ClassLoader classLoader = getClass().getClassLoader();
File file = new File(classLoader.getResource("document_to_upload.pdf").getFile());
byte [] fileContents = FileUtils.readFileToByteArray(file);

HashMap<String, Object> personalisation = new HashMap();
personalisation.put("link_to_file", client.prepareUpload(fileContents, "report.csv"));
client.sendEmail(templateId,
                 emailAddress,
                 personalisation,
                 reference,
                 emailReplyToId);

Set the filename

To do this you will need version 7.0.0 of the .NET client library, or a more recent version.

You should provide a filename when you upload your file.

The filename should tell the recipient what the file contains. A memorable filename can help the recipient to find the file again later.

The filename must end with a file extension. For example, .csv for a CSV file. If you include the wrong file extension, recipients may not be able to open your file.

If you do not provide a filename for your file, Notify will:

  • generate a random filename
  • try to add the correct file extension

If Notify cannot add the correct file extension, recipients may not be able to open your file.


byte[] documentContents = File.ReadAllBytes("<file path>");

Dictionary<String, dynamic> personalisation = new Dictionary<String, dynamic>
{
    { "name", "Foo" },
    { "link_to_file", NotificationClient.PrepareUpload(documentContents, filename = "2023-12-25-daily-report.csv")}
};

Set the filename

To do this you will need version 8.0.0 of the Node client library, or a more recent version.

You should provide a filename when you upload your file.

The filename should tell the recipient what the file contains. A memorable filename can help the recipient to find the file again later.

The filename must end with a file extension. For example, .csv for a CSV file. If you include the wrong file extension, recipients may not be able to open your file.

If you do not provide a filename for your file, Notify will:

  • generate a random filename
  • try to add the correct file extension

If Notify cannot add the correct file extension, recipients may not be able to open your file.

var fs = require('fs')
fs.readFile('path/to/document.csv', function (err, csvFile) {
  console.log(err)
  notifyClient.sendEmail(templateId, emailAddress, {
    personalisation: {
      first_name: 'Amala',
      application_date: '2018-01-01',
      link_to_file: notifyClient.prepareUpload(csvFile, { filename: '2023-12-25-daily-report.csv' })
    }
  }).then(response => console.log(response)).catch(err => console.error(err))
})

Set the filename

To do this you will need version 6.0.0 of the PHP client library, or a more recent version.

You should provide a filename when you upload your file.

The filename should tell the recipient what the file contains. A memorable filename can help the recipient to find the file again later.

The filename must end with a file extension. For example, .csv for a CSV file. If you include the wrong file extension, recipients may not be able to open your file.

If you do not provide a filename for your file, Notify will:

  • generate a random filename
  • try to add the correct file extension

If Notify cannot add the correct file extension, recipients may not be able to open your file.

try {
    $file_data = file_get_contents('/path/to/my/file.csv');

    $response = $notifyClient->sendEmail(
        'betty@example.com',
        'df10a23e-2c0d-4ea5-87fb-82e520cbf93c',
        [
            'name' => 'Betty Smith',
            'dob'  => '12 July 1968',
            'link_to_file' => $notifyClient->prepareUpload( $file_data, "report.csv" )
        ]
    );
}
catch (ApiException $e){}
catch (InvalidArgumentException $e){}

Set the filename

To do this you will need version 9.0.0 of the Python client library, or a more recent version.

You should provide a filename when you upload your file.

The filename should tell the recipient what the file contains. A memorable filename can help the recipient to find the file again later.

The filename must end with a file extension. For example, .csv for a CSV file. If you include the wrong file extension, recipients may not be able to open your file.

If you do not provide a filename for your file, Notify will:

  • generate a random filename
  • try to add the correct file extension

If Notify cannot add the correct file extension, recipients may not be able to open your file.

from notifications_python_client import prepare_upload

with open('file.csv', 'rb') as f:
    ...
    personalisation={
      'first_name': 'Amala',
      'application_date': '2018-01-01',
      'link_to_file': prepare_upload(f, filename='2023-12-25-daily-report.csv'),
    }

Set the filename

To do this you will need version 6.0.0 of the Ruby client library, or a more recent version.

You should provide a filename when you upload your file.

The filename should tell the recipient what the file contains. A memorable filename can help the recipient to find the file again later.

The filename must end with a file extension. For example, .csv for a CSV file. If you include the wrong file extension, recipients may not be able to open your file.

If you do not provide a filename for your file, Notify will:

  • generate a random filename
  • try to add the correct file extension

If Notify cannot add the correct file extension, recipients may not be able to open your file.

File.open("file.csv", "rb") do |f|
    ...
    personalisation: {
      first_name: "Amala",
      application_date: "2018-01-01",
      link_to_file: Notifications.prepare_upload(f, filename="2023-12-25-daily-report.csv"),
    }
end

Ask recipients to confirm their email address before they can download the file

When a recipient clicks the link in the email you’ve sent them, they have to enter their email address. Only someone who knows the recipient’s email address can download the file.

This security feature is turned on by default.

Ask recipients to confirm their email address before they can download the file

When a recipient clicks the link in the email you’ve sent them, they have to enter their email address. Only someone who knows the recipient’s email address can download the file.

This security feature is turned on by default.

Ask recipients to confirm their email address before they can download the file

When a recipient clicks the link in the email you’ve sent them, they have to enter their email address. Only someone who knows the recipient’s email address can download the file.

This security feature is turned on by default.

Ask recipients to confirm their email address before they can download the file

When a recipient clicks the link in the email you’ve sent them, they have to enter their email address. Only someone who knows the recipient’s email address can download the file.

This security feature is turned on by default.

Ask recipients to confirm their email address before they can download the file

When a recipient clicks the link in the email you’ve sent them, they have to enter their email address. Only someone who knows the recipient’s email address can download the file.

This security feature is turned on by default.

Ask recipients to confirm their email address before they can download the file

When a recipient clicks the link in the email you’ve sent them, they have to enter their email address. Only someone who knows the recipient’s email address can download the file.

This security feature is turned on by default.

If you do not want to use this feature, you can turn it off on a file-by-file basis.

To do this you will need version 3.19.0-RELEASE of the Java client library, or a more recent version.

You should not turn this feature off if you send files that contain:

  • personally identifiable information
  • commercially sensitive information
  • information classified as ‘OFFICIAL’ or ‘OFFICIAL-SENSITIVE’ under the Government Security Classifications policy

To let the recipient download the file without confirming their email address, set the confirmEmailBeforeDownload flag to false.

ClassLoader classLoader = getClass().getClassLoader();
File file = new File(classLoader.getResource("document_to_upload.pdf").getFile());
byte [] fileContents = FileUtils.readFileToByteArray(file);

HashMap<String, Object> personalisation = new HashMap();
personalisation.put("link_to_file", client.prepareUpload(fileContents, false, false, "52 weeks"));
client.sendEmail(templateId,
                 emailAddress,
                 personalisation,
                 reference,
                 emailReplyToId);

If you do not want to use this feature, you can turn it off on a file-by-file basis.

To do this you will need version 6.1.0 of the .NET client library, or a more recent version.

You should not turn this feature off if you send files that contain:

  • personally identifiable information
  • commercially sensitive information
  • information classified as ‘OFFICIAL’ or ‘OFFICIAL-SENSITIVE’ under the Government Security Classifications policy

To let the recipient download the file without confirming their email address, set the confirmEmailBeforeDownload flag to false.


byte[] documentContents = File.ReadAllBytes("<file path>");

Dictionary<String, dynamic> personalisation = new Dictionary<String, dynamic>
{
    { "name", "Foo" },
    { "link_to_file", NotificationClient.PrepareUpload(documentContents, false, false)}
};

If you do not want to use this feature, you can turn it off on a file-by-file basis.

To do this you will need version 5.2.0 of the Node.js client library, or a more recent version.

You should not turn this feature off if you send files that contain:

  • personally identifiable information
  • commercially sensitive information
  • information classified as ‘OFFICIAL’ or ‘OFFICIAL-SENSITIVE’ under the Government Security Classifications policy

To let the recipient download the file without confirming their email address, set the confirmEmailBeforeDownload option to false.

var fs = require('fs')

fs.readFile('path/to/document.pdf', function (err, pdfFile) {
  console.log(err)
  notifyClient.sendEmail(templateId, emailAddress, {
    personalisation: {
      first_name: 'Amala',
      application_date: '2018-01-01',
      link_to_file: notifyClient.prepareUpload(pdfFile, { confirmEmailBeforeDownload: false })
    }
  }).then(response => console.log(response)).catch(err => console.error(err))
})

If you do not want to use this feature, you can turn it off on a file-by-file basis.

To do this you will need version 4.2.0 of the PHP client library, or a more recent version.

You should not turn this feature off if you send files that contain:

  • personally identifiable information
  • commercially sensitive information
  • information classified as ‘OFFICIAL’ or ‘OFFICIAL-SENSITIVE’ under the Government Security Classifications policy

To let the recipient download the file without confirming their email address, set the confirm_email_before_download flag to false.

try {
    $file_data = file_get_contents('/path/to/my/file.pdf');

    $response = $notifyClient->sendEmail(
        'betty@example.com',
        'df10a23e-2c0d-4ea5-87fb-82e520cbf93c',
        [
            'name' => 'Betty Smith',
            'dob'  => '12 July 1968',
            'link_to_file' => $notifyClient->prepareUpload( $file_data, false, false )
        ]
    );
}
catch (ApiException $e){}
catch (InvalidArgumentException $e){}

If you do not want to use this feature, you can turn it off on a file-by-file basis.

To do this you will need version 6.4.0 of the Python client library, or a more recent version.

You should not turn this feature off if you send files that contain:

  • personally identifiable information
  • commercially sensitive information
  • information classified as ‘OFFICIAL’ or ‘OFFICIAL-SENSITIVE’ under the Government Security Classifications policy

To let the recipient download the file without confirming their email address, set the confirm_email_before_download flag to False.

from notifications_python_client import prepare_upload

with open('file.pdf', 'rb') as f:
    ...
    personalisation={
      'first_name': 'Amala',
      'application_date': '2018-01-01',
      'link_to_file': prepare_upload(f, confirm_email_before_download=False),
    }

If you do not want to use this feature, you can turn it off on a file-by-file basis.

To do this you will need version 5.4.0 of the Ruby client library, or a more recent version.

You should not turn this feature off if you send files that contain:

  • personally identifiable information
  • commercially sensitive information
  • information classified as ‘OFFICIAL’ or ‘OFFICIAL-SENSITIVE’ under the Government Security Classifications policy

To let the recipient download the file without confirming their email address, set the confirm_email_before_download flag to false.

File.open("file.pdf", "rb") do |f|
    ...
    personalisation: {
      first_name: "Amala",
      application_date: "2018-01-01",
      link_to_file: Notifications.prepare_upload(f, confirm_email_before_download: false),
    }
end

Choose the length of time that a file is available to download

Set the number of weeks you want the file to be available using the retention_period parameter.

To use this feature you will need 3.19.0-RELEASE of the Java client library, or a more recent version.

You can choose any value between 1 week and 78 weeks. When deciding this, you should consider:

  • the need to protect the recipient’s personal information
  • whether the recipient will need to download the file again later

If you do not choose a value, the file will be available for the default period of 26 weeks (6 months).

Files sent before 12 April 2023 had a longer default period of 78 weeks (18 months).

ClassLoader classLoader = getClass().getClassLoader();
File file = new File(classLoader.getResource("document_to_upload.pdf").getFile());
byte [] fileContents = FileUtils.readFileToByteArray(file);

HashMap<String, Object> personalisation = new HashMap();
personalisation.put("link_to_file",
                    client.prepareUpload(
                            fileContents,
                            false,
                            false,
                            new RetentionPeriodDuration(52, ChronoUnit.WEEKS)
                    ));
client.sendEmail(templateId,
                 emailAddress,
                 personalisation,
                 reference,
                 emailReplyToId);

Choose the length of time that a file is available to download

Set the number of weeks you want the file to be available using the retentionPeriod parameter.

To use this feature will need version 6.1.0 of the .NET client library, or a more recent version.

You can choose any value between 1 week and 78 weeks. When deciding this, you should consider:

  • the need to protect the recipient’s personal information
  • whether the recipient will need to download the file again later

If you do not choose a value, the file will be available for the default period of 26 weeks (6 months).

Files sent before 12 April 2023 had a longer default period of 78 weeks (18 months).


byte[] documentContents = File.ReadAllBytes("<file path>");

Dictionary<String, dynamic> personalisation = new Dictionary<String, dynamic>
{
    { "name", "Foo" },
    { "link_to_file", NotificationClient.PrepareUpload(documentContents, false, true, "52 weeks")}
};

Choose the length of time that a file is available to download

Set the number of weeks you want the file to be available using the retentionPeriod option.

To use this feature will need version 5.2.0 of the Node.js client library, or a more recent version.

You can choose any value between 1 week and 78 weeks. When deciding this, you should consider:

  • the need to protect the recipient’s personal information
  • whether the recipient will need to download the file again later

If you do not choose a value, the file will be available for the default period of 26 weeks (6 months).

Files sent before 12 April 2023 had a longer default period of 78 weeks (18 months).

var fs = require('fs')

fs.readFile('path/to/document.pdf', function (err, pdfFile) {
  console.log(err)
  notifyClient.sendEmail(templateId, emailAddress, {
    personalisation: {
      first_name: 'Amala',
      application_date: '2018-01-01',
      link_to_file: notifyClient.prepareUpload(pdfFile, { retentionPeriod: '52 weeks' })
    }
  }).then(response => console.log(response)).catch(err => console.error(err))
})

Choose the length of time that a file is available to download

Set the number of weeks you want the file to be available using the retentionPeriod key.

To use this feature will need version 4.2.0 of the PHP client library, or a more recent version.

You can choose any value between 1 week and 78 weeks. When deciding this, you should consider:

  • the need to protect the recipient’s personal information
  • whether the recipient will need to download the file again later

If you do not choose a value, the file will be available for the default period of 26 weeks (6 months).

Files sent before 12 April 2023 had a longer default period of 78 weeks (18 months).

try {
    $file_data = file_get_contents('/path/to/my/file.pdf');

    $response = $notifyClient->sendEmail(
        'betty@example.com',
        'df10a23e-2c0d-4ea5-87fb-82e520cbf93c',
        [
            'name' => 'Betty Smith',
            'dob'  => '12 July 1968',
            'link_to_file' => $notifyClient->prepareUpload( $file_data, false, null, "52 weeks" )
        ]
    );
}
catch (ApiException $e){}
catch (InvalidArgumentException $e){}

Choose the length of time that a file is available to download

Set the number of weeks you want the file to be available using the retention_period key.

To use this feature will need version 6.4.0 of the Python client library, or a more recent version.

You can choose any value between 1 week and 78 weeks. When deciding this, you should consider:

  • the need to protect the recipient’s personal information
  • whether the recipient will need to download the file again later

If you do not choose a value, the file will be available for the default period of 26 weeks (6 months).

Files sent before 12 April 2023 had a longer default period of 78 weeks (18 months).

from notifications_python_client import prepare_upload

with open('file.pdf', 'rb') as f:
    ...
    personalisation={
      'first_name': 'Amala',
      'application_date': '2018-01-01',
      'link_to_file': prepare_upload(f, retention_period='4 weeks'),
    }

Choose the length of time that a file is available to download

Set the number of weeks you want the file to be available using the retention_period key.

To use this feature will need version 5.4.0 of the Ruby client library, or a more recent version.

You can choose any value between 1 week and 78 weeks. When deciding this, you should consider:

  • the need to protect the recipient’s personal information
  • whether the recipient will need to download the file again later

If you do not choose a value, the file will be available for the default period of 26 weeks (6 months).

Files sent before 12 April 2023 had a longer default period of 78 weeks (18 months).

File.open("file.pdf", "rb") do |f|
    ...
    personalisation: {
      first_name: "Amala",
      application_date: "2018-01-01",
      link_to_file: Notifications.prepare_upload(f, retention_period: '52 weeks'),
    }
end

Error codes

If the request is not successful, the client returns an HTTPError containing the relevant error code.

error.status_code error.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 .pdf, .csv, .txt, .doc, .docx, .xlsx, .rtf or .odt files
400 [{
"error": "BadRequestError",
"message": "`filename` cannot be longer than 100 characters"
}]
Choose a shorter filename
400 [{
"error": "BadRequestError",
"message": "`filename` must end with a file extension. For example, filename.csv"
}]
Include the file extension in your filename
400 [{
"error": "BadRequestError",
"message": "Unsupported value for retention_period '(PERIOD)'. Supported periods are from 1 to 78 weeks."
}]
Choose a period between 1 and 78 weeks
400 [{
"error": "BadRequestError",
"message": "Unsupported value for confirm_email_before_download: '(VALUE)'. Use a boolean true or false value."
}]
Use either true or false
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
400 [{
"error": "BadRequestError",
"message": "Can only send a file by email"
}]
Make sure you are using an email template
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 type of API key
413 File is larger than 2MB The file is too big. Files must be smaller than 2MB
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.

Error codes

If the request is not successful, the client returns a Notify.Exceptions.NotifyClientException containing the relevant error code.

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 .pdf, .csv, .txt, .doc, .docx, .xlsx, .rtf or .odt files
400 [{
"error": "BadRequestError",
"message": "`filename` cannot be longer than 100 characters"
}]
Choose a shorter filename
400 [{
"error": "BadRequestError",
"message": "`filename` must end with a file extension. For example, filename.csv"
}]
Include the file extension in your filename
400 [{
"error": "BadRequestError",
"message": "Unsupported value for retention_period '(PERIOD)'. Supported periods are from 1 to 78 weeks."
}]
Choose a period between 1 and 78 weeks
400 [{
"error": "BadRequestError",
"message": "Unsupported value for confirm_email_before_download: '(VALUE)'. Use a boolean true or false value."
}]
Use either true or false
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
400 [{
"error": "BadRequestError",
"message": "Can only send a file by email"
}]
Make sure you are using an email template
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.
N/A File is larger than 2MB The file is too big. Files must be smaller than 2MB

Response

If the request is successful, the promise resolves with a response object. For example, the response.data property will look like this:

{
  'id': '740e5834-3a29-46b4-9a6f-16142fde533a',
  'reference': 'your_reference_here',
  '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': INTEGER,
    'uri': 'https://api.notifications.service.gov.uk/v2/template/f33517ff-2a88-4f6e-b855-c550268ce08a'
  }
}

Response

If the request to the client is successful, the client returns an array:

[
    "id" => "bfb50d92-100d-4b8b-b559-14fa3b091cda",
    "reference" => None,
    "content" => [
        "subject" => "SUBJECT TEXT",
        "body" => "MESSAGE TEXT",
        "from_email" => "SENDER EMAIL
    ],
    "uri" => "https://api.notifications.service.gov.uk/v2/notifications/ceb50d92-100d-4b8b-b559-14fa3b091cd",
    "template" => [
        "id" => "ceb50d92-100d-4b8b-b559-14fa3b091cda",
        "version" => 1,
        "uri" => "https://api.notificaitons.service.gov.uk/service/your_service_id/templates/bfb50d92-100d-4b8b-b559-14fa3b091cda"
    ]
];

Response

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": INTEGER,
    "uri": "https://api.notifications.service.gov.uk/v2/template/f33517ff-2a88-4f6e-b855-c550268ce08a"
  }
}

Response

If the request to the client is successful, the client returns a Notifications::Client:ResponseNotification object. In the example shown in the Method section, the object is named emailresponse.

You can then call different methods on this object to return the requested information.

Method Information Type
emailresponse.id Notification UUID String
emailresponse.reference reference argument String
emailresponse.content - body: Message body
- subject: Message subject
- from_email: From email address of your service found on the Settings page
Hash
emailresponse.template Contains the id, version and uri of the template Hash
emailresponse.uri Notification URL String

Error codes

If the request is not successful, the promise fails with an err.

err.response.data.status_code err.response.data.errors 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 .pdf, .csv, .txt, .doc, .docx, .xlsx, .rtf or .odt files
400 [{
"error": "BadRequestError",
"message": "`filename` cannot be longer than 100 characters"
}]
Choose a shorter filename
400 [{
"error": "BadRequestError",
"message": "`filename` must end with a file extension. For example, filename.csv"
}]
Include the file extension in your filename
400 [{
"error": "BadRequestError",
"message": "Unsupported value for retention_period '(PERIOD)'. Supported periods are from 1 to 78 weeks."
}]
Choose a period between 1 and 78 weeks
400 [{
"error": "BadRequestError",
"message": "Unsupported value for confirm_email_before_download: '(VALUE)'. Use a boolean true or false value."
}]
Use either true or false
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
400 [{
"error": "BadRequestError",
"message": "Can only send a file by email"
}]
Make sure you are using an email template
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.
N/A File is larger than 2MB The file is too big. Files must be smaller than 2MB

Error codes

If the request is not successful, the client returns an Alphagov\Notifications\Exception\ApiException object containing the relevant error code.

exc->getCode() exc->getErrors() 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 .pdf, .csv, .txt, .doc, .docx, .xlsx, .rtf or .odt files.
400 [{
"error": "BadRequestError",
"message": "`filename` cannot be longer than 100 characters"
}]
Choose a shorter filename
400 [{
"error": "BadRequestError",
"message": "`filename` must end with a file extension. For example, filename.csv"
}]
Include the file extension in your filename
400 [{
"error": "BadRequestError",
"message": "Unsupported value for retention_period '(PERIOD)'. Supported periods are from 1 to 78 weeks."
}]
Choose a period between 1 and 78 weeks
400 [{
"error": "BadRequestError",
"message": "Unsupported value for confirm_email_before_download: '(VALUE)'. Use a boolean true or false value."
}]
Use either true or false
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
400 [{
"error": "BadRequestError",
"message": "Can only send a file by email"
}]
Make sure you are using an email template
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.
N/A Exception\InvalidArgumentException( 'File is larger than 2MB.' ) The file is too big. Files must be smaller than 2MB.

Error codes

If the request is not successful, the client returns an HTTPError containing the relevant error code.

error.status_code error.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 email in trial mode
400 [{
"error": "BadRequestError",
"message": "Unsupported file type '(FILE TYPE)'. Supported types are: '(ALLOWED TYPES)'"
}]
Wrong file type. You can only upload .pdf, .csv, .txt, .doc, .docx, .xlsx, .rtf or .odt files
400 [{
"error": "BadRequestError",
"message": "`filename` cannot be longer than 100 characters"
}]
Choose a shorter filename
400 [{
"error": "BadRequestError",
"message": "`filename` must end with a file extension. For example, filename.csv"
}]
Include the file extension in your filename
400 [{
"error": "BadRequestError",
"message": "Unsupported value for retention_period '(PERIOD)'. Supported periods are from 1 to 78 weeks."
}]
Choose a period between 1 and 78 weeks
400 [{
"error": "BadRequestError",
"message": "Unsupported value for confirm_email_before_download: '(VALUE)'. Use a boolean true or false value."
}]
Use either True or False
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
400 [{
"error": "BadRequestError",
"message": "Can only send a file by email"
}]
Make sure you are using an email template
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 email.
- ValueError('File is larger than 2MB') The file is too big. Files must be smaller than 2MB.

Error codes

If the request is not successful, the client raises a Notifications::Client::RequestError exception (or a subclass), which contains a code:

error.code error.message class How to fix
400 BadRequestError: Can't send to this recipient using a team-only API key BadRequestError Use the correct type of API key
400 BadRequestError: Can't send to this recipient when service is in trial mode - see https://www.notifications.service.gov.uk/trial-mode BadRequestError Your service cannot send this notification in trial mode
400 BadRequestError: Unsupported file type '(FILE TYPE)'. Supported types are: '(ALLOWED TYPES)' BadRequestError Wrong file type. You can only upload .pdf, .csv, .txt, .doc, .docx, .xlsx, .rtf or .odt files
400 BadRequestError: `filename` cannot be longer than 100 characters" BadRequestError Choose a shorter filename
400 BadRequestError: `filename` must end with a file extension. For example, filename.csv" BadRequestError Include the file extension in your filename
400 BadRequestError: Unsupported value for retention_period '(PERIOD)'. Supported periods are from 1 to 78 weeks. BadRequestError Choose a period between 1 and 78 weeks
400 BadRequestError: Unsupported value for confirm_email_before_download: '(VALUE)'. Use a boolean true or false value. BadRequestError Use either true or false
400 BadRequestError: File did not pass the virus scan BadRequestError The file contains a virus
400 BadRequestError: 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 BadRequestError See how to add contact details to the file download page
400 BadRequestError: Can only send a file by email BadRequestError Make sure you are using an email template
403 AuthError: Error: Your system clock must be accurate to within 30 seconds AuthError Check your system clock
403 AuthError: Invalid token: API key not found AuthError Use the correct API key. Refer to API keys for more information
429 RateLimitError: Exceeded rate limit for key type TEAM/TEST/LIVE of 3000 requests per 60 seconds RateLimitError Refer to API rate limits for more information
429 TooManyRequestsError: Exceeded send limits (LIMIT NUMBER) for today RateLimitError Refer to service limits for the limit number
500 Exception: Internal server error ServerError Notify was unable to process the request, resend your notification
- ArgumentError: File is larger than 2MB") - The file is too big. Files must be smaller than 2MB

Send a letter

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:

  1. Sign in to GOV.UK Notify.
  2. Go to the Settings page.
  3. In the Your service is in trial mode section, select request to go live.

Send a letter

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:

  1. Sign in to GOV.UK Notify.
  2. Go to the Settings page.
  3. In the Your service is in trial mode section, select request to go live.

Send a letter

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:

  1. Sign in to GOV.UK Notify.
  2. Go to the Settings page.
  3. In the Your service is in trial mode section, select request to go live.

Send a letter

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:

  1. Sign in to GOV.UK Notify.
  2. Go to the Settings page.
  3. In the Your service is in trial mode section, select request to go live.

Send a letter

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:

  1. Sign in to GOV.UK Notify.
  2. Go to the Settings page.
  3. In the Your service is in trial mode section, select request to go live.

Send a letter

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:

  1. Sign in to GOV.UK Notify.
  2. Go to the Settings page.
  3. In the Your service is in trial mode section, select request to go live.

Method

SendLetterResponse response = client.sendLetter(
    templateId,
    personalisation,
    reference
);

Method

Dictionary<String, dynamic> personalisation = new Dictionary<String, dynamic>
{
    { "address_line_1", "The Occupier" }, // required
    { "address_line_2", "123 High Street" }, // required
    { "address_line_3", "SW14 6BF" }, // required
      ... // any other optional address lines, or personalisation fields found in your template
};

LetterNotificationResponse response = client.SendLetter(templateId, personalisation, reference);

Method

notifyClient
  .sendLetter(templateId, {
    personalisation: personalisation,
    reference: reference
  })
  .then(response => console.log(response))
  .catch(err => console.error(err))

The method returns a promise [external link]. The promise will either:

  • resolve with a response if successful
  • fail with an err if unsuccessful

Method

sendLetter( $templateId, array $personalisation = array(), $reference = '' )

For example:

try {

    $response = $notifyClient->sendEmail(
        'df10a23e-2c0d-4ea5-87fb-82e520cbf93c',
        [
            'name'=>'Fred',
            'address_line_1' => 'Foo',
            'address_line_2' => 'Bar',
            'address_line_3' => 'SW1 1AA'
        ],
        'unique_ref123'
    );

} catch (ApiException $e){}

Method

    response = notifications_client.send_letter_notification(
        template_id='f33517ff-2a88-4f6e-b855-c550268ce08a', # required UUID string
        personalisation={
          'address_line_1': 'The Occupier' # required string,
          'address_line_2': '123 High Street' # required string,
          'address_line_3': 'SW14 6BH' # required string,
        },
    )

Method

letterresponse = client.send_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',
  },
)

Arguments

Arguments

Arguments

Arguments

Arguments

Arguments

templateId (required)

To find the template ID:

  1. Sign in to GOV.UK Notify.
  2. Go to the Templates page and select the relevant template.
  3. Select Copy template ID to clipboard.

For example:

String templateId = "f33517ff-2a88-4f6e-b855-c550268ce08a";
templateId (required)

To find the template ID:

  1. Sign in to GOV.UK Notify.
  2. Go to the Templates page and select the relevant template.
  3. Select Copy template ID to clipboard.

For example:

string templateId: "f33517ff-2a88-4f6e-b855-c550268ce08a";
templateId (required)

To find the template ID:

  1. Sign in to GOV.UK Notify.
  2. Go to the Templates page and select the relevant template.
  3. Select Copy template ID to clipboard.

For example:

"f33517ff-2a88-4f6e-b855-c550268ce08a"
templateId (required)

To find the template ID:

  1. Sign in to GOV.UK Notify.
  2. Go to the Templates page and select the relevant template.
  3. Select Copy template ID to clipboard.
template_id (required)

To find the template ID:

  1. Sign in to GOV.UK Notify.
  2. Go to the Templates page and select the relevant template.
  3. Select Copy template ID to clipboard.
template_id (required)

To find the template ID:

  1. Sign in to GOV.UK Notify.
  2. Go to the Templates page and select the relevant template.
  3. Select Copy template ID to clipboard.

For example:

template_id: "f33517ff-2a88-4f6e-b855-c550268ce08a"
personalisation (required)

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 must provide their values in a map. For example:

Map<String, Object> personalisation = new HashMap<>();
personalisation.put("address_line_1", "The Occupier"); // mandatory address field
personalisation.put("address_line_2", "Flat 2"); // mandatory address field
personalisation.put("address_line_3", "SW14 6BH"); // mandatory address field, must be a real UK postcode
personalisation.put("first_name", "Amala"); // field from template
personalisation.put("application_date", "2018-01-01"); // field from template
// pass in a list and it will appear as bullet points in the letter:
personalisation.put("list", listOfItems);

If a template does not have any placeholder fields for personalised information, you must pass in an empty map or null.

personalisation (required)

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. For example:

Dictionary<String, dynamic> personalisation = new Dictionary<String, dynamic>
{
    {"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"},
    {"first_name", "Amala"},
    {"application_id", "4134325"},
    // pass in a list and it will appear as bullet points in the letter:
    {"required_documents", new List<string> {"passport", "utility bill", "other id"}}
};
personalisation (required)

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 must provide their values in an object. For example:

{
  personalisation: {
    'address_line_1': 'The Occupier',
    'address_line_2': '123 High Street',
    'address_line_3': 'SW14 6BH',
    'application_date': '2018-01-01',
    // pass in an array and it will appear as bullet points in the letter:
    'required_documents': ['passport', 'utility bill', 'other id']
  }
}
personalisation (required)

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',
            # pass in an array and it will appear as bullet points in the letter:
            'required_documents' => ['passport', 'utility bill', 'other id']
          ];
personalisation (required)

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',
  # pass in a list and it will appear as bullet points in the letter:
  "required_documents": ["passport", "utility bill", "other id"],
}
personalisation (required)

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 must provide their values in a hash. For example:

personalisation: {
  address_line_1: 'The Occupier',  # mandatory address field
  address_line_2: '123 High Street', # mandatory address field
  address_line_3: 'SW14 6BH',  # mandatory address field
  name: 'John Smith', # field from template
  application_date: '2018-01-01' # field from template,
  # pass in an array and it will appear as bullet points in the letter:
  required_documents: ["passport", "utility bill", "other id"],
},
reference (required)

A unique identifier you create. This reference identifies a single unique notification or a batch of notifications. It must not contain any personal information such as name or postal address. If you do not have a reference, you must pass in an empty string or null.

String reference='STRING';
reference (optional)

A unique identifier you can create if you need to. This reference identifies a single unique notification or a batch of notifications. It must not contain any personal information such as name or postal address. For example:

string reference: "STRING";

You can leave out this argument if you do not have a reference.

reference (optional)

A unique identifier you can create if required. This reference identifies a single unique notification or a batch of notifications. It must not contain any personal information such as name or postal address. For example:

"your_reference_here"
reference (optional)

A unique identifier you can create if necessary. This reference identifies a single unique notification or a batch of notifications. It must not contain any personal information such as name or postal address. For example:

$reference = 'STRING';
reference (optional)

A unique identifier you can create if necessary. This reference identifies a single unique letter or a batch of letters. It must not contain any personal information such as name or postal address. For example:

reference='STRING' # optional string - identifies notification(s)
reference (optional)

A unique identifier you can create if necessary. This reference identifies a single unique notification or a batch of notifications. It must not contain any personal information such as name or postal address. For example:

reference: 'your_reference_string'

Response

If the request to the client is successful, the client returns a SendLetterResponse:

UUID notificationId;
Optional<String> reference;
UUID templateId;
int templateVersion;
String templateUri;
String body;
String subject;

Response

If the request to the client is successful, the client returns a LetterNotificationResponse:

public String id;
public String reference;
public String uri;
public Template template;
public string postage;
public LetterResponseContent content;

public class Template
{
    public String id;
    public String uri;
    public Int32 version;
}
public class LetterResponseContent{
    public string body;
    public string subject;
}

Response

If the request is successful, the promise resolves with a response object. For example, the response.data property will look like this:

{
  'id': '740e5834-3a29-46b4-9a6f-16142fde533a',
  'reference': null,
  'content': {
    'subject': 'Licence renewal',
    'body': 'Dear Bill, your licence is due for renewal on 3 January 2016.'
  },
  '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': null
}

Response

If the request to the client is successful, the client returns an array:

[
    "id" => "bfb50d92-100d-4b8b-b559-14fa3b091cda",
    "reference" => "unique_ref123",
    "content" => [
        "subject" => "Licence renewal",
        "body" => "Dear Bill, your licence is due for renewal on 3 January 2016.",
    ],
    "uri" => "https://api.notifications.service.gov.uk/v2/notifications/ceb50d92-100d-4b8b-b559-14fa3b091cd",
    "template" => [
        "id" => "ceb50d92-100d-4b8b-b559-14fa3b091cda",
        "version" => 1,
        "uri" => "https://api.notifications.service.gov.uk/service/your_service_id/templates/bfb50d92-100d-4b8b-b559-14fa3b091cda"
    ],
    "scheduled_for" => null
];

Response

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": "LETTER TEXT",
  },
  "uri": "https://api.notifications.service.gov.uk/v2/notifications/740e5834-3a29-46b4-9a6f-16142fde533a",
  "template": {
    "id": "f33517ff-2a88-4f6e-b855-c550268ce08a",
    "version": INTEGER,
    "uri": "https://api.notifications.service.gov.uk/v2/template/f33517ff-2a88-4f6e-b855-c550268ce08a"
  }
  "scheduled_for": None
}

Response

If the request to the client is successful, the client returns a Notifications::Client:ResponseNotification object. In the example shown in the Method section, the object is named letterresponse.

You can then call different methods on this object to return the requested information.

Method Information Type
letterresponse.id Notification UUID String
letterresponse.reference reference argument String
letterresponse.content - body: Letter body
- subject: Letter subject or main heading
Hash
letterresponse.template Contains the id, version and uri of the template Hash
letterresponse.uri Notification URL String

Error codes

If the request is not successful, the client returns a NotificationClientException containing the relevant error code:

httpResult Message How to fix
403 [{
"error": "BadRequestError",
"message": "Cannot send letters with a team api key"
}]
Use the correct type of API key.
400 [{
"error": "BadRequestError",
"message": "Cannot 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, refer to 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.

Error codes

If the request is not successful, the client returns a Notify.Exceptions.NotifyClientException containing the relevant error code.

Status code Message How to fix
403 [{
"error": "BadRequestError",
"message": "Cannot send letters with a team api key"
}]
Use the correct type of API key.
400 [{
"error": "BadRequestError",
"message": "Cannot 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, refer to 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.

Error codes

If the request is not successful, the promise fails with an err.

err.response.data.status_code err.response.data.errors How to fix
403 [{
"error": "BadRequestError",
"message": "Cannot send letters with a team api key"
}]
Use the correct type of API key.
400 [{
"error": "BadRequestError",
"message": "Cannot 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, refer to 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.

Error codes

If the request is not successful, the client returns an Alphagov\Notifications\Exception\ApiException object containing the relevant error code.

exc->getCode() exc->getErrors() How to fix
403 [{
"error": "BadRequestError",
"message": "Cannot send letters with a team api key"
}]
Use the correct type of API key.
400 [{
"error": "BadRequestError",
"message": "Cannot 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.

Error codes

If the request is not successful, the client returns an HTTPError containing the relevant error code.

error.status_code error.message How to fix
403 [{
"error": "BadRequestError",
"message": "Cannot send letters with a team api key"
}]
Use the correct type of API key
400 [{
"error": "BadRequestError",
"message": "Cannot send letters when service is in trial mode - see https://www.notifications.service.gov.uk/trial-mode"
}]
Your service cannot send this letter 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 letter.

Error codes

If the request is not successful, the client raises a Notifications::Client::RequestError exception (or a subclass), which contains a code:

error.code error.message class How to fix
403 BadRequestError: Cannot send letters with a team api key BadRequestError Use the correct type of API key.
400 BadRequestError: Cannot send letters when service is in trial mode - see https://www.notifications.service.gov.uk/trial-mode BadRequestError Your service cannot send this notification in trial mode.
400 ValidationError: personalisation address_line_1 is a required property BadRequestError Ensure that your template has a field for the first line of the address, refer to 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 AuthError: Error: Your system clock must be accurate to within 30 seconds AuthError Check your system clock.
403 AuthError: Invalid token: API key not found AuthError Use the correct API key. Refer to API keys for more information.
429 RateLimitError: Exceeded rate limit for key type TEAM/TEST/LIVE of 3000 requests per 60 seconds RateLimitError Refer to API rate limits for more information.
429 TooManyRequestsError: Exceeded send limits (LIMIT NUMBER) for today RateLimitError Refer to service limits for the limit number.
500 Exception: Internal server error ServerError Notify was unable to process the request, resend your notification.

Send a precompiled letter

Send a precompiled letter

Send a precompiled letter

Send a precompiled letter

Send a precompiled letter

Send a precompiled letter

Method

LetterResponse response = client.sendPrecompiledLetter(
    reference,
    precompiledPDFAsFile
    );
LetterResponse response = client.sendPrecompiledLetterWithInputStream(
    reference,
    precompiledPDFAsInputStream
    );
LetterResponse response = client.sendPrecompiledLetter(
    reference,
    precompiledPDFAsFile,
    postage
    );
LetterResponse response = client.sendPrecompiledLetterWithInputStream(
    reference,
    precompiledPDFAsInputStream,
    postage
    );

Method

LetterNotificationsResponse response = client.SendPrecompiledLetter(
    clientReference,
    pdfContents,
    postage
    );

Method

var response = notifyClient.sendPrecompiledLetter(
  reference,
  pdfFile,
  postage
)

Method

$response = $notifyClient->sendPrecompiledLetter(
    $reference,
    $pdf_data,
    $postage,
);

Method

response = notifications_client.send_precompiled_letter_notification(
    reference,      # Reference to identify the notification
    pdf_file,       # PDF File object
    postage         # set postage on your precompiled letter
)

Method

precompiled_letter = client.send_precompiled_letter(reference, pdf_file)

Arguments

Arguments

Arguments

Arguments

Arguments

Arguments

reference (required)

A unique identifier you create. This reference identifies a single unique notification or a batch of notifications. It must not contain any personal information such as name or postal address.

String reference="STRING";
clientReference (required)

A unique identifier you create. This reference identifies a single unique notification or a batch of notifications. It must not contain any personal information such as name or postal address.

reference (required)

A unique identifier you create. This reference identifies a single unique notification or a batch of notifications. It must not contain any personal information such as name or postal address. For example:

"your_reference_here"
reference (required)

A unique identifier you create if necessary. This reference identifies a single unique notification or a batch of notifications. It must not contain any personal information such as name or postal address.

$reference = 'STRING';
reference (required)

A unique identifier you create. This reference identifies a single unique precompiled letter or a batch of precompiled letters. It must not contain any personal information such as name or postal address.

reference (required)

A unique identifier you create. This reference identifies a single unique notification or a batch of notifications. It must not contain any personal information such as name or postal address.

precompiledPDFAsFile (required for the sendPrecompiledLetter method)

The precompiled letter must be a PDF file which meets the GOV.UK Notify letter specification.

This argument adds the precompiled letter PDF file to a Java file object. The method sends this Java file object to GOV.UK Notify.

File precompiledPDF = new File("<PDF file path>");
pdfContents (required for the SendPrecompiledLetter method)

The precompiled letter must be a PDF file which meets the GOV.UK Notify letter specification. The method sends the contents of the file to GOV.UK Notify.

byte[] pdfContents = File.ReadAllBytes("<PDF file path>");
pdfFile

The precompiled letter must be a PDF file which meets the GOV.UK Notify letter specification. For example:

var fs = require('fs')

fs.readFile('path/to/document.pdf', function (err, pdfFile) {
  if (err) {
    console.error(err)
  }
  var notification = notifyClient.sendPrecompiledLetter(
    'your reference', pdfFile
  )
})
pdf_data (required)

The precompiled letter must be a PDF file which meets the GOV.UK Notify letter specification. The method sends the contents of the file to GOV.UK Notify.

$pdf_data = file_get_contents("path/to/pdf_file");
try {

    $response = $notifyClient->sendPrecompiledLetter(
        'unique_ref123',
        $pdf_data,
        'first',
    );

} catch (ApiException $e){}
pdf_file (required)

The precompiled letter must be a PDF file which meets the GOV.UK Notify letter specification.

with open("path/to/pdf_file", "rb") as pdf_file:
    notification = notifications_client.send_precompiled_letter_notification(
        reference="your reference", pdf_file=pdf_file
    )
pdf_file (required)

The precompiled letter must be a PDF file which meets the GOV.UK Notify letter specification.

File.open("path/to/pdf_file", "rb") do |pdf_file|
    client.send_precompiled_letter("your reference", pdf_file)
end
precompiledPDFAsInputStream (required for the sendPrecompiledLetterWithInputStream method)

The precompiled letter must be an InputStream. This argument adds the precompiled letter PDF content to a Java InputStream object. The method sends this InputStream to GOV.UK Notify.

InputStream precompiledPDFAsInputStream = new FileInputStream(pdfContent);
postage (optional)

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 (optional)

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 (optional)

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 = 'first';
postage (optional)

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 (optional)

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 (optional)

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.

Response

If the request to the client is successful, the client returns a LetterResponse:

UUID notificationId;
String reference;
String postage

Response

If the request to the client is successful, the client returns a LetterNotificationResponse with the id, reference and postage:

public String id;
public String reference;
public String postage;
public String uri;  // null for this response
public Template template;  // null for this response
public LetterResponseContent content;  // null for this response

Response

If the request is successful, the promise resolves with a response object. For example, the response.data property will look like this:

{
  'id': '740e5834-3a29-46b4-9a6f-16142fde533a',
  'reference': 'your-letter-reference',
  'postage': 'second'
}

Response

If the request to the client is successful, the client returns an array:

[
  "id" => "740e5834-3a29-46b4-9a6f-16142fde533a",
  "reference" => "unique_ref123",
  "postage" => "first"
];

Response

If the request to the client is successful, the client returns a dict:

{
  "id": "740e5834-3a29-46b4-9a6f-16142fde533a",
  "reference": "your-letter-reference",
  "postage": "postage-you-have-set-or-None"
}

Response

If the request to the client is successful, the client returns a Notifications::Client:ResponsePrecompiledLetter object. In the example shown in the Method section, the object is named precompiled_letter.

You can then call different methods on this object to return the requested information.

Method Information Type
precompiled_letter.id Notification UUID String
precompiled_letter.reference reference argument String
precompiled_letter.postage postage argument String

Error codes

If the request is not successful, the client returns a NotificationClientException containing the relevant error code:

httpResult Message How to fix
403 [{
"error": "BadRequestError",
"message": "Cannot send letters with a team api key"
}]
Use the correct type of API key
400 [{
"error": "BadRequestError",
"message": "Cannot 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"
}]
Send a valid PDF file
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’
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
400 "message":"precompiledPDF must be a valid PDF file" Send a valid PDF file
400 "message":"reference cannot be null or empty" Populate the reference parameter
400 "message":"precompiledPDF cannot be null or empty" Send a PDF file with data in it

Error codes

If the request is not successful, the client returns a Notify.Exceptions.NotifyClientException containing the relevant error code.

Status code Message How to fix
403 [{
"error": "BadRequestError",
"message": "Cannot send letters with a team api key"
}]
Use the correct type of API key
400 [{
"error": "BadRequestError",
"message": "Cannot 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"
}]
Send a valid PDF file
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’
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
N/A "message":"precompiledPDF must be a valid PDF file" Send a valid PDF file
N/A "message":"reference cannot be null or empty" Populate the reference parameter
N/A "message":"precompiledPDF cannot be null or empty" Send a PDF file with data in it

Error codes

If the request is not successful, the promise fails with an err.

err.response.data.status_code err.response.data.errors How to fix
403 [{
"error": "BadRequestError",
"message": "Cannot send letters with a team api key"
}]
Use the correct type of API key
400 [{
"error": "BadRequestError",
"message": "Cannot 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"
}]
Send a valid PDF file
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’
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
N/A "message":"precompiledPDF must be a valid PDF file" Send a valid PDF file
N/A "message":"reference cannot be null or empty" Populate the reference parameter
N/A "message":"precompiledPDF cannot be null or empty" Send a PDF file with data in it

Error codes

If the request is not successful, the client returns an Alphagov\Notifications\Exception\ApiException object containing the relevant error code.

exc->getCode() exc->getErrors() How to fix
403 [{
"error": "BadRequestError",
"message": "Cannot 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": "Cannot 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 (LIMIT NUMBER) for today"
}]
Refer to service limits for the limit number.

Error codes

If the request is not successful, the client returns an HTTPError containing the relevant error code.

error.status_code error.message How to fix
403 [{
"error": "BadRequestError",
"message": "Cannot 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": "Cannot send letters when service is in trial mode - see https://www.notifications.service.gov.uk/trial-mode"
}]
Your service cannot send this precompiled letter 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

Error codes

If the request is not successful, the client raises a Notifications::Client::RequestError exception (or a subclass), which contains a code:

error.status_code error.message class How to fix
403 BadRequestError: Cannot send letters with a team api key BadRequestError Use the correct type of API key
400 BadRequestError: Letter content is not a valid PDF BadRequestError PDF file format is required
400 BadRequestError: Cannot send letters when service is in trial mode - see https://www.notifications.service.gov.uk/trial-mode BadRequestError Your service cannot send this notification in trial mode
400 ValidationError: reference is a required property BadRequestError Add a reference argument to the method call
400 ValidationError: postage invalid. It must be either first or second. BadRequestError Change the value of postage argument in the method call to either ‘first’ or ‘second’
429 RateLimitError: Exceeded rate limit for key type live of 10 requests per 20 seconds RateLimitError Use the correct API key. Refer to API keys for more information
429 TooManyRequestsError: Exceeded send limits (50) for today RateLimitError Refer to service limits for the limit number

Get message status

Get message status

Get message status

Get message status

Get message status

Get message status

Send a message

You can use GOV.UK Notify to send emails, text messages and letters.

Get the status of one message

You can only get the status of messages sent within the retention period. The default retention period is 7 days.

Get the status of one message

You can only get the status of messages sent within the retention period. The default retention period is 7 days.

Get the status of one message

You can only get the status of messages sent within the retention period. The default retention period is 7 days.

Get the status of one message

You can only get the status of messages sent within the retention period. The default retention period is 7 days.

Get the status of one message

You can only get the status of messages sent within the retention period. The default retention period is 7 days.

Get the status of one message

You can only get the status of messages sent within the retention period. The default retention period is 7 days.

Send a text message

POST /v2/notifications/sms

Method

Notification notification = client.getNotificationById(notificationId);

Method

Notification notification = client.GetNotificationById(notificationId);

Method

notifyClient
  .getNotificationById(notificationId)
  .then((response) => console.log(response))
  .catch((err) => console.error(err))

The method returns a promise [external link]. The promise will either:

  • resolve with a response if successful
  • fail with an err if unsuccessful

Method

getNotification( $notificationId )

For example:

try {

    $response = $notifyClient->getNotification( 'c32e9c89-a423-42d2-85b7-a21cd4486a2a' );

} catch (ApiException $e){}

Method

response = notifications_client.get_notification_by_id(notification_id)

Method

response = client.get_notification(id)

Request body

{
  "phone_number": "+447900900123",
  "template_id": "f33517ff-2a88-4f6e-b855-c550268ce08a"
}

Arguments

Arguments

Arguments

Arguments

Arguments

Arguments

Arguments

notificationId (required)

The ID of the notification. To find the notification ID, you can either:

notificationId (required)

The ID of the notification. To find the notification ID, you can either:

notificationId (required)

The ID of the notification. To find the notification ID, you can either:

notificationId (required)

The ID of the notification. To find the notification ID, you can either:

notification_id (required)

The ID of the notification. To find the notification ID, you can either:

id (required)

The ID of the notification. To find the notification ID, you can either:

phone_number (required)

The phone number of the recipient of the text message. This can be a UK or international number.

template_id (required)

To find the template ID:

  1. Sign in to GOV.UK Notify.
  2. Go to the Templates page and select the relevant template.
  3. Select Copy template ID to clipboard.
personalisation (optional)

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.

reference (optional)

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.

sms_sender_id (optional)

A unique identifier of the sender of the text message notification.

To find the text message sender:

  1. Sign in to GOV.UK Notify.
  2. Go to the Settings page.
  3. 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.

Response

If the request to the client is successful, the client returns a Notification:

UUID id;
Optional<String> reference;
Optional<String> emailAddress;
Optional<String> phoneNumber;
Optional<String> line1;
Optional<String> line2;
Optional<String> line3;
Optional<String> line4;
Optional<String> line5;
Optional<String> line6;
Optional<String> line7;
Optional<String> postage;
String notificationType;
String status;
UUID templateId;
int templateVersion;
String templateUri;
String body;
Optional<String subject;
ZonedDateTime createdAt;
Optional<ZonedDateTime> sentAt;
Optional<ZonedDateTime> completedAt;
Optional<ZonedDateTime> estimatedDelivery;
Optional<String> createdByName;

Response

If the request to the client is successful, the client returns a Notification.

public String id;
public String completedAt;
public String createdAt;
public String emailAddress;
public String body;
public String subject;
public String line1;
public String line2;
public String line3;
public String line4;
public String line5;
public String line6;
public String line7;
public String phoneNumber;
public String postage;
public String reference;
public String sentAt;
public String status;
public Template template;
public String type;
public string createdByName;

public class Template
{
    public String id;
    public String uri;
    public Int32 version;
}


Response

If the request is successful, the promise resolves with a response object. For example, the response.data property will look like this:

{
  'id': 'notify_id',
  'body': 'Hello Foo',
  'subject': 'null|email_subject',
  'reference': 'client reference',
  'email_address': 'email address',
  'phone_number': 'phone number',
  'line_1': 'full name of a person or company',
  'line_2': '123 The Street',
  'line_3': 'Some Area',
  'line_4': 'Some Town',
  'line_5': 'Some county',
  'line_6': 'Something else',
  'line_7': 'UK postcode or country',
  'postage': 'first or second',
  'type': 'sms|letter|email',
  'status': 'current status',
  'template': {
    'version': 1,
    'id': 1,
    'uri': '/template/{id}/{version}'
  },
  'created_by_name': 'name of the person who sent the notification if sent manually',
  'created_at': 'created at',
  'sent_at': 'sent to provider at'
}

Response

If the request to the client is successful, the client returns an array:

[
    "id" => "notify_id",
    "body" => "Hello Foo",
    "subject" => "null|email_subject",
    "reference" => "client reference",
    "email_address" => "email address",
    "phone_number" => "phone number",
    "line_1" => "full name of a person or company",
    "line_2" => "123 The Street",
    "line_3" => "Some Area",
    "line_4" => "Some Town",
    "line_5" => "Some county",
    "line_6" => "Something else",
    "line_7" => "Postcode or country",
    "postage" => "null|first|second",
    "type" => "sms|letter|email",
    "status" => "current status",
    "template" => [
        "version" => 1,
        "id" => 1,
        "uri" => "/template/{id}/{version}"
     ],
    "created_at" => "created at",
    "sent_at" => "sent to provider at",
];

Response

If the request to the client is successful, the client will return a dict:

{
  "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", # 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
  "line_7": "ADDRESS LINE 7", # required string for letter
  "type": "sms / letter / email", # required string
  "status": "sending / delivered / permanent-failure / temporary-failure / technical-failure", # required string
  "template": {
    "Version": INTEGER
    "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
}

For more information, see the:

Response

If the request to the client is successful, the client returns a Notifications::Client::Notification object. In the example shown in the Method section, the object is named response.

You can then call different methods on this object to return the requested information.

Method Information Type
response.id Notification UUID String
response.reference String supplied in reference argument String
response.email_address Recipient email address (email only) String
response.phone_number Recipient phone number (SMS only) String
response.line_1 Recipient address line 1 of the address (letter only) String
response.line_2 Recipient address line 2 of the address (letter only) String
response.line_3 Recipient address line 3 of the address (letter only) String
response.line_4 Recipient address line 4 of the address (letter only) String
response.line_5 Recipient address line 5 of the address (letter only) String
response.line_6 Recipient address line 6 of the address (letter only) String
response.line_7 Recipient address line 7 of the address (letter only) String
response.postage Postage class of the notification sent (letter only) String
response.type Type of notification sent (sms, email or letter) String
response.status Notification status (sending / delivered / permanent-failure / temporary-failure / technical-failure) String
response.template Template UUID String
response.body Notification body String
response.subject Notification subject (email and letter) String
response.sent_at Date and time notification sent to provider String
response.created_at Date and time notification created String
response.completed_at Date and time notification delivered or failed String
response.created_by_name Name of sender if notification sent manually String

Response

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.

Error codes

If the request is not successful, the client returns a NotificationClientException containing the relevant error code:

httpResult 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

Error codes

If the request is not successful, the client returns a Notify.Exceptions.NotifyClientException containing the relevant error code.

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

Error codes

If the request is not successful, the promise fails with an err.

err.response.data.status_code err.response.data.errors 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

Error codes

If the request is not successful, the client will return an Alphagov\Notifications\Exception\ApiException object containing the relevant error code:

exc->getCode() exc->getErrors() 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.

Error codes

If the request is not successful, the client will return an HTTPError containing the relevant error code:

error.status_code error.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 when your message was sent. If it was sent before the retention period, it has been deleted. You can no longer get the status of this message. The default retention period is 7 days.

Error codes

If the request is not successful, the client raises a Notifications::Client::RequestError exception (or a subclass), which contains a code:

error.code error.message class How to fix
400 ValidationError: id is not a valid UUID BadRequestError Check the notification ID
403 AuthError: Error: Your system clock must be accurate to within 30 seconds AuthError Check your system clock
403 AuthError: Invalid token: API key not found AuthError Use the correct API key. Refer to API keys for more information
404 NoResultFound: No result found NotFoundError Check the notification ID. This error occurs if the notification is more than 7 days old.

Errors

If the request is not successful, the API returns json containing the relevant error code. For example:

{
  "status_code": 400,
  "errors": [
    {"error": "BadRequestError", "message": "Can't send to this recipient using a team-only API key"}
  ]
}
status_code Error 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.

Get the status of multiple messages

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 olderThanId argument.

You can only get the status of messages that are 7 days old or newer.

Get the status of multiple messages

This API call returns the status of multiple messages. You can get either the most recent messages, or get older messages by specifying a particular notification ID in the olderThanId argument.

You can only get messages that are 7 days old or newer.

Get the status of multiple messages

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 olderThan argument.

You can only get the status of messages that are 7 days old or newer.

Get the status of multiple messages

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 the status of multiple messages

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 sent within the retention period. The default retention period is 7 days.

Get the status of multiple messages

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 messages that are 7 days old or newer.

Send an email

POST /v2/notifications/email

Method

NotificationList notification = client.getNotifications(
    status,
    notificationType,
    reference,
    olderThanId
);

To get the most recent messages, you must pass in an empty olderThanId argument or null.

To get older messages, pass the ID of an older notification into the olderThanId argument. This returns the next oldest messages from the specified notification ID.

Method

NotificationList notifications = client.GetNotifications(templateType, status, reference, olderThanId, includeSpreadsheetUploads);

Method

notifyClient
  .getNotifications(templateType, status, reference, olderThan)
  .then((response) => console.log(response))
  .catch((err) => console.error(err))

The method returns a promise [external link]. The promise will either:

  • resolve with a response if successful
  • fail with an err if unsuccessful

To get the most recent messages, you must pass in an empty olderThan argument or null.

To get older messages, pass the ID of an older notification into the olderThan argument. This returns the next oldest messages from the specified notification ID.

Method

listNotifications( array $filters = array() )
    $response = $notifyClient->listNotifications([
        'older_than' => 'c32e9c89-a423-42d2-85b7-a21cd4486a2a',
        'reference' => 'weekly-reminders',
        'status' => 'delivered',
        'template_type' => 'sms'
    ]);

You can leave out the older_than argument to get the 250 most recent messages.

To get older messages, pass the ID of an older notification into the older_than argument. This returns the next 250 oldest messages from the specified notification ID.

Method

Method

args = {
  template_type: 'sms',
  status: 'failed',
  reference: 'your_reference_string'
  older_than: 'e194efd1-c34d-49c9-9915-e4267e01e92e'
}
response = client.get_notifications(args)

You can leave out the older_than argument to get the 250 most recent messages.

To get older messages, pass the ID of an older notification into the older_than argument. This returns the next 250 oldest messages from the specified notification ID.

Request body

{
  "email_address": "sender@something.com",
  "template_id": "f33517ff-2a88-4f6e-b855-c550268ce08a"
}
All messages

This will return all your messages with statuses. They will display in pages of up to 250 messages each.

response = notifications_client.get_all_notifications(template_type, status, reference, older_than, include_jobs)

You can filter the returned messages by including the following optional arguments in the method:

One page of up to 250 messages

This will return 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.

To get the most recent messages, add the following code to your application:

response = get_all_notifications_iterator(status="sending")

You must set the status argument to sending.

To get older messages:

  1. Get the ID of an older message.
  2. Add the following code to your application, with the older notification ID in the older_than argument.
response = get_all_notifications_iterator(status="sending",older_than="NOTIFICATION ID")

You must set the status argument to sending.

This method will return the next oldest messages from the specified notification ID.

Arguments

You can pass in empty arguments or null to ignore these filters.

Arguments

You can leave out these arguments to ignore these filters.

Arguments

You can pass in empty arguments or null to ignore these filters.

Arguments

You can leave out any of these arguments to ignore these filters.

Arguments

Arguments

You can leave out these arguments to ignore these filters.

Arguments

status (optional)

You can filter by each:

You can leave out this argument to ignore this filter.

templateType (optional)

You can filter by:

  • email
  • sms
  • letter
status (optional)

You can filter by each:

You can leave out this argument to ignore this filter.

template_type (optional)

You can filter by:

  • email
  • sms
  • letter

You can leave out this argument to ignore this filter.

template_type (optional)

You can filter by:

  • email
  • sms
  • letter

You can leave out this argument to ignore this filter.

status (optional)

You can filter by each:

You can leave out this argument to ignore this filter.

email_address (required)

The email address of the recipient.

notificationType (optional)

You can filter by:

  • email
  • sms
  • letter
status (optional)

You can filter by each:

You can leave out this argument to ignore this filter.

notificationType (optional)

You can filter by:

  • email
  • sms
  • letter
status (optional)

You can filter by each:

You can leave out this argument to ignore this filter.

status (optional)

You can filter by each:

If you filter by failed it will return all 3 failure statuses: permanent-failure, temporary-failure and technical-failure.

You can leave out this argument to ignore this filter.

templateType (optional)

You can filter by:

  • email
  • sms
  • letter
template_id (required)

To find the template ID:

  1. Sign in to GOV.UK Notify.
  2. Go to the Templates page and select the relevant template.
  3. Select Copy template ID to clipboard.
reference (optional)

A unique identifier you create if necessary. This reference identifies a single unique notification or a batch of notifications. It must not contain any personal information such as name or postal address.

String reference='STRING';
reference (optional)

A unique identifier you can create if you need to. This reference identifies a single unique notification or a batch of notifications. It must not contain any personal information such as name or postal address. For example:

string reference = "STRING";
reference (optional)

A unique identifier you create if necessary. This reference identifies a single unique notification or a batch of notifications. It must not contain any personal information such as name or postal address. For example:

"your_reference_here"
reference (optional)

A unique identifier you can create if necessary. This reference identifies a single unique notification or a batch of notifications. It must not contain any personal information such as name or postal address.

$reference = 'STRING';

You can leave out this argument to ignore this filter.

reference (optional)

A unique identifier you can create if necessary. This reference identifies a single unique message or a batch of messages. It must not contain any personal information such as name or postal address. For example:

reference='STRING' # optional string - identifies notification(s)

You can leave out this argument to ignore this filter.

reference (optional)

A unique identifier you can create if necessary. This reference identifies a single unique notification or a batch of notifications. It must not contain any personal information such as name or postal address. For example:

reference: 'your_reference_string'
personalisation (optional)

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",
  # pass in a list and it will appear as bullet points in the message:
  "required_documents": ["passport", "utility bill", "other id"],
}

You can leave out this argument if a template does not have any placeholder fields for personalised information.

olderThanId (optional)

Input the ID of a notification into this argument. If you use this argument, the client returns the next 250 received notifications older than the given ID.

String olderThanId='8e222534-7f05-4972-86e3-17c5d9f894e2'

If you pass in an empty argument or null, the client returns the most recent 250 notifications.

olderThanId (optional)

Input the ID of a notification into this argument to return the next 250 received notifications older than the given ID. For example:

string olderThanId: "e194efd1-c34d-49c9-9915-e4267e01e92e";

If you leave out this argument, the client 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.

olderThan (optional)

Input the ID of a notification into this argument. If you use this argument, the client returns the next 250 received notifications older than the given ID. For example:

"8e222534-7f05-4972-86e3-17c5d9f894e2"

If you pass in an empty argument or null, the client returns the most recent 250 notifications.

older_than (optional)

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 specified 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.

older_than (optional)

Input a notification ID into this argument. If you use this argument, the method returns the next 250 received messages older than the given ID.

older_than='740e5834-3a29-46b4-9a6f-16142fde533a' # optional string - notification ID

If you leave out this argument, the method returns the most recent 250 messages.

The client only returns messages sent within the retention period. The default retention period is 7 days. If the message specified in this argument was sent before the retention period, the client returns an empty response.

older_than (optional)

Input the ID of a notification into this argument. If you use this argument, the client returns the next 250 received notifications older than the given ID. For example:

older_than: 'e194efd1-c34d-49c9-9915-e4267e01e92e'

If you leave out this argument, the client 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.

reference (optional)

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.

includeSpreadsheetUploads (optional)

Specifies whether the response should include notifications which were sent by uploading a spreadsheet of recipients to Notify.

bool includeSpreadsheetUploads = true;

If you do not pass in this argument it defaults to false.

include_jobs (optional)

Includes notifications sent as part of a batch upload.

If you leave out this argument, the method only returns notifications sent using the API.

one_click_unsubscribe_url (optional)

The one-click unsubscribe URL will be added to the headers of your email. Email clients will use it to add an unsubscribe button.

Read our Using Notify page for more information about unsubscribe links.

"one_click_unsubscribe_url": "https://example.com/unsubscribe.html?opaque=123456789"

The one-click unsubscribe URL must respond to an empty POST request by unsubscribing the user from your emails. You can include query parameters to help you identify the user.

Your unsubscribe URL and response must comply with the guidance specified in Section 3.1 of IETF RFC 8058.

You can leave out this argument if the email being sent is not a subscription email.

email_reply_to_id (optional)

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:

  1. Sign in to GOV.UK Notify.
  2. Go to the Settings page.
  3. In the Email section, select Manage on the Reply-to email addresses row.
  4. Select Add reply-to address.
  5. 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.

Response

If the request to the client is successful, the client returns a NotificationList:

List<Notification> notifications;
String currentPageLink;
Optional<String> nextPageLink;

Response

If the request to the client is successful, the client returns a NotificationList.

public List<Notification> notifications;
public Link links;

public class Link {
    public String current;
    public String next;
}

Response

If the request is successful, the promise resolves with a response object. For example, the response.data property will look like this:

{
  'notifications': [
    {
      'id': 'notify_id',
      'reference': 'client reference',
      'email_address': 'email address',
      'phone_number': 'phone number',
      'line_1': 'full name of a person or company',
      'line_2': '123 The Street',
      'line_3': 'Some Area',
      'line_4': 'Some Town',
      'line_5': 'Some county',
      'line_6': 'Something else',
      'postcode': 'postcode',
      'postage': 'first or second',
      'type': 'sms | letter | email',
      'status': 'sending | delivered | permanent-failure | temporary-failure | technical-failure',
      'template': {
        'version': 1,
        'id': 1,
        'uri': '/template/{id}/{version}'
      },
      'created_by_name': 'name of the person who sent the notification if sent manually',
      'created_at': 'created at',
      'sent_at': 'sent to provider at'
    }
    // …
  ],
  'links': {
    'current': '/notifications?template_type=sms&status=delivered',
    'next': '/notifications?other_than=last_id_in_list&template_type=sms&status=delivered'
  }
}

Response

If the request to the client is successful, the client returns an array.

[
    "notifications" => [
            "id" => "notify_id",
            "reference" => "client reference",
            "email_address" => "email address",
            "phone_number" => "phone number",
            "line_1" => "full name of a person or company",
            "line_2" => "123 The Street",
            "line_3" => "Some Area",
            "line_4" => "Some Town",
            "line_5" => "Some county",
            "line_6" => "Something else",
            "postcode" => "postcode",
            "postage" => "null|first|second",
            "type" => "sms | letter | email",
            "status" => sending | delivered | permanent-failure | temporary-failure | technical-failure
            "template" => [
            "version" => 1,
            "id" => 1,
            "uri" => "/template/{id}/{version}"
        ],
        "created_at" => "created at",
        "sent_at" => "sent to provider at",
        ],
        
  ],
  "links" => [
     "current" => "/notifications?template_type=sms&status=delivered",
     "next" => "/notifications?older_than=last_id_in_list&template_type=sms&status=delivered"
  ]
];

Response

If the request to the client is successful, the client returns a dict.

Response

If the request to the client is successful, the client returns a Notifications::Client::NotificationsCollection object. In the example shown in the Method section, the object is named response.

You must then call either the .links method or the .collection method on this object.

Method Information
response.links Returns a hash linking to the requested notifications (limited to 250)
response.collection Returns an array of the required notifications

If you call the collection method on this object to return a notification array, you must then call the following methods on the notifications in this array to return information on those notifications:

Method Information Type
response.id Notification UUID String
response.reference String supplied in reference argument String
response.email_address Recipient email address (email only) String
response.phone_number Recipient phone number (SMS only) String
response.line_1 Recipient address line 1 of the address (letter only) String
response.line_2 Recipient address line 2 of the address (letter only) String
response.line_3 Recipient address line 3 of the address (letter only) String
response.line_4 Recipient address line 4 of the address (letter only) String
response.line_5 Recipient address line 5 of the address (letter only) String
response.line_6 Recipient address line 6 of the address (letter only) String
response.postcode Recipient postcode (letter only) String
response.type Type of notification sent (sms, email or letter) String
response.status Notification status (sending / delivered / permanent-failure / temporary-failure / technical-failure) String
response.template Template UUID String
response.body Notification body String
response.subject Notification subject (email and letter) String
response.sent_at Date and time notification sent to provider String
response.created_at Date and time notification created String
response.completed_at Date and time notification delivered or failed String
response.created_by_name Name of sender if notification sent manually String

If the notification specified in the older_than argument is older than 7 days, the client returns an empty collection response.

Response

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": {
    "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"
  }
}
All messages
{"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": "A REAL UK POSTCODE", # required string for letter
      "type": "sms / letter / email", # required string
      "status": "sending / delivered / permanent-failure / temporary-failure / technical-failure", # required string
      "template": {
        "version": INTEGER
        "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"
  }
}
One page of up to 250 messages
<generator object NotificationsAPIClient.get_all_notifications_iterator at 0x1026c7410>

For more information, see the:

Error codes

If the request is not successful, the client returns a NotificationClientException containing the relevant error code:

httpResult Message How to fix
400 [{
"error": "ValidationError",
"message": "bad status is not one of [created, sending, sent, delivered, pending, failed, technical-failure, temporary-failure, permanent-failure, accepted, received]"
}]
Contact the GOV.UK Notify team
400 [{
"error": "ValidationError",
"message": "Applet is not one of [sms, email, letter]"
}]
Contact the GOV.UK Notify team
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

Error codes

If the request is not successful, the client returns a Notify.Exceptions.NotifyClientException containing the relevant error code.

Status code Message How to fix
400 [{
"error": "ValidationError",
"message": "bad status is not one of [created, sending, delivered, pending, failed, technical-failure, temporary-failure, permanent-failure]"
}]
Contact the GOV.UK Notify team
400 [{
"error": "ValidationError",
"message": "Apple is not one of [sms, email, letter]"
}]
Contact the GOV.UK Notify team
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

Error codes

If the request is not successful, the promise fails with an err.

err.response.data.status_code err.response.data.errors How to fix
400 [{
"error": "ValidationError",
"message": "bad status is not one of [created, sending, sent, delivered, pending, failed, technical-failure, temporary-failure, permanent-failure, accepted, received]"
}]
Contact the GOV.UK Notify team
400 [{
"error": "ValidationError",
"message": "Applet is not one of [sms, email, letter]"
}]
Contact the GOV.UK Notify team
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

Error codes

If the request is not successful, the client returns an Alphagov\Notifications\Exception\ApiException object containing the relevant error code:

exc->getCode() exc->getErrors() How to fix
400 [{
"error": "ValidationError",
"message": "bad status is not one of [created, sending, delivered, pending, failed, technical-failure, temporary-failure, permanent-failure]"
}]
Contact the GOV.UK Notify team.
400 [{
"error": "ValidationError",
"message": "Apple is not one of [sms, email, letter]"
}]
Contact the GOV>UK Notify team.
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.

Error codes

If the request is not successful, the client returns an HTTPError containing the relevant error code:

error.status_code error.message How to fix
400 [{
"error": "ValidationError",
"message": "status ‘elephant’ is not one of [cancelled, created, sending, sent, delivered, pending, failed, technical-failure, temporary-failure, permanent-failure, pending-virus-check, validation-failed, virus-scan-failed, returned-letter, accepted, received]"
}]
Change the status argument
400 [{
"error": "ValidationError",
"message": "‘Apple’ is not one of [sms, email, letter]"
}]
Change the template_type argument

Error codes

If the request is not successful, the client raises a Notifications::Client::RequestError exception (or a subclass), which contains a code:

error.code error.message class How to fix
400 ValidationError: bad status is not one of [created, sending, sent, delivered, pending, failed, technical-failure, temporary-failure, permanent-failure, accepted, received] BadRequestError Contact the GOV.UK Notify team
400 ValidationError: Template type is not one of [sms, email, letter] BadRequestError Contact the GOV.UK Notify team
403 AuthError: Error: Your system clock must be accurate to within 30 seconds AuthError Check your system clock
403 AuthError: Invalid token: API key not found AuthError Use the correct API key. Refer to API keys for more information

Errors

If the request is not successful, the API returns json containing the relevant error code. For example:

{
  "status_code": 400,
  "errors": [
    {"error": "BadRequestError", "message": "Can't send to this recipient using a team-only API key"}
  ]
}
status_code Error 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.

Email status descriptions

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.

Email status descriptions

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.

Email status descriptions

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.

Email status descriptions

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.

Email status descriptions

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.

Email status descriptions

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.

Send a file by email

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 links are unique and unguessable. GOV.UK Notify cannot access or decrypt your file.

Your file will be available to download for a default period of 26 weeks (6 months).

To help protect your files you can also:

  • ask recipients to confirm their email address before downloading
  • choose the length of time that a file is available to download

Add contact details to the file download page

  1. Sign in to GOV.UK Notify.
  2. Go to the Settings page.
  3. In the Email section, select Manage on the Send files by email row.
  4. Enter the contact details you want to use, and select Save.

Add a placeholder to the template

  1. Sign in to GOV.UK Notify.
  2. Go to the Templates page and select the relevant email template.
  3. Select Edit.
  4. Add a placeholder to the email template using double brackets. For example: “Download your file at: ((link_to_file))”

Your email should also tell recipients how long the file will be available to download.

Upload your file

You can upload the following file types:

  • PDF (.pdf)
  • CSV (.csv)
  • Text (.odt, .txt, .rtf, .json)
  • 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"}
}

Set the filename

You should provide a filename when you upload your file.

The filename should tell the recipient what the file contains. A memorable filename can help the recipient to find the file again later.

The filename must end with a file extension. For example, .csv for a CSV file. If you include the wrong file extension, recipients may not be able to open your file.

If you do not provide a filename for your file, Notify will:

  • generate a random filename
  • try to add the correct file extension

If Notify cannot add the correct file extension, recipients may not be able to open your file.

"personalisation":{
  "first_name": "Amala",
  "application_date": "2018-01-01",
  "link_to_file": {"file": "CSV file as base64 encoded string", "filename": "report.csv"}
}

Ask recipients to confirm their email address before they can download the file

When a recipient clicks the link in the email you’ve sent them, they have to enter their email address. Only someone who knows the recipient’s email address can download the file.

This security feature is turned on by default.

If you do not want to use this feature, you can turn it off on a file-by-file basis.

You should not turn this feature off if you send files that contain:

  • personally identifiable information
  • commercially sensitive information
  • information classified as ‘OFFICIAL’ or ‘OFFICIAL-SENSITIVE’ under the Government Security Classifications policy

To let the recipient download the file without confirming their email address, set the confirm_email_before_download flag to false.

"personalisation":{
  "first_name": "Amala",
  "application_date": "2018-01-01",
  "link_to_file": {"file": "file as base64 encoded string", "confirm_email_before_download": false}
}

Choose the length of time that a file is available to download

Set the number of weeks you want the file to be available using the retention_period key.

You can choose any value between 1 week and 78 weeks. When deciding this, you should consider:

  • the need to protect the recipient’s personal information
  • whether the recipient will need to download the file again later

If you do not choose a value, the file will be available for the default period of 26 weeks (6 months).

Files sent before 12 April 2023 had a longer default period of 78 weeks (18 months).

"personalisation":{
  "first_name": "Amala",
  "application_date": "2018-01-01",
  "link_to_file": {"file": "file as base64 encoded string", "retention_period": "4 weeks"}
}

Response

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": {
    "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"
  }
}

Errors

If the request is not successful, the API returns json containing the relevant error code. For example:

{
  "status_code": 400,
  "errors": [
    {"error": "BadRequestError", "message": "Can't send to this recipient using a team-only API key"}
  ]
}
status_code Error 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": "`filename` cannot be longer than 100 characters"
}]
Choose a shorter filename
400 [{
"error": "BadRequestError",
"message": "`filename` must end with a file extension. For example, filename.csv"
}]
Include the file extension in your filename
400 [{
"error": "BadRequestError",
"message": "Unsupported value for retention_period '(PERIOD)'. Supported periods are from 1 to 78 weeks."
}]
Choose a period between 1 and 78 weeks
400 [{
"error": "BadRequestError",
"message": "Unsupported value for confirm_email_before_download: '(VALUE)'. Use a boolean true or false value."
}]
Use either true or false
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
400 [{
"error": "BadRequestError",
"message": "Can only send a file by email"
}]
Make sure you are using an email template
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.

Text message status descriptions

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.

Text message status descriptions

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. If a recipient blocks your sender name or mobile number, your message will still show as 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.

Text message status descriptions

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. If a recipient blocks your sender name or mobile number, your message will still show as 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.

Text message status descriptions

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. If a recipient blocks your sender name or mobile number, your message will still show as 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.

Text message status descriptions

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. If a recipient blocks your sender name or mobile number, your message will still show as 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.

Text message status descriptions

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. If a recipient blocks your sender name or mobile number, your message will still show as 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.

Send a letter

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:

  1. Sign in to GOV.UK Notify.
  2. Go to the Settings page.
  3. In the Your service is in trial mode section, select request to go live.
POST /v2/notifications/letter

Request body

{
  "template_id": "f33517ff-2a88-4f6e-b855-c550268ce08a",
  "personalisation": {
    "address_line_1": "The Occupier",
    "address_line_2": "123 High Street",
    "address_line_3": "SW14 6BH"
  }
}

Arguments

template_id (required)

To find the template ID:

  1. Sign in to GOV.UK Notify.
  2. Go to the Templates page and select the relevant template.
  3. Select Copy template ID to clipboard.
personalisation (required)

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",
  # pass in a list and it will appear as bullet points in the letter:
  "required_documents": ["passport", "utility bill", "other id"],
}
reference (optional)

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"

Response

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": ""
}

Errors

If the request is not successful, the API returns json containing the relevant error code. For example:

{
  "status_code": 400,
  "errors": [
    {"error": "BadRequestError", "message": "Can't send to this recipient using a team-only API key"}
  ]
}
status_code Error message How to fix
403 [{
"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.

Letter status descriptions

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.

Letter status descriptions

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.

Letter status descriptions

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.

Letter status descriptions

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.

Letter status descriptions

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.

Letter status descriptions

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.

Send a precompiled letter

POST /v2/notifications/letter

Request body

{
  "reference": "STRING",
  "content": "STRING"
}

Arguments

reference (required)

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.

content (required)

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"
postage (optional)

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"

Response

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"
}

Errors

If the request is not successful, the API returns json containing the relevant error code. For example:

{
  "status_code": 400,
  "errors": [
    {"error": "BadRequestError", "message": "Can't send to this recipient using a team-only API key"}
  ]
}
status_code Error message How to fix
403 [{
"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

Precompiled letter status descriptions

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.

Precompiled letter status descriptions

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.

Precompiled letter status descriptions

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.

Precompiled letter status descriptions

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.

Precompiled letter status descriptions

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.

Precompiled letter status descriptions

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.

Get a PDF for a letter notification

Get a PDF for a letter notification

Get a PDF for a letter notification

Get a PDF for a letter notification

Get a PDF for a letter

Get a PDF for a letter notification

Method

This returns the PDF contents of a letter notification.

byte[] pdfFile = client.getPdfForLetter(notificationId)

Method

This returns the pdf contents of a letter notification.

byte[] pdfFile = client.GetPdfForLetter(notificationId);

Method

notifyClient
  .getPdfForLetterNotification(notificationId)
  .then(function (fileBuffer) {
    return fileBuffer
  }) /* the response is a file buffer, an instance of Buffer */
  .catch((err) => console.error(err))

The method returns a promise [external link]. The promise will either:

  • resolve with fileBuffer if successful
  • fail with an err if unsuccessful

Method

This returns the PDF contents of a letter notification.

$pdf_file = $notifyClient->getPdfForLetter(
  'f33517ff-2a88-4f6e-b855-c550268ce08a' // required string - notification ID
)

Method

This returns the PDF contents of a letter.

pdf_file = notifications_client.get_pdf_for_letter(
  'f33517ff-2a88-4f6e-b855-c550268ce08a' # required string - notification ID
)

Method

This returns the pdf contents of a letter notification.

pdf_file = client.get_pdf_for_letter(
  'f33517ff-2a88-4f6e-b855-c550268ce08a' # notification id (required)
)

Arguments

Arguments

Arguments

Arguments

Arguments

Arguments

notificationId (required)

The ID of the notification. To find the notification ID, you can either:

notificationId (required)

The ID of the notification. To find the notification ID, you can either:

notificationId (required)

The ID of the notification. To find the notification ID, you can either:

notificationId (required)

The ID of the notification. To find the notification ID, you can either:

notification_id (required)

The ID of the notification. To find the notification ID, you can either:

id (required)

The ID of the notification. To find the notification ID, you can either:

Response

If the request to the client is successful, the client will return a byte[] object containing the raw PDF data.

Response

If the request to the client is successful, the client will return a byte[] object containing the raw PDF data.

Response

If the request to the client is successful, the client will return an instance of the Buffer class containing the raw PDF data.

Response

If the request to the client is successful, the client will return a string containing the raw PDF data.

Response

If the request to the client is successful, the client will return a io.BytesIO object containing the raw PDF data.

Response

If the request to the client is successful, the client will return a string containing the raw PDF data.

Error codes

If the request is not successful, the client returns a NotificationClientException containing the relevant error code:

error.status_code error.message How to fix
400 [{
"error": "ValidationError",
"message": "id is not a valid UUID"
}]
Check the notification ID
400 [{
"error": "PDFNotReadyError",
"message": "PDF not available yet, try again later"
}]
Wait for the notification to finish processing. This usually takes a few seconds
400 [{
"error": "BadRequestError",
"message": "File did not pass the virus scan"
}]
You cannot retrieve the contents of a letter notification that contains a virus
400 [{
"error": "BadRequestError",
"message": "PDF not available for letters in technical-failure"
}]
You cannot retrieve the contents of a letter notification in technical-failure
400 [{
"error": "ValidationError",
"message": "Notification is not a letter"
}]
Check that you are looking up the correct notification
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

Error codes

If the request is not successful, the client returns a NotificationClientException containing the relevant error code.

Status code Message How to fix
400 [{
"error": "ValidationError",
"message": "id is not a valid UUID"
}]
Check the notification ID
400 [{
"error": "ValidationError",
"message": "Notification is not a letter"
}]
Check that you are looking up the correct notification
400 [{
"error": "PDFNotReadyError",
"message": "PDF not available yet, try again later"
}]
Wait for the notification to finish processing. This usually takes a few seconds
400 [{
"error": "BadRequestError",
"message": "File did not pass the virus scan"
}]
You cannot retrieve the contents of a letter notification that contains a virus
400 [{
"error": "BadRequestError",
"message": "PDF not available for letters in technical-failure"
}]
You cannot retrieve the contents of a letter notification in technical-failure
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

Error codes

If the request is not successful, the client will return an HTTPError containing the relevant error code:

error.status_code error.message How to fix
400 [{
"error": "ValidationError",
"message": "id is not a valid UUID"
}]
Check the notification ID
400 [{
"error": "PDFNotReadyError",
"message": "PDF not available yet, try again later"
}]
Wait for the notification to finish processing. This usually takes a few seconds
400 [{
"error": "BadRequestError",
"message": "File did not pass the virus scan"
}]
You cannot retrieve the contents of a letter notification that contains a virus
400 [{
"error": "BadRequestError",
"message": "PDF not available for letters in technical-failure"
}]
You cannot retrieve the contents of a letter notification in technical-failure
400 [{
"error": "ValidationError",
"message": "Notification is not a letter"
}]
Check that you are looking up the correct notification
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

Error codes

If the request is not successful, the client throws an Alphagov\Notifications\Exception\ApiException object containing the relevant error code:

error.status_code error.message How to fix
400 [{
"error": "ValidationError",
"message": "id is not a valid UUID"
}]
Check the notification ID
400 [{
"error": "PDFNotReadyError",
"message": "PDF not available yet, try again later"
}]
Wait for the notification to finish processing. This usually takes a few seconds
400 [{
"error": "BadRequestError",
"message": "File did not pass the virus scan"
}]
You cannot retrieve the contents of a letter notification that contains a virus
400 [{
"error": "BadRequestError",
"message": "PDF not available for letters in technical-failure"
}]
You cannot retrieve the contents of a letter notification in technical-failure
400 [{
"error": "ValidationError",
"message": "Notification is not a letter"
}]
Check that you are looking up the correct notification
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

Error codes

If the request is not successful, the client will return an HTTPError containing the relevant error code:

error.status_code error.message How to fix
400 [{
"error": "ValidationError",
"message": "id is not a valid UUID"
}]
Check the notification ID
400 [{
"error": "PDFNotReadyError",
"message": "PDF not available yet, try again later"
}]
Wait for the letter to finish processing. This usually takes a few seconds
400 [{
"error": "BadRequestError",
"message": "File did not pass the virus scan"
}]
You cannot retrieve the contents of a letter that contains a virus
400 [{
"error": "BadRequestError",
"message": "PDF not available for letters in technical-failure"
}]
You cannot retrieve the contents of a letter in technical-failure
400 [{
"error": "ValidationError",
"message": "Notification is not a letter"
}]
Check that you are looking up the correct notification
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

Error codes

If the request is not successful, the client raises a Notifications::Client::RequestError exception (or a subclass), which contains a code:

error.code error.message class How to fix
400 ValidationError: id is not a valid UUID BadRequestError Check the notification ID
400 PDFNotReadyError: PDF not available yet, try again later BadRequestError Wait for the notification to finish processing. This usually takes a few seconds
400 BadRequestError: File did not pass the virus scan BadRequestError You cannot retrieve the contents of a letter notification that contains a virus
400 BadRequestError: PDF not available for letters in technical-failure BadRequestError You cannot retrieve the contents of a letter notification in technical-failure
400 ValidationError: Notification is not a letter BadRequestError Check that you are looking up the correct notification
403 AuthError: Error: Your system clock must be accurate to within 30 seconds BadRequestError Check your system clock
403 AuthError: Invalid token: API key not found BadRequestError Use the correct API key. Refer to API keys for more information
404 NoResultFound: No result found BadRequestError Check the notification ID

Get a template

Get a template

Get a template

Get a template

Get a template

Get a template

Get message status

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 a template by ID

Get a template by ID

Get a template by ID

Get a template by ID

Get a template by ID

Get a template by ID

Get the status of one message

GET /v2/notifications/{notification_id}

Method

This returns the latest version of the template.

Template template = client.getTemplateById(templateId);

Method

This returns the latest version of the template.

TemplateResponse response = client.GetTemplateById(
    "templateId"
);

Method

This returns the latest version of the template.

notifyClient
  .getTemplateById(templateId)
  .then((response) => console.log(response))
  .catch((err) => console.error(err))

The method returns a promise [external link]. The promise will either:

  • resolve with a response if successful
  • fail with an err if unsuccessful

Method

This returns the latest version of the template.

$response = $notifyClient->getTemplate( 'templateId' );

Method

This returns the latest version of the template.

response = notifications_client.get_template(
  'f33517ff-2a88-4f6e-b855-c550268ce08a' # required string - template ID
)

Method

This returns the latest version of the template.

response = client.get_template_by_id(id)

Query parameters

notification_id (required)

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:

Arguments

Arguments

Arguments

Arguments

Arguments

Arguments

Response

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
}
templateId (required)

The ID of the template. Sign in to GOV.UK Notify and go to the Templates page to find it.

String templateId='f33517ff-2a88-4f6e-b855-c550268ce08a';
templateId (required)

The ID of the template. Sign in to GOV.UK Notify and go to the Templates page to find it. For example:

string templateId: "f33517ff-2a88-4f6e-b855-c550268ce08a";
templateId (required)

The ID of the template. Sign in to GOV.UK Notify and go to the Templates page to find it. For example:

"f33517ff-2a88-4f6e-b855-c550268ce08a"
templateId (required)

The ID of the template. Sign in to GOV.UK Notify and go to the Templates page to find it.

template_id (required)

The ID of the template. Sign in to GOV.UK Notify and go to the Templates page to find it.

id (required)

The ID of the template. Sign in to GOV.UK Notify and go to the Templates page to find it. For example:

'f33517ff-2a88-4f6e-b855-c550268ce08a'

Response

If the request to the client is successful, the client returns a Template:

UUID id;
String name;
String templateType;
ZonedDateTime createdAt;
Optional<ZonedDateTime> updatedAt;
String createdBy;
int version;
String body;
Optional<String> subject;
Optional<Map<String, Object>> personalisation;
Optional<String> letterContactBlock;

Response

If the request to the client is successful, the client returns a TemplateResponse.

public String id;
public String name;
public String type;
public DateTime created_at;
public DateTime? updated_at;
public String created_by;
public int version;
public String body;
public String subject; // null if an sms message
public String letter_contact_block; // null if not a letter template or contact block not set for letter

Response

If the request is successful, the promise resolves with a response object. For example, the response.data property will look like this:

{
  'id': 'template_id',
  'name': 'template name',
  'type': 'sms|email|letter',
  'created_at': 'created at',
  'updated_at': 'updated at',
  'version': 'version',
  'created_by': 'someone@example.com',
  'body': 'body',
  'subject': 'null|email_subject',
  'letter_contact_block': 'null|letter_contact_block'
}

Response

If the request to the client is successful, the client returns an array.

[
    "id" => "template_id",
    "type" => "sms|email|letter",
    "created_at" => "created at",
    "updated_at" => "updated at",
    "version" => "version",
    "created_by" => "someone@example.com",
    "body" => "body",
    "subject" => "null|email or letter subject",
    "letter_contact_block" => "null|letter_contact_block"
];

Response

If the request to the client is successful, the client returns a dict.

{
    "id": 'f33517ff-2a88-4f6e-b855-c550268ce08a', # required string - template ID
    "name": "STRING", # required string - template name
    "type": "sms / email / letter" , # required string
    "created_at": "STRING", # required string - date and time template created
    "updated_at": "STRING", # required string - date and time template last updated
    "version": INTEGER,
    "created_by": "someone@example.com", # required string
    "body": "STRING", # required string - body of notification
    "subject": "STRING" # required string for email - subject of email
    "letter_contact_block": "STRING" # optional string - None if not a letter template or contact block not set
}

Response

If the request to the client is successful, the client returns a Notifications::Client::Template object. In the example shown in the Method section, the object is named response.

You can then call different methods on this object to return the requested information.

Method Information Type
response.id Template UUID String
response.name Template name String
response.type Template type (email/sms/letter) String
response.created_at Date and time template created String
response.updated_at Date and time template last updated (may be nil if version 1) String
response.created_by Email address of person that created the template String
response.version Template version String
response.body Template content String
response.subject Template subject (email and letter) String
response.letter_contact_block Template letter contact block (letter) String

Errors

If the request is not successful, the API returns json containing the relevant error code. For example:

{
  "status_code": 400,
  "errors": [
    {"error": "BadRequestError", "message": "Can't send to this recipient using a team-only API key"}
  ]
}
status_code Error 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

Error codes

If the request is not successful, the client returns a NotificationClientException containing the relevant error code:

httpResult Message How to fix
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 your template ID

Error codes

If the request is not successful, the client returns a Notify.Exceptions.NotifyClientException containing the relevant error code.

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 your template ID

Error codes

If the request is not successful, the promise fails with an err.

err.response.data.status_code err.response.data.errors How to fix
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 your template ID

Error codes

If the request is not successful, the client returns an Alphagov\Notifications\Exception\ApiException object containing the relevant error code:

exc->getCode() exc->getErrors() How to fix
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 your template ID.

Error codes

If the request is not successful, the client returns an HTTPError containing the relevant error code:

error.status_code error.message How to fix
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 your template ID

Error codes

If the request is not successful, the client raises a Notifications::Client::RequestError exception (or a subclass), which contains a code:

error.code error.message class How to fix
400 ValidationError: id is not a valid UUID BadRequestError Check the notification ID
403 AuthError: Error: Your system clock must be accurate to within 30 seconds AuthError Check your system clock
403 AuthError: Invalid token: API key not found AuthError Use the correct API key. Refer to API keys for more information
404 NoResultFound: No Result Found NotFoundError Check your template ID

Get a template by ID and version

Get a template by ID and version

Get a template by ID and version

Get a template by ID and version

Get a template by ID and version

Get a template by ID and version

Get the status of multiple messages

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
All messages

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:

Method

Template template = client.getTemplateVersion(templateId, version);

Method

TemplateResponse response = client.GetTemplateByIdAndVersion(
    "templateId",
    1   // integer required for version number
);

Method

notifyClient
  .getTemplateByIdAndVersion(templateId, version)
  .then((response) => console.log(response))
  .catch((err) => console.error(err))

The method returns a promise [external link]. The promise will either:

  • resolve with a response if successful
  • fail with an err if unsuccessful

Method

$response = $notifyClient->getTemplateVersion( 'templateId', 1 );

Method

response = notifications_client.get_template_version(
    'f33517ff-2a88-4f6e-b855-c550268ce08a' # required string - template ID
    'version': INTEGER,
)

Method

response = client.get_template_version(id, version)

Arguments

You can omit any of these arguments to ignore these filters.

template_type (optional)

You can filter by:

  • email
  • sms
  • letter
status (optional)

You can filter by each:

You can leave out this argument to ignore this filter.

reference (optional)

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"
older_than (optional)

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.

include_jobs (optional)

Includes notifications sent as part of a batch upload.

If you leave out this argument, the method only returns notifications sent using the API.

Arguments

Arguments

Arguments

Arguments

Arguments

Arguments

Response

If the request is successful, the response body is json and the status code is 200.

templateId (required)

The ID of the template. Sign in to GOV.UK Notify and go to the Templates page to find it.

String templateId='f33517ff-2a88-4f6e-b855-c550268ce08a';
templateId (required)

The ID of the template. Sign in to GOV.UK Notify and go to the Templates page to find it. For example:

string templateId: "f33517ff-2a88-4f6e-b855-c550268ce08a";
templateId (required)

The ID of the template. Sign in to GOV.UK Notify and go to the Templates page to find it. For example:

"f33517ff-2a88-4f6e-b855-c550268ce08a"
templateId (required)

The ID of the template. Sign in to GOV.UK Notify and go to the Templates page to find it.

template_id (required)

The ID of the template. Sign in to GOV.UK Notify and go to the Templates page to find it.

id (required)

The ID of the template. Sign in to GOV.UK Notify and go to the Templates page to find it. For example:

'f33517ff-2a88-4f6e-b855-c550268ce08a'
All messages
{
  "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"
  }
}
version (required)

The version number of the template.

version (required)

The version number of the template.

version (required)

The version number of the template.

version (required)

The version number of the template.

version (required)

The version number of the template.

version (required)

The version number of the template.

Response

If the request to the client is successful, the client returns a Template:

UUID id;
String name;
String templateType;
ZonedDateTime createdAt;
Optional<ZonedDateTime> updatedAt;
String createdBy;
int version;
String body;
Optional<String> subject;
Optional<Map<String, Object>> personalisation;
Optional<String> letterContactBlock;

Response

If the request to the client is successful, the client returns a TemplateResponse.

public String id;
public String name;
public String type;
public DateTime created_at;
public DateTime? updated_at;
public String created_by;
public int version;
public String body;
public String subject; // null if an sms message
public String letter_contact_block; // null if not a letter template or contact block not set for letter

Response

If the request is successful, the promise resolves with a response object. For example, the response.data property will look like this:

{
  'id': 'template_id',
  'name': 'template name',
  'type': 'sms|email|letter',
  'created_at': 'created at',
  'updated_at': 'updated at',
  'version': 'version',
  'created_by': 'someone@example.com',
  'body': 'body',
  'subject': 'null|email_subject',
  'letter_contact_block': 'null|letter_contact_block'
}

Response

If the request to the client is successful, the client returns an array.

[
    "id" => "template_id",
    "type" => "sms|email|letter",
    "created_at" => "created at",
    "updated_at" => "updated at",
    "version" => "version",
    "created_by" => "someone@example.com",
    "body" => "body",
    "subject" => "null|email or letter subject",
    "letter_contact_block" => "null|letter_contact_block"
];

Response

If the request to the client is successful, the client returns a dict.

{
    "id": 'f33517ff-2a88-4f6e-b855-c550268ce08a', # required string - template ID
    "name": "STRING", # required string - template name
    "type": "sms / email / letter" , # required string
    "created_at": "STRING", # required string - date and time template created
    "updated_at": "STRING", # required string - date and time template last updated
    "version": INTEGER,
    "created_by": "someone@example.com", # required string
    "body": "STRING", # required string - body of notification
    "subject": "STRING" # required string for email - subject of email
    "letter_contact_block": "STRING" # optional string - None if not a letter template or contact block not set
}

Response

If the request to the client is successful, the client returns a Notifications::Client::Template object. In the example shown in the Method section, the object is named response.

You can then call different methods on this object to return the requested information.

Method Information Type
response.id Template UUID String
response.name Template name String
response.type Template type (email/sms/letter) String
response.created_at Date and time template created String
response.updated_at Date and time template last updated (may be nil if it is the first version) String
response.created_by Email address of person that created the template String
response.version Template version String
response.body Template content String
response.subject Template subject (email and letter) String
response.letter_contact_block Template letter contact block (letter) String

Errors

If the request is not successful, the API returns json containing the relevant error code. For example:

{
  "status_code": 400,
  "errors": [
    {"error": "BadRequestError", "message": "Can't send to this recipient using a team-only API key"}
  ]
}
status_code Error 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

Error codes

If the request is not successful, the client returns a NotificationClientException containing the relevant error code:

httpResult 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 your template ID and version

Error codes

If the request is not successful, the client returns a Notify.Exceptions.NotifyClientException containing the relevant error code.

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 your template ID and version

Error codes

If the request is not successful, the promise fails with an err.

err.response.data.status_code err.response.data.errors 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 your template ID and version

Error codes

If the request is not successful, the client returns an Alphagov\Notifications\Exception\ApiException object containing the relevant error code:

exc->getCode() exc->getErrors() How to fix
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 your template ID and version.

Error codes

If the request is not successful, the client returns an HTTPError containing the relevant error code:

error.status_code error.message How to fix
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 your template ID and version

Error codes

If the request is not successful, the client raises a Notifications::Client::RequestError exception (or a subclass), which contains a code:

error.code error.message class How to fix
400 ValidationError: id is not a valid UUID BadRequestError Check the notification ID
403 AuthError: Error: Your system clock must be accurate to within 30 seconds AuthError Check your system clock
403 AuthError: Invalid token: API key not found AuthError Use the correct API key. Refer to API keys for more information
404 NoResultFound: No Result Found NotFoundError Check your template ID and version

Get all templates

Get all templates

Get all templates

Get all templates

Get all templates

Get all templates

Email status descriptions

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.

Method

This returns the latest version of all templates.

TemplateList templates = client.getAllTemplates(templateType);

Method

This returns the latest version of all templates.

TemplateList response = client.GetAllTemplates(
    "sms" | "email" | "letter" // optional
);

Method

This returns the latest version of all templates.

notifyClient
  .getAllTemplates(templateType)
  .then((response) => console.log(response))
  .catch((err) => console.error(err))

The method returns a promise [external link]. The promise will either:

  • resolve with a response if successful
  • fail with an err if unsuccessful

Method

This returns the latest version of all templates.

    $this->listTemplates(
      $template_type  // optional
    );

Method

This returns the latest version of all templates.

response = notifications_client.get_all_templates(
    template_type="sms / letter / email" # optional string
)

Method

This returns the latest version of all templates inside a collection object.

args = {
  type: 'sms'
}
response = client.get_all_templates(args)

Arguments

Arguments

Arguments

Arguments

Arguments

Arguments

templateType (optional)

If you do not use templateType, the client returns all templates. Otherwise you can filter by:

  • email
  • sms
  • letter
templateType (optional)

If left out, the method returns all templates. Otherwise you can filter by:

  • email
  • sms
  • letter
templateType (optional)

If you do not use templateType, the client returns all templates. Otherwise you can filter by:

  • email
  • sms
  • letter
template_type (optional)

If omitted, the method returns all templates. Otherwise you can filter by:

  • email
  • sms
  • letter
template_type (optional)

If you leave out this argument, the method returns all templates. Otherwise you can filter by:

  • email
  • sms
  • letter
type (optional)

If you do not use type, the client returns all templates. Otherwise you can filter by:

  • email
  • sms
  • letter

Response

If the request to the client is successful, the client returns a TemplateList:

List<Template> templates;

If no templates exist for a template type or there no templates for a service, the templates list is empty.

Response

If the request to the client is successful, the client returns a TemplateList.

List<TemplateResponse> templates;

If no templates exist for a template type or there no templates for a service, the client returns a TemplateList with an empty templates list element:

List<TemplateResponse> templates; // empty list of templates

Response

If the request is successful, the promise resolves with a response object. For example, the response.data property will look like this:

{
  'templates': [
    {
      'id': 'template_id',
      'name': 'template name',
      'type': 'sms|email|letter',
      'created_at': 'created at',
      'updated_at': 'updated at',
      'version': 'version',
      'created_by': 'someone@example.com',
      'body': 'body',
      'subject': 'null|email_subject',
      'letter_contact_block': 'null|letter_contact_block'
    },
    {
      // … another template
    }
  ]
}

If no templates exist for a template type or there no templates for a service, the object is empty.

Response

If the request to the client is successful, the client returns an array.

[
    "templates"  => [
        [
            "id" => "template_id",
            "type" => "sms|email|letter",
            "created_at" => "created at",
            "updated_at" => "updated at",
            "version" => "version",
            "created_by" => "someone@example.com",
            "body" => "body",
            "subject" => "null|email or letter subject",
            "letter_contact_block" => "null|letter_contact_block"
        ],
        [
            ... another template
        ]
    ]
];

If no templates exist for a template type or there no templates for a service, the client returns a dict with an empty templates list element:

[
    "templates"  => []
];

Response

If the request to the client is successful, the client returns a dict.

{
    "templates": [
        {
            "id": 'f33517ff-2a88-4f6e-b855-c550268ce08a', # required string - template ID
            "name": "STRING", # required string - template name
            "type": "sms / email / letter" , # required string
            "created_at": "STRING", # required string - date and time template created
            "updated_at": "STRING", # required string - date and time template last updated
            "version": NUMBER, # required string - template version
            "created_by": "someone@example.com", # required string
            "body": "STRING", # required string - body of notification
            "subject": "STRING" # required string for email - subject of email
            "letter_contact_block": "STRING" # optional string - None if not a letter template or contact block not set
        },
        {
            ...another template
        }
    ]
}

If no templates exist for a template type or there no templates for a service, the client returns a dict with an empty templates list element:

{
    "templates": []
}

Response

If the request to the client is successful, the client returns a Notifications::Client::TemplateCollection object. In the example shown in the Method section, the object is named response.

You must then call the .collection method on this object to return an array of the required templates.

Once the client has returned a template array, you must then call the following methods on the templates in this array to return information on those templates.

Method Information Type
response.id Template UUID String
response.name Template name String
response.type Template type (email/sms/letter) String
response.created_at Date and time template created String
response.updated_at Date and time template last updated (may be nil if it is the first version) String
response.created_by Email address of person that created the template String
response.version Template version String
response.body Template content String
response.subject Template subject (email and letter) String
response.letter_contact_block Template letter contact block (letter) String

If no templates exist for a template type or there no templates for a service, the templates array will be empty.

Error codes

If the request is not successful, the client raises a Notifications::Client::RequestError exception (or a subclass), which contains a code:

error.code error.message class How to fix
400 ValidationError: Template type is not one of [sms, email, letter] BadRequestError Contact the Notify team

Generate a preview template

Generate a preview template

Generate a preview template

Generate a preview template

Generate a preview template

Generate a preview template

Text message status descriptions

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. If a recipient blocks your sender name or mobile number, your message will still show as 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.

Method

This generates a preview version of a template.

TemplatePreview templatePreview = client.generateTemplatePreview(
    templateId,
    personalisation
);

The parameters in the personalisation argument must match the placeholder fields in the actual template. The API notification client ignores any extra fields in the method.

Method

This generates a preview version of a template.

TemplatePreviewResponse response = client.GenerateTemplatePreview(
    templateId,
    personalisation
);

The parameters in the personalisation argument must match the placeholder fields in the actual template. The API notification client ignores any extra fields in the method.

Method

This generates a preview version of a template.

personalisation = { 'foo': 'bar' }
notifyClient
  .previewTemplateById(templateId, personalisation)
  .then((response) => console.log(response))
  .catch((err) => console.error(err))

The method returns a promise [external link]. The promise will either:

  • resolve with a response if successful
  • fail with an err if unsuccessful

The parameters in the personalisation argument must match the placeholder fields in the actual template. The API notification client ignores any extra fields in the method.

Method

This generates a preview version of a template.

    $personalisation = [ "foo" => "bar" ];
    $this->previewTemplate( $templateId, $personalisation );

The parameters in the personalisation argument must match the placeholder fields in the actual template. The API notification client will ignore any extra fields in the method.

Method

This generates a preview version of a template.

response = notifications_client.post_template_preview(
    template_id='f33517ff-2a88-4f6e-b855-c550268ce08a', # required UUID string
    personalisation={
        'KEY': 'VALUE',
        'KEY': 'VALUE',
        ...
        }, # required dict - specifies template parameters
)

The parameters in the personalisation argument must match the placeholder fields in the actual template. The API notification client will ignore any extra fields in the method.

Method

This generates a preview version of a template.

response = client.generate_template_preview(id)

The parameters in the personalisation argument must match the placeholder fields in the actual template. The API notification client ignores any extra fields in the method.

Arguments

Arguments

Arguments

Arguments

Arguments

Arguments

templateId (required)

The ID of the template. Sign in to GOV.UK Notify and go to the Templates page to find it.

String templateId='f33517ff-2a88-4f6e-b855-c550268ce08a';
templateId (required)

The ID of the template. Sign in to GOV.UK Notify and go to the Templates page to find it. For example:

string templateId: "f33517ff-2a88-4f6e-b855-c550268ce08a";
templateId (required)

The ID of the template. Sign in to GOV.UK Notify and go to the Templates page to find it. For example:

"f33517ff-2a88-4f6e-b855-c550268ce08a"
templateId (required)

The ID of the template. Sign in to GOV.UK Notify and go to the Templates page to find it.

template_id (required)

The ID of the template. Sign in to GOV.UK Notify and go to the Templates page to find it.

id (required)

The ID of the template. Sign in to GOV.UK Notify and go to the Templates page to find it. For example:

'f33517ff-2a88-4f6e-b855-c550268ce08a'
personalisation (required)

If a template has placeholder fields for personalised information such as name or application date, you must provide their values in a map. For example:

Map<String, Object> personalisation = new HashMap<>();
personalisation.put("first_name", "Amala");
personalisation.put("application_date", "2018-01-01");

If a template does not have any placeholder fields for personalised information, you must pass in an empty map or null.

personalisation (required)

If a template has placeholder fields for personalised information such as name or reference number, you need to provide their values in a Dictionary. For example:

Dictionary<String, dynamic> personalisation = new Dictionary<String, dynamic>
{
    { "name", "someone" }
};

You can leave out this argument if a template does not have any placeholder fields for personalised information.

personalisation (optional)

If a template has placeholder fields for personalised information such as name or application date, you must provide their values in an object. For example:

{
  personalisation: {
    'first_name': 'Amala',
    'reference_number': '300241'
  }
}

You can leave out this argument if a template does not have any placeholder fields for personalised information.

personalisation (required)

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',
    'reference_number' => '300241',
];
personalisation (required)

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',
}
personalisation (optional)

If a template has placeholder fields for personalised information such as name or application date, you must provide their values in a hash. For example:

personalisation: {
  name: "John Smith",
  ID: "300241",
}

You can leave out this argument if a template does not have any placeholder fields for personalised information.

Response

If the request to the client is successful, the client returns a TemplatePreview:

UUID id;
String templateType;
int version;
String body;
Optional<String> subject;
Optional<String> html;

Response

If the request to the client is successful, you receive a TemplatePreviewResponse response.

public String id;
public String type;
public int version;
public String body;
public String subject; // null if a sms message

Response

If the request is successful, the promise resolves with a response object. For example, the response.data property will look like this:

{
  'id': 'notify_id',
  'type': 'sms|email|letter',
  'version': 'version',
  'body': 'Hello bar', // with substitution values
  'subject': 'null|email_subject',
  'html': '<p>Example</p>' // Returns the rendered body (email templates only)
}

Response

If the request to the client is successful, the client returns an array.

[
    "id" => "notify_id",
    "type" => "sms|email|letter",
    "version" => "version",
    "body" => "Hello bar" // with substitution values,
    "subject" => "null|email_subject"
];

Response

If the request to the client is successful, you receive a dict response.

{
    "id": "740e5834-3a29-46b4-9a6f-16142fde533a", # required string - notification ID
    "type": "sms / email / letter" , # required string
    "version": INTEGER,
    "body": "STRING", # required string - body of notification
    "subject": "STRING" # required string for email - subject of email
}

Response

If the request to the client is successful, the client returns a Notifications::Client::TemplatePreview object. In the example shown in the Method section, the object is named response.

You can then call different methods on this object to return the requested information.

Method Information Type
response.id Template UUID String
response.version Template version String
response.body Template content String
response.subject Template subject (email and letter) String
response.type Template type (sms/email/letter) String
response.html Body as rendered HTML (email only) String

Error codes

If the request is not successful, the client returns a NotificationClientException containing the relevant error code:

httpResult message How to fix
400 [{
"error": "BadRequestError",
"message": "Missing personalisation: [PERSONALISATION FIELD]"
}]
Check that the personalisation arguments in the method match the placeholder fields in the template
400 [{
"error": "NoResultFound",
"message": "No result found"
}]
Check the template 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

Error codes

If the request is not successful, the client returns a Notify.Exceptions.NotifyClientException containing the relevant error code.

Status code Message How to fix
400 [{
"error": "BadRequestError",
"message": "Missing personalisation: [PERSONALISATION FIELD]"
}]
Check that the personalisation arguments in the method match the placeholder fields in the template
400 [{
"error": "NoResultFound",
"message": "No result found"
}]
Check the template 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

Error codes

If the request is not successful, the promise fails with an err.

err.response.data.status_code err.response.data.errors How to fix
400 [{
"error": "BadRequestError",
"message": "Missing personalisation: [PERSONALISATION FIELD]"
}]
Check that the personalisation arguments in the method match the placeholder fields in the template
400 [{
"error": "NoResultFound",
"message": "No result found"
}]
Check the template 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

Error codes

If the request is not successful, the client returns an Alphagov\Notifications\Exception\ApiException object containing the relevant error code:

exc->getCode() exc->getErrors() Notes
400 [{
"error": "BadRequestError",
"message": "Missing personalisation: [PERSONALISATION FIELD]"
}]
Check that the personalisation arguments in the method match the placeholder fields in the template.
400 [{
"error": "NoResultFound",
"message": "No result found"
}]
Check the template 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.

Error codes

If the request is not successful, the client returns an HTTPError containing the relevant error code:

error.status_code error.message Notes
400 [{
"error": "BadRequestError",
"message": "Missing personalisation: [PERSONALISATION FIELD]"
}]
Check that the personalisation arguments in the method match the placeholder fields in the template
400 [{
"error": "NoResultFound",
"message": "No result found"
}]
Check the template 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

Error codes

If the request is not successful, the client raises a Notifications::Client::RequestError exception (or a subclass), which contains a code:

error.code error.message class How to fix
400 BadRequestError: Missing personalisation: [PERSONALISATION FIELD] BadRequestError Check that the personalisation arguments in the method match the placeholder fields in the template
400 NoResultFound: No result found BadRequestError Check the template ID
403 AuthError: Error: Your system clock must be accurate to within 30 seconds AuthError Check your system clock
403 AuthError: Invalid token: API key not found AuthError Use the correct API key. Refer to API keys for more information

Letter status descriptions

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.

Precompiled letter status descriptions

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.

Get a PDF for a letter

This returns the PDF contents of a letter.

GET /v2/notifications/{notification_id}/pdf

Query parameters

notification_id (required)

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.

Response

If the request to the client is successful, the client will return bytes representing the raw PDF data.

Errors

If the request is not successful, the API returns json containing the relevant error code. For example:

{
  "status_code": 400,
  "errors": [
    {"error": "ValidationError", "message": "Notification is not a letter"}
  ]
}
error.status_code error.message How to fix
400 [{
"error": "ValidationError",
"message": "id is not a valid UUID"
}]
Check the notification ID
400 [{
"error": "PDFNotReadyError",
"message": "PDF not available yet, try again later"
}]
Wait for the letter to finish processing. This usually takes a few seconds
400 [{
"error": "BadRequestError",
"message": "File did not pass the virus scan"
}]
You cannot retrieve the contents of a letter that contains a virus
400 [{
"error": "BadRequestError",
"message": "PDF not available for letters in technical-failure"
}]
You cannot retrieve the contents of a letter in technical-failure
400 [{
"error": "ValidationError",
"message": "Notification is not a letter"
}]
Check that you are looking up the correct notification
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

Get received text messages

This API call returns one page of up to 250 received text messages. You can get either the most recent messages, or get older messages by specifying a particular notification ID in the olderThanId argument.

You can only get messages that are 7 days old or newer.

You can also set up callbacks for received text messages.

Get received text messages

This API call returns one page of up to 250 received text messages. You can get either the most recent messages, or get older messages by specifying a particular notification ID in the olderThanId argument.

You can only get the status of messages that are 7 days old or newer.

You can also set up callbacks for received text messages.

Get received text messages

This API call returns one page of up to 250 received text messages. You can get either the most recent messages, or get older messages by specifying a particular notification ID in the olderThan argument.

You can only get messages that are 7 days old or newer.

You can also set up callbacks for received text messages.

Get received text messages

This API call returns one page of up to 250 received text messages. 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.

You can also set up callbacks for received text messages.

Get received text messages

This API call returns one page of up to 250 received text messages. 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 received text messages

This API call returns one page of up to 250 received text messages. 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.

You can also set up callbacks for received text messages.

Get a template

Enable received text messages

To receive text messages:

  1. Go to the Text message settings section of the Settings page.
  2. Select Change on the Receive text messages row.

Enable received text messages

To receive text messages:

  1. Go to the Text message settings section of the Settings page.
  2. Select Change on the Receive text messages row.

Enable received text messages

To receive text messages:

  1. Go to the Text message settings section of the Settings page.
  2. Select Change on the Receive text messages row.

Enable received text messages

To receive text messages:

  1. Go to the Text message settings section of the Settings page.
  2. Select Change on the Receive text messages row.

Enable received text messages

To receive text messages:

  1. Go to the Text message settings section of the Settings page.
  2. Select Change on the Receive text messages row.

Enable received text messages

To receive text messages:

  1. Go to the Text message settings section of the Settings page.
  2. Select Change on the Receive text messages row.

Get a template by ID

Method

This returns the latest version of the template.

GET /v2/template/{template_id}

Arguments

template_id (required)

The ID of the template. Sign in to GOV.UK Notify and go to the Templates page to find it.

Response

If the request is successful, the response body is json and the status code is 200.

All messages
{
    "id": "f33517ff-2a88-4f6e-b855-c550268ce08a", # required string - template ID
    "name": "STRING", # required string - template name
    "type": "sms / email / letter" , # required string
    "created_at": "STRING", # required string - date and time template created
    "updated_at": "STRING", # required string - date and time template last updated
    "version": INTEGER,
    "created_by": "someone@example.com", # required string
    "body": "STRING", # required string - body of notification
    "subject": "STRING" # required string for email - subject of email
    "letter_contact_block": "STRING" # optional string - None if not a letter template or contact block not set
}

Error codes

If the request is not successful, the API returns json containing the relevant error code. For example:

{
  "status_code": 404,
  "errors": [
    {"error": "NoResultFound", "message": "No result found"}
  ]
}
error.status_code error.message How to fix
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 your template ID

Get a page of received text messages

Get a page of received text messages

Get a page of received text messages

Get a page of received text messages

Get all received text messages

This method returns a <generator object> with all received text messages.

Get a page of received text messages

Get a template by ID and version

Method

ReceivedTextMessageList response = client.getReceivedTextMessages(olderThanId);

To get the most recent messages, you must pass in an empty argument or null.

To get older messages, pass the ID of an older notification into the olderThanId argument. This returns the next oldest messages from the specified notification ID.

Method

ReceivedTextListResponse response = client.GetReceivedTexts(olderThanId);

Method

notifyClient
  .getReceivedTexts(olderThan)
  .then((response) => console.log(response))
  .catch((err) => console.error(err))

The method returns a promise [external link]. The promise will either:

  • resolve with a response if successful
  • fail with an err if unsuccessful

To get the most recent messages, you must pass in an empty argument or null.

To get older messages, pass the ID of an older notification into the olderThan argument. This returns the next oldest messages from the specified notification ID.

Method

    $this->listReceivedTexts(
      $older_than  // optional
    );

To get older messages, pass the ID of an older notification into the older_than argument. This returns the next 250 oldest messages from the specified notification ID.

If you leave out the older_than argument, the client returns the most recent 250 notifications.

Method

response = get_received_texts_iterator()

Method

args = {
  older_than: 'e194efd1-c34d-49c9-9915-e4267e01e92e'
}
response = client.get_received_texts(args)

To get older messages, pass the ID of an older notification into the older_than argument. This returns the next oldest messages from the specified notification ID.

If you leave out the older_than argument, the client returns the most recent 250 notifications.

Method

GET /v2/template/{template_id}/version/{version}

Arguments

Arguments

Arguments

Arguments

Response

If the request to the client is successful, the client will return a <generator object> that will return all received text messages.

<generator object NotificationsAPIClient.get_received_texts_iterator at 0x1026c7410>

Arguments

Arguments

olderThanId (optional)

Input the ID of a received text message into this argument. If you use this argument, the client returns the next 250 received text messages older than the given ID.

String olderThanId='8e222534-7f05-4972-86e3-17c5d9f894e2'

If you pass in an empty argument or null, the client returns the most recent 250 text messages.

olderThanId (optional)

Input the ID of a notification into this argument to return the next 250 received notifications older than the given ID. For example:

olderThanId: "740e5834-3a29-46b4-9a6f-16142fde533a"

If you leave out the olderThanId argument, the client 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 ReceivedTextListResponse response.

olderThan (optional)

Input the ID of a received text message into this argument. If you use this argument, the client returns the next 250 received text messages older than the given ID. For example:

8e222534-7f05-4972-86e3-17c5d9f894e2"

If you pass in an empty argument or null, the client returns the most recent 250 text messages.

older_than (optional)

Input the ID of a received text message into this argument. If you use this argument, the client returns the next 250 received text messages older than the given ID. For example:

$older_than = '8e222534-7f05-4972-86e3-17c5d9f894e2'

If you leave out the older_than argument, the client 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 collection response.

older_than (optional)

Input the ID of a received text message into this argument. If you use this argument, the client returns the next 250 received text messages older than the given ID. For example:

older_than: '8e222534-7f05-4972-86e3-17c5d9f894e2'

If you leave out the older_than argument, the client 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 collection response.

template_id (required)

The ID of the template. Sign in to GOV.UK Notify and go to the Templates page to find it.

version (required)

The version number of the template.

Response

If the request to the client is successful, the client returns a ReceivedTextMessageList that returns all received texts.

private List<ReceivedTextMessage> receivedTextMessages;
private String currentPageLink;
private String nextPageLink;

The ReceivedTextMessageList has the following properties:

private UUID id;
private String notifyNumber;
private String userNumber;
private UUID serviceId;
private String content;
private ZonedDateTime createdAt;

If the notification specified in the olderThanId argument is older than 7 days, the client returns an empty response.

Response

If the request to the client is successful, the client returns a ReceivedTextListResponse that returns all received text messages.

public List<ReceivedText> receivedTextList;
public Link links;

public class Link {
           public String current;
           public String next;
}
public String id;
public String userNumber;
public String createdAt;
public String serviceId;
public String notifyNumber;
public String content;

If the notification specified in the olderThanId argument is older than 7 days, the client returns an empty ReceivedTextListResponse response.

Response

If the request to the client is successful, the promise resolves with an object containing all received texts.

{
  'received_text_messages':
        [
          {
            'id': 'notify_id', // required
            'user_number': 'user number', // required user number
            'notify_number': 'notify number', // receiving number
            'created_at': 'created at', // required
            'service_id': 'service id', // required service id
            'content': 'text content' // required text content
          }
          // …
        ],
  'links': {
    'current': '/received-test-messages',
    'next': '/received-text-messages?older_than=last_id_in_list'
  }
}

If the notification specified in the olderThan argument is older than 7 days, the promise resolves an empty response.

Response

If the request to the client is successful, the client returns an array.

[
    "received_text_messages" => [
        [
            "id" => "notify_id",
            "user_number" => "user number",
            "notify_number" => "notify number",
            "created_at" => "created at",
            "service_id" => "service id",
            "content" => "text content"
        ],
        [
            ... another received text message
        ]
    ]
  ],
  "links" => [
     "current" => "/received-text-messages",
     "next" => "/received-text-messages?older_than=last_id_in_list"
  ]
];

Response

If the request to the client is successful, the client returns a Notifications::Client::ReceivedTextCollection object. In the example shown in the Method section, the object is named response.

You must then call either the .links method or the .collection method on this object.

Method Information
response.links Returns a hash linking to the requested texts (limited to 250)
response.collection Returns an array of the required texts

If you call the collection method on this object to return an array, you must then call the following methods on the received texts in this array to return information on those texts:

Method Information Type
response.id Received text UUID String
response.created_at Date and time of received text String
response.content Received text content String
response.notify_number Number that received text was sent to String
response.service_id Received text service ID String
response.user_number Number that received text was sent from String

If the notification specified in the older_than argument is older than 7 days, the client returns an empty collection response.

Response

If the request is successful, the response body is json and the status code is 200.

{
    "id": "f33517ff-2a88-4f6e-b855-c550268ce08a", # required string - template ID
    "name": "STRING", # required string - template name
    "type": "sms / email / letter" , # required string
    "created_at": "STRING", # required string - date and time template created
    "updated_at": "STRING", # required string - date and time template last updated
    "version": INTEGER,
    "created_by": "someone@example.com", # required string
    "body": "STRING", # required string - body of notification
    "subject": "STRING" # required string for email - subject of email
    "letter_contact_block": "STRING" # optional string - None if not a letter template or contact block not set
}

Error codes

If the request is not successful, the client returns a NotificationClientException containing the relevant error code:

httpResult Message How to fix
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

Error codes

If the request is not successful, the client returns a Notify.Exceptions.NotifyClientException containing the relevant error code.

Status code Message How to fix
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

Error codes

If the request is not successful, the promise fails with an err.

err.response.data.status_code err.response.data.errors How to fix
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

Error codes

If the request is not successful, the client returns an Alphagov\Notifications\Exception\ApiException object containing the relevant error code:

exc->getCode() exc->getErrors() Notes
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.

Error codes

If the request is not successful, the client raises a Notifications::Client::RequestError exception (or a subclass), which contains a code:

error.code error.message class How to fix
403 AuthError: Error: Your system clock must be accurate to within 30 seconds AuthError Check your system clock
403 AuthError: Invalid token: API key not found AuthError Use the correct API key. Refer to API keys for more information

Error codes

If the request is not successful, the API returns json containing the relevant error code. For example:

{
  "status_code": 404,
  "errors": [
    {"error": "NoResultFound", "message": "No result found"}
  ]
}
error.status_code error.message How to fix
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 your template ID and version

Get one page of received text messages

This will return one page of up to 250 text messages.

Get all templates

Method

response = client.get_received_texts(older_than)

You can specify which text messages to receive by inputting the ID of a received text message into the older_than argument.

Method

This returns the latest version of all templates.

GET /v2/templates

Arguments

Query parameters

older_than (optional)

Input the ID of a received text message into this argument. If you use this argument, the method returns the next 250 received text messages older than the given ID.

older_than='740e5834-3a29-46b4-9a6f-16142fde533a' # optional string - notification ID

If you leave out this argument, the method returns the most recent 250 text messages.

type (optional)

If you leave out this argument, the method returns all templates. Otherwise you can filter by:

  • email
  • sms
  • letter

Response

If the request to the client is successful, the client returns a dict.

{
  "received_text_messages":
  [
    {
      "id": "STRING", # required string - ID of received text message
      "user_number": "STRING", # required string
      "notify_number": "STRING", # required string - receiving number
      "created_at": "STRING", # required string - date and time template created
      "service_id": "STRING", # required string - service ID
      "content": "STRING" # required string - text content
    },
    
  ],
  "links": {
    "current": "/received-text-messages",
    "next": "/received-text-messages?other_than=last_id_in_list"
  }
}

Response

If the request is successful, the response body is json and the status code is 200.

{
    "templates": [
        {
            "id": "f33517ff-2a88-4f6e-b855-c550268ce08a", # required string - template ID
            "name": "STRING", # required string - template name
            "type": "sms / email / letter" , # required string
            "created_at": "STRING", # required string - date and time template created
            "updated_at": "STRING", # required string - date and time template last updated
            "version": NUMBER, # required string - template version
            "created_by": "someone@example.com", # required string
            "body": "STRING", # required string - body of notification
            "subject": "STRING" # required string for email - subject of email
            "letter_contact_block": "STRING" # optional string - None if not a letter template or contact block not set
        },
        {
            ...another template
        }
    ]
}

If no templates exist for a template type or there no templates for a service, the API returns a json object with a templates key for an empty array:

{
    "templates": []
}

Error codes

If the request is not successful, the client returns an HTTPError containing the relevant error code.

error.status_code error.message How to fix
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

Error codes

If the request is not successful, the API returns json containing the relevant error code. For example:

{
  "status_code": 400,
  "errors": [
    {"error": "ValidationError", "message": "type blah is not one of [sms, email, letter, broadcast]"}
  ]
}
error.status_code error.message Notes
400 [{
"error": "ValidationError",
"message": "type <TYPE> is not one of [sms, email, letter, broadcast]"
}]
Make sure that the provided type is one of: email, sms, letter
400 [{
"error": "NoResultFound",
"message": "No result found"
}]
Check the template 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

Generate a preview template

Method

This generates a preview version of a template.

POST /v2/template/{template_id}/preview

The parameters in the personalisation argument must match the placeholder fields in the actual template. The API notification client will ignore any extra fields in the method.

Arguments

template_id (required)

The ID of the template. Sign in to GOV.UK Notify and go to the Templates page to find it.

Request body

personalisation (optional)

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",
  }
}

Response

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
    "type": "sms / email / letter" , # required string
    "version": INTEGER,
    "body": "STRING", # required string - body of notification
    "subject": "STRING" # required string for email - subject of email
}

Error codes

If the request is not successful, the API returns json containing the relevant error code. For example:

error.status_code error.message Notes
400 [{
"error": "BadRequestError",
"message": "Missing personalisation: [PERSONALISATION FIELD]"
}]
Check that the personalisation arguments in the method match the placeholder fields in the template
400 [{
"error": "NoResultFound",
"message": "No result found"
}]
Check the template 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

Error messages

Error messages consist of:

  • a status_code, for example ‘400’
  • an error, for example ’BadRequestError’
  • a message, for example ‘Mobile numbers can only include: 0 1 2 3 4 5 6 7 8 9 ( ) + -‘

Do not use the content of the messages in your code. These can sometimes change, which may affect your API integration.

Use the status_code or the error instead, as these will not change.

Find error codes in:

Error messages

Error messages consist of:

  • a status_code, for example ‘400’
  • an error, for example ’BadRequestError’
  • a message, for example ‘Mobile numbers can only include: 0 1 2 3 4 5 6 7 8 9 ( ) + -‘

Do not use the content of the messages in your code. These can sometimes change, which may affect your API integration.

Use the status_code or the error instead, as these will not change.

Find error codes in:

Error messages

Error messages consist of:

  • a status_code, for example ‘400’
  • an error, for example ’BadRequestError’
  • a message, for example ‘Mobile numbers can only include: 0 1 2 3 4 5 6 7 8 9 ( ) + -‘

Do not use the content of the messages in your code. These can sometimes change, which may affect your API integration.

Use the status_code or the error instead, as these will not change.

Find error codes in:

Error messages

Error messages consist of:

  • a status_code, for example ‘400’
  • an error, for example ’BadRequestError’
  • a message, for example ‘Mobile numbers can only include: 0 1 2 3 4 5 6 7 8 9 ( ) + -‘

Do not use the content of the messages in your code. These can sometimes change, which may affect your API integration.

Use the status_code or the error instead, as these will not change.

Find error codes in:

Error messages

Error messages consist of:

  • a status_code, for example ‘400’
  • an error, for example ’BadRequestError’
  • a message, for example ‘Mobile numbers can only include: 0 1 2 3 4 5 6 7 8 9 ( ) + -‘

Do not use the content of the messages in your code. These can sometimes change, which may affect your API integration.

Use the status_code or the error instead, as these will not change.

Find error codes in:

Error messages

Error messages consist of:

  • a status_code, for example ‘400’
  • an error, for example ’BadRequestError’
  • a message, for example ‘Mobile numbers can only include: 0 1 2 3 4 5 6 7 8 9 ( ) + -‘

Do not use the content of the messages in your code. These can sometimes change, which may affect your API integration.

Use the status_code or the error instead, as these will not change.

Find error codes in:

Get received text messages

This API call returns one page of up to 250 received text messages. 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.

Enable received text messages

To receive text messages:

  1. Go to the Text message settings section of the Settings page.
  2. Select Change on the Receive text messages row.

Method

GET /v2/received-text-messages

Query parameters

older_than (optional)

The ID of a received text message. If this is passed, the response will only list text messages received before that message.

Response

If the request is successful, the response body is json and the status code is 200.

{
  "received_text_messages": [
    {
      "id": "740e5834-3a29-46b4-9a6f-16142fde533a", # required string - notification ID
      "created_at": "STRING", # required string - date and time template created
      "service_id": "STRING", # required string - service ID
      "notify_number": "STRING", # required string - receiving number
      "user_number": "STRING", # required string
      "content": "STRING" # required string - text content
    },
    ...
  ],
  "links": {
    "current": "STRING", # required string - the requested URL
    "next": "STRING" # optional string - the URL to request for the next batch of messages
  }
}

Error codes

If the request is not successful, the API returns json containing the relevant error code. For example:

error.status_code error.message How to fix
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

Testing

All testing takes place in the production environment. There is no test environment for GOV.UK Notify.

Testing

All testing takes place in the production environment. There is no test environment for GOV.UK Notify.

Testing

All testing takes place in the production environment. There is no test environment for GOV.UK Notify.

Testing

All testing takes place in the production environment. There is no test environment for GOV.UK Notify.

Testing

All testing takes place in the production environment. There is no test environment for GOV.UK Notify.

Testing

All testing takes place in the production environment. There is no test environment for GOV.UK Notify.

Error messages

Error messages consist of:

  • a status_code, for example ‘400’
  • an error, for example ’BadRequestError’
  • a message, for example ‘Mobile numbers can only include: 0 1 2 3 4 5 6 7 8 9 ( ) + -‘

Do not use the content of the messages in your code. These can sometimes change, which may affect your API integration.

Use the status_code or the error instead, as these will not change.

Find error codes in:

Smoke testing

If you need to smoke test your integration with Notify on a regular basis, you must use the following smoke test phone numbers and email addresses.

Smoke testing

If you need to smoke test your integration with Notify on a regular basis, you must use the following smoke test phone numbers and email addresses.

Smoke testing

If you need to smoke test your integration with Notify on a regular basis, you must use the following smoke test phone numbers and email addresses.

Smoke testing

If you need to smoke test your integration with Notify on a regular basis, you must use the following smoke test phone numbers and email addresses.

Smoke testing

If you need to smoke test your integration with Notify on a regular basis, you must use the following smoke test phone numbers and email addresses.

Smoke testing

If you need to smoke test your integration with Notify on a regular basis, you must use the following smoke test phone numbers and email addresses.

Phone numbers

  • 07700900000
  • 07700900111
  • 07700900222

Phone numbers

  • 07700900000
  • 07700900111
  • 07700900222

Phone numbers

  • 07700900000
  • 07700900111
  • 07700900222

Phone numbers

  • 07700900000
  • 07700900111
  • 07700900222

Phone numbers

  • 07700900000
  • 07700900111
  • 07700900222

Phone numbers

  • 07700900000
  • 07700900111
  • 07700900222

Email addresses

  • simulate-delivered@notifications.service.gov.uk
  • simulate-delivered-2@notifications.service.gov.uk
  • simulate-delivered-3@notifications.service.gov.uk

The smoke test phone numbers and email addresses will validate the request and simulate a successful response, but will not send a real message, produce a delivery receipt or persist the notification to the database.

You can use these smoke test numbers and addresses with any type of API key.

You can smoke test all Notify API client functions except:

  • Get the status of one message
  • Get the status of all messages

You cannot use the smoke test phone numbers or email address with these functions because they return a fake notification_ID. If you need to test these functions, use a test API key and any other phone number or email.

Email addresses

  • simulate-delivered@notifications.service.gov.uk
  • simulate-delivered-2@notifications.service.gov.uk
  • simulate-delivered-3@notifications.service.gov.uk

The smoke test phone numbers and email addresses will validate the request and simulate a successful response, but will not send a real message, produce a delivery receipt or persist the notification to the database.

You can use these smoke test numbers and addresses with any type of API key.

You can smoke test all Notify API client functions except:

  • Get the status of one message
  • Get the status of all messages

You cannot use the smoke test phone numbers or email address with these functions because they return a fake notification_ID. If you need to test these functions, use a test API key and any other phone number or email.

Email addresses

  • simulate-delivered@notifications.service.gov.uk
  • simulate-delivered-2@notifications.service.gov.uk
  • simulate-delivered-3@notifications.service.gov.uk

The smoke test phone numbers and email addresses will validate the request and simulate a successful response, but will not send a real message, produce a delivery receipt or persist the notification to the database.

You can use these smoke test numbers and addresses with any type of API key.

You can smoke test all Notify API client functions except:

  • Get the status of one message
  • Get the status of all messages

You cannot use the smoke test phone numbers or email address with these functions because they return a fake notification_ID. If you need to test these functions, use a test API key and any other phone number or email.

Email addresses

  • simulate-delivered@notifications.service.gov.uk
  • simulate-delivered-2@notifications.service.gov.uk
  • simulate-delivered-3@notifications.service.gov.uk

The smoke test phone numbers and email addresses will validate the request and simulate a successful response, but will not send a real message, produce a delivery receipt or persist the notification to the database.

You can use these smoke test numbers and addresses with any type of API key.

You can smoke test all Notify API client functions except:

  • Get the status of one message
  • Get the status of all messages

You cannot use the smoke test phone numbers or email address with these functions because they return a fake notification_ID. If you need to test these functions, use a test API key and any other phone number or email.

Email addresses

  • simulate-delivered@notifications.service.gov.uk
  • simulate-delivered-2@notifications.service.gov.uk
  • simulate-delivered-3@notifications.service.gov.uk

The smoke test phone numbers and email addresses will validate the request and simulate a successful response, but will not send a real message, produce a delivery receipt or persist the notification to the database.

You can use these smoke test numbers and addresses with any type of API key.

You can smoke test all Notify API client functions except:

  • Get the status of one message
  • Get the status of all messages

You cannot use the smoke test phone numbers or email address with these functions because they return a fake notification_ID. If you need to test these functions, use a test API key and any other phone number or email.

Email addresses

  • simulate-delivered@notifications.service.gov.uk
  • simulate-delivered-2@notifications.service.gov.uk
  • simulate-delivered-3@notifications.service.gov.uk

The smoke test phone numbers and email addresses will validate the request and simulate a successful response, but will not send a real message, produce a delivery receipt or persist the notification to the database.

You can use these smoke test numbers and addresses with any type of API key.

You can smoke test all Notify API client functions except:

  • Get the status of one message
  • Get the status of all messages

You cannot use the smoke test phone numbers or email address with these functions because they return a fake notification_ID. If you need to test these functions, use a test API key and any other phone number or email.

Other testing

You must use a test API key to do non-smoke testing such as performance or integration testing. You can use any non-smoke testing phone numbers or email addresses. You do not need a specific Notify testing account.

Other testing

You must use a test API key to do non-smoke testing such as performance or integration testing. You can use any non-smoke testing phone numbers or email addresses. You do not need a specific Notify testing account.

Other testing

You must use a test API key to do non-smoke testing such as performance or integration testing. You can use any non-smoke testing phone numbers or email addresses. You do not need a specific Notify testing account.

Other testing

You must use a test API key to do non-smoke testing such as performance or integration testing. You can use any non-smoke testing phone numbers or email addresses. You do not need a specific Notify testing account.

Other testing

You must use a test API key to do non-smoke testing such as performance or integration testing. You can use any non-smoke testing phone numbers or email addresses. You do not need a specific Notify testing account.

Other testing

You must use a test API key to do non-smoke testing such as performance or integration testing. You can use any non-smoke testing phone numbers or email addresses. You do not need a specific Notify testing account.

API keys

There are three different types of API keys:

  • test
  • team and guest list
  • live

When you set up a new service it will start in trial mode. A service in trial mode can create test and team and guest list keys. You must have a live service to create a live key.

To create an API key:

  1. Sign in to GOV.UK Notify.
  2. Go to the API integration page.
  3. Select API keys.
  4. Select Create an API key.

API keys

There are three different types of API keys:

  • test
  • team and guest list
  • live

When you set up a new service it will start in trial mode. A service in trial mode can create test and team and guest list keys. You must have a live service to create a live key.

To create an API key:

  1. Sign in to GOV.UK Notify.
  2. Go to the API integration page.
  3. Select API keys.
  4. Select Create an API key.

API keys

There are three different types of API keys:

  • test
  • team and guest list
  • live

When you set up a new service it will start in trial mode. A service in trial mode can create test and team and guest list keys. You must have a live service to create a live key.

To create an API key:

  1. Sign in to GOV.UK Notify.
  2. Go to the API integration page.
  3. Select API keys.
  4. Select Create an API key.

API keys

There are three different types of API keys:

  • test
  • team and guest list
  • live

When you set up a new service it will start in trial mode. A service in trial mode can create test and team and guest list keys. You must have a live service to create a live key.

To create an API key:

  1. Sign in to GOV.UK Notify.
  2. Go to the API integration page.
  3. Select API keys.
  4. Select Create an API key.

API keys

There are three different types of API keys:

  • test
  • team and guest list
  • live

When you set up a new service it will start in trial mode. A service in trial mode can create test and team and guest list keys. You must have a live service to create a live key.

To create an API key:

  1. Sign in to GOV.UK Notify.
  2. Go to the API integration page.
  3. Select API keys.
  4. Select Create an API key.

API keys

There are three different types of API keys:

  • test
  • team and guest list
  • live

When you set up a new service it will start in trial mode. A service in trial mode can create test and team and guest list keys. You must have a live service to create a live key.

To create an API key:

  1. Sign in to GOV.UK Notify.
  2. Go to the API integration page.
  3. Select API keys.
  4. Select Create an API key.

Testing

All testing takes place in the production environment. There is no test environment for GOV.UK Notify.

Test

Use a test key to test the performance of your service and its integration with GOV.UK Notify.

Messages sent using a test key:

  • generate realistic responses
  • result in a delivered status
  • are not actually delivered to a recipient
  • do not appear on your dashboard
  • do not count against your text message and email allowances

To test failure responses with a test key, use the following numbers and addresses:

Phone number/Email address Response
07700900003 temporary-failure
07700900002 permanent-failure
temp-fail@simulator.notify temporary-failure
perm-fail@simulator.notify permanent-failure
any other valid number or address delivered

You do not have to revoke test keys.

Test

Use a test key to test the performance of your service and its integration with GOV.UK Notify.

Messages sent using a test key:

  • generate realistic responses
  • result in a delivered status
  • are not actually delivered to a recipient
  • do not appear on your dashboard
  • do not count against your text message and email allowances

To test failure responses with a test key, use the following numbers and addresses:

Phone number/Email address Response
07700900003 temporary-failure
07700900002 permanent-failure
temp-fail@simulator.notify temporary-failure
perm-fail@simulator.notify permanent-failure
any other valid number or address delivered

You do not have to revoke test keys.

Test

Use a test key to test the performance of your service and its integration with GOV.UK Notify.

Messages sent using a test key:

  • generate realistic responses
  • result in a delivered status
  • are not actually delivered to a recipient
  • do not appear on your dashboard
  • do not count against your text message and email allowances

To test failure responses with a test key, use the following numbers and addresses:

Phone number/Email address Response
07700900003 temporary-failure
07700900002 permanent-failure
temp-fail@simulator.notify temporary-failure
perm-fail@simulator.notify permanent-failure
any other valid number or address delivered

You do not have to revoke test keys.

Test

Use a test key to test the performance of your service and its integration with GOV.UK Notify.

Messages sent using a test key:

  • generate realistic responses
  • result in a delivered status
  • are not actually delivered to a recipient
  • do not appear on your dashboard
  • do not count against your text message and email allowances

To test failure responses with a test key, use the following numbers and addresses:

Phone number/Email address Response
07700900003 temporary-failure
07700900002 permanent-failure
temp-fail@simulator.notify temporary-failure
perm-fail@simulator.notify permanent-failure
any other valid number or address delivered

You do not have to revoke test keys.

Test

Use a test key to test the performance of your service and its integration with GOV.UK Notify.

Messages sent using a test key:

  • generate realistic responses
  • result in a delivered status
  • are not actually delivered to a recipient
  • do not appear on your dashboard
  • do not count against your text message and email allowances

To test failure responses with a test key, use the following numbers and addresses:

Phone number/Email address Response
07700900003 temporary-failure
07700900002 permanent-failure
temp-fail@simulator.notify temporary-failure
perm-fail@simulator.notify permanent-failure
any other valid number or address delivered

You do not have to revoke test keys.

Test

Use a test key to test the performance of your service and its integration with GOV.UK Notify.

Messages sent using a test key:

  • generate realistic responses
  • result in a delivered status
  • are not actually delivered to a recipient
  • do not appear on your dashboard
  • do not count against your text message and email allowances

To test failure responses with a test key, use the following numbers and addresses:

Phone number/Email address Response
07700900003 temporary-failure
07700900002 permanent-failure
temp-fail@simulator.notify temporary-failure
perm-fail@simulator.notify permanent-failure
any other valid number or address delivered

You do not have to revoke test keys.

Smoke testing

If you need to smoke test your integration with Notify on a regular basis, you must use the following smoke test phone numbers and email addresses.

Phone numbers

  • 07700900000
  • 07700900111
  • 07700900222

Email addresses

  • simulate-delivered@notifications.service.gov.uk
  • simulate-delivered-2@notifications.service.gov.uk
  • simulate-delivered-3@notifications.service.gov.uk

The smoke test phone numbers and email addresses will validate the request and simulate a successful response, but will not send a real message, produce a delivery receipt or persist the notification to the database.

You can use these smoke test numbers and addresses with any type of API key.

You can smoke test all Notify API client functions except:

  • Get the status of one message
  • Get the status of all messages

You cannot use the smoke test phone numbers or email address with these functions because they return a fake notification_ID. If you need to test these functions, use a test API key and any other phone number or email.

Team and guest list

A team and guest list key lets you send real messages to your team members and addresses/numbers on your guest list while your service is still in trial mode.

You will get an error if you use these keys to send messages to anyone who is not on your team or your guest list.

Messages sent with a team and guest list key appear on your dashboard and count against your text message and email allowances.

You do not have to revoke team and guest list keys.

Team and guest list

A team and guest list key lets you send real messages to your team members and addresses/numbers on your guest list while your service is still in trial mode.

You will get an error if you use these keys to send messages to anyone who is not on your team or your guest list.

Messages sent with a team and guest list key appear on your dashboard and count against your text message and email allowances.

You do not have to revoke team and guest list keys.

Team and guest list

A team and guest list key lets you send real messages to your team members and addresses/numbers on your guest list while your service is still in trial mode.

You will get an error if you use these keys to send messages to anyone who is not on your team or your guest list.

Messages sent with a team and guest list key appear on your dashboard and count against your text message and email allowances.

You do not have to revoke team and guest list keys.

Team and guest list

A team and guest list key lets you send real messages to your team members and addresses/numbers on your guest list while your service is still in trial mode.

You will get an error if you use these keys to send messages to anyone who is not on your team or your guest list.

Messages sent with a team and guest list key appear on your dashboard and count against your text message and email allowances.

You do not have to revoke team and guest list keys.

Team and guest list

A team and guest list key lets you send real messages to your team members and addresses/numbers on your guest list while your service is still in trial mode.

You will get an error if you use these keys to send messages to anyone who is not on your team or your guest list.

Messages sent with a team and guest list key appear on your dashboard and count against your text message and email allowances.

You do not have to revoke team and guest list keys.

Team and guest list

A team and guest list key lets you send real messages to your team members and addresses/numbers on your guest list while your service is still in trial mode.

You will get an error if you use these keys to send messages to anyone who is not on your team or your guest list.

Messages sent with a team and guest list key appear on your dashboard and count against your text message and email allowances.

You do not have to revoke team and guest list keys.

Other testing

You must use a test API key to do non-smoke testing such as performance or integration testing. You can use any non-smoke testing phone numbers or email addresses. You do not need a specific Notify testing account.

Live

You can only create live keys once your service is live. You can use live keys to send messages to anyone.

Messages sent with a live key appear on your dashboard and count against your text message and email allowances.

You should revoke and re-create these keys on a regular basis. To revoke a key:

  1. Sign in to GOV.UK Notify.
  2. Go to the API integration page.
  3. Select API keys.
  4. Select Revoke for the API key you want to revoke.

You can have more than one active key at a time.

You should never send test messages to invalid numbers or addresses using a live key.

Live

You can only create live keys once your service is live. You can use live keys to send messages to anyone.

Messages sent with a live key appear on your dashboard and count against your text message and email allowances.

You should revoke and re-create these keys on a regular basis. To revoke a key:

  1. Sign in to GOV.UK Notify.
  2. Go to the API integration page.
  3. Select API keys.
  4. Select Revoke for the API key you want to revoke.

You can have more than one active key at a time.

You should never send test messages to invalid numbers or addresses using a live key.

Live

You can only create live keys once your service is live. You can use live keys to send messages to anyone.

Messages sent with a live key appear on your dashboard and count against your text message and email allowances.

You should revoke and re-create these keys on a regular basis. To revoke a key:

  1. Sign in to GOV.UK Notify.
  2. Go to the API integration page.
  3. Select API keys.
  4. Select Revoke for the API key you want to revoke.

You can have more than one active key at a time.

You should never send test messages to invalid numbers or addresses using a live key.

Live

You can only create live keys once your service is live. You can use live keys to send messages to anyone.

Messages sent with a live key appear on your dashboard and count against your text message and email allowances.

You should revoke and re-create these keys on a regular basis. To revoke a key:

  1. Sign in to GOV.UK Notify.
  2. Go to the API integration page.
  3. Select API keys.
  4. Select Revoke for the API key you want to revoke.

You can have more than one active key at a time.

You should never send test messages to invalid numbers or addresses using a live key.

Live

You can only create live keys once your service is live. You can use live keys to send messages to anyone.

Messages sent with a live key appear on your dashboard and count against your text message and email allowances.

You should revoke and re-create these keys on a regular basis. To revoke a key:

  1. Sign in to GOV.UK Notify.
  2. Go to the API integration page.
  3. Select API keys.
  4. Select Revoke for the API key you want to revoke.

You can have more than one active key at a time.

You should never send test messages to invalid numbers or addresses using a live key.

Live

You can only create live keys once your service is live. You can use live keys to send messages to anyone.

Messages sent with a live key appear on your dashboard and count against your text message and email allowances.

You should revoke and re-create these keys on a regular basis. To revoke a key:

  1. Sign in to GOV.UK Notify.
  2. Go to the API integration page.
  3. Select API keys.
  4. Select Revoke for the API key you want to revoke.

You can have more than one active key at a time.

You should never send test messages to invalid numbers or addresses using a live key.

Limits

Limits

Limits

Limits

Limits

Limits

API keys

There are three different types of API keys:

  • test
  • team and guest list
  • live

When you set up a new service it will start in trial mode. A service in trial mode can create test and team and guest list keys. You must have a live service to create a live key.

To create an API key:

  1. Sign in to GOV.UK Notify.
  2. Go to the API integration page.
  3. Select API keys.
  4. Select Create an API key.

Rate limits

You’re limited to sending 3,000 messages per minute.

This limit is calculated on a rolling basis, per API key type. If you exceed the limit, you will get a 429 error RateLimitError.

Rate limits

You’re limited to sending 3,000 messages per minute.

This limit is calculated on a rolling basis, per API key type. If you exceed the limit, you will get a 429 error RateLimitError.

Rate limits

You’re limited to sending 3,000 messages per minute.

This limit is calculated on a rolling basis, per API key type. If you exceed the limit, you will get a 429 error RateLimitError.

Rate limits

You’re limited to sending 3,000 messages per minute.

This limit is calculated on a rolling basis, per API key type. If you exceed the limit, you will get a 429 error RateLimitError.

Rate limits

You’re limited to sending 3,000 messages per minute.

This limit is calculated on a rolling basis, per API key type. If you exceed the limit, you will get a 429 error RateLimitError.

Rate limits

You’re limited to sending 3,000 messages per minute.

This limit is calculated on a rolling basis, per API key type. If you exceed the limit, you will get a 429 error RateLimitError.

Test

Use a test key to test the performance of your service and its integration with GOV.UK Notify.

Messages sent using a test key:

  • generate realistic responses
  • result in a delivered status
  • are not actually delivered to a recipient
  • do not appear on your dashboard
  • do not count against your text message and email allowances

To test failure responses with a test key, use the following numbers and addresses:

Phone number/Email address Response
07700900003 temporary-failure
07700900002 permanent-failure
temp-fail@simulator.notify temporary-failure
perm-fail@simulator.notify permanent-failure
any other valid number or address delivered

You do not have to revoke test keys.

Daily limits

There’s a limit to the number of messages you can send each day:

Service status Type of API key Daily limit
Live Team or live
  • 250,000 emails
  • 250,000 text messages
  • 20,000 letters
Trial Team 50 emails or text messages
Live or trial Test Unlimited

These limits reset at midnight UTC.

Daily limits

There’s a limit to the number of messages you can send each day:

Service status Type of API key Daily limit
Live Team or live
  • 250,000 emails
  • 250,000 text messages
  • 20,000 letters
Trial Team 50 emails or text messages
Live or trial Test Unlimited

These limits reset at midnight UTC.

Daily limits

There’s a limit to the number of messages you can send each day:

Service status Type of API key Daily limit
Live Team or live
  • 250,000 emails
  • 250,000 text messages
  • 20,000 letters
Trial Team 50 emails or text messages
Live or trial Test Unlimited

These limits reset at midnight UTC.

Daily limits

There’s a limit to the number of messages you can send each day:

Service status Type of API key Daily limit
Live Team or live
  • 250,000 emails
  • 250,000 text messages
  • 20,000 letters
Trial Team 50 emails or text messages
Live or trial Test Unlimited

These limits reset at midnight UTC.

Daily limits

There’s a limit to the number of messages you can send each day:

Service status Type of API key Daily limit
Live Team or live
  • 250,000 emails
  • 250,000 text messages
  • 20,000 letters
Trial Team 50 emails or text messages
Live or trial Test Unlimited

These limits reset at midnight UTC.

Daily limits

There’s a limit to the number of messages you can send each day:

Service status Type of API key Daily limit
Live Team or live
  • 250,000 emails
  • 250,000 text messages
  • 20,000 letters
Trial Team 50 emails or text messages
Live or trial Test Unlimited

These limits reset at midnight UTC.

Team and guest list

A team and guest list key lets you send real messages to your team members and addresses/numbers on your guest list while your service is still in trial mode.

You will get an error if you use these keys to send messages to anyone who is not on your team or your guest list.

Messages sent with a team and guest list key appear on your dashboard and count against your text message and email allowances.

You do not have to revoke team and guest list keys.

Phone network limits

If you repeatedly send text messages to the same number the phone networks will block them.

There’s an hourly limit of:

  • 20 messages with the same content
  • 100 messages with any content

Your messages may not be delivered if you exceed these limits.

Phone network limits

If you repeatedly send text messages to the same number the phone networks will block them.

There’s an hourly limit of:

  • 20 messages with the same content
  • 100 messages with any content

Your messages may not be delivered if you exceed these limits.

Phone network limits

If you repeatedly send text messages to the same number the phone networks will block them.

There’s an hourly limit of:

  • 20 messages with the same content
  • 100 messages with any content

Your messages may not be delivered if you exceed these limits.

Phone network limits

If you repeatedly send text messages to the same number the phone networks will block them.

There’s an hourly limit of:

  • 20 messages with the same content
  • 100 messages with any content

Your messages may not be delivered if you exceed these limits.

Phone network limits

If you repeatedly send text messages to the same number the phone networks will block them.

There’s an hourly limit of:

  • 20 messages with the same content
  • 100 messages with any content

Your messages may not be delivered if you exceed these limits.

Phone network limits

If you repeatedly send text messages to the same number the phone networks will block them.

There’s an hourly limit of:

  • 20 messages with the same content
  • 100 messages with any content

Your messages may not be delivered if you exceed these limits.

Live

You can only create live keys once your service is live. You can use live keys to send messages to anyone.

Messages sent with a live key appear on your dashboard and count against your text message and email allowances.

You should revoke and re-create these keys on a regular basis. To revoke a key:

  1. Sign in to GOV.UK Notify.
  2. Go to the API integration page.
  3. Select API keys.
  4. Select Revoke for the API key you want to revoke.

You can have more than one active key at a time.

You should never send test messages to invalid numbers or addresses using a live key.

Callbacks

Callbacks are when GOV.UK Notify sends POST requests to your service. You can get callbacks when:

  • a text message or email you’ve sent is delivered or fails
  • your service receives a text message

Callbacks

Callbacks are when GOV.UK Notify sends POST requests to your service. You can get callbacks when:

  • a text message or email you’ve sent is delivered or fails
  • your service receives a text message

Callbacks

Callbacks are when GOV.UK Notify sends POST requests to your service. You can get callbacks when:

  • a text message or email you’ve sent is delivered or fails
  • your service receives a text message

Callbacks

Callbacks are when GOV.UK Notify sends POST requests to your service. You can get callbacks when:

  • a text message or email you’ve sent is delivered or fails
  • your service receives a text message

Callbacks

Callbacks are when GOV.UK Notify sends POST requests to your service. You can get callbacks when:

  • a text message or email you’ve sent is delivered or fails
  • your service receives a text message

Callbacks

Callbacks are when GOV.UK Notify sends POST requests to your service. You can get callbacks when:

  • a text message or email you’ve sent is delivered or fails
  • your service receives a text message

Limits

Set up callbacks

You must provide:

  • a URL where Notify will post the callback to
  • a bearer token which Notify will put in the authorisation header of the requests

To do this:

  1. Sign in to GOV.UK Notify.
  2. Go to the API integration page.
  3. Select Callbacks.

Set up callbacks

You must provide:

  • a URL where Notify will post the callback to
  • a bearer token which Notify will put in the authorisation header of the requests

To do this:

  1. Sign in to GOV.UK Notify.
  2. Go to the API integration page.
  3. Select Callbacks.

Set up callbacks

You must provide:

  • a URL where Notify will post the callback to
  • a bearer token which Notify will put in the authorisation header of the requests

To do this:

  1. Sign in to GOV.UK Notify.
  2. Go to the API integration page.
  3. Select Callbacks.

Set up callbacks

You must provide:

  • a URL where Notify will post the callback to
  • a bearer token which Notify will put in the authorisation header of the requests

To do this:

  1. Sign in to GOV.UK Notify.
  2. Go to the API integration page.
  3. Select Callbacks.

Set up callbacks

You must provide:

  • a URL where Notify will post the callback to
  • a bearer token which Notify will put in the authorisation header of the requests

To do this:

  1. Sign in to GOV.UK Notify.
  2. Go to the API integration page.
  3. Select Callbacks.

Set up callbacks

You must provide:

  • a URL where Notify will post the callback to
  • a bearer token which Notify will put in the authorisation header of the requests

To do this:

  1. Sign in to GOV.UK Notify.
  2. Go to the API integration page.
  3. Select Callbacks.

Rate limits

You’re limited to sending 3,000 messages per minute.

This limit is calculated on a rolling basis, per API key type. If you exceed the limit, you will get a 429 error RateLimitError.

Retry callbacks

If Notify sends a POST request to your service, but the request fails then we will retry.

We will retry every 5 minutes, up to a maximum of 5 times.

Retry callbacks

If Notify sends a POST request to your service, but the request fails then we will retry.

We will retry every 5 minutes, up to a maximum of 5 times.

Retry callbacks

If Notify sends a POST request to your service, but the request fails then we will retry.

We will retry every 5 minutes, up to a maximum of 5 times.

Retry callbacks

If Notify sends a POST request to your service, but the request fails then we will retry.

We will retry every 5 minutes, up to a maximum of 5 times.

Retry callbacks

If Notify sends a POST request to your service, but the request fails then we will retry.

We will retry every 5 minutes, up to a maximum of 5 times.

Retry callbacks

If Notify sends a POST request to your service, but the request fails then we will retry.

We will retry every 5 minutes, up to a maximum of 5 times.

Daily limits

There’s a limit to the number of messages you can send each day:

Service status Type of API key Daily limit
Live Team or live
  • 250,000 emails
  • 250,000 text messages
  • 20,000 letters
Trial Team 50 emails or text messages
Live or trial Test Unlimited

These limits reset at midnight UTC.

Delivery receipts

When you send an email or text message, Notify will send a receipt to your callback URL with the status of the message. This is an automated method to get the status of messages.

This functionality works with test API keys, but does not work with smoke testing phone numbers or email addresses.

The callback message is formatted in JSON. All of the values are strings, apart from the template version, which is a number. The key, description and format of the callback message arguments will be:

Key Description Format
id Notify’s id for the status receipts UUID
reference The reference sent by the service 12345678 or null
to The email address or phone number of the recipient hello@gov.uk or 07700912345
status The status of the notification delivered, permanent-failure, temporary-failure or technical-failure
created_at The time the service sent the request 2017-05-14T12:15:30.000000Z
completed_at The last time the status was updated 2017-05-14T12:15:30.000000Z or null
sent_at The time the notification was sent 2017-05-14T12:15:30.000000Z or null
notification_type The notification type email or sms
template_id The id of the template that was used UUID
template_version The version number of the template that was used 1

Delivery receipts

When you send an email or text message, Notify will send a receipt to your callback URL with the status of the message. This is an automated method to get the status of messages.

This functionality works with test API keys, but does not work with smoke testing phone numbers or email addresses.

The callback message is formatted in JSON. All of the values are strings, apart from the template version, which is a number. The key, description and format of the callback message arguments will be:

Key Description Format
id Notify’s id for the status receipts UUID
reference The reference sent by the service 12345678 or null
to The email address or phone number of the recipient hello@gov.uk or 07700912345
status The status of the notification delivered, permanent-failure, temporary-failure or technical-failure
created_at The time the service sent the request 2017-05-14T12:15:30.000000Z
completed_at The last time the status was updated 2017-05-14T12:15:30.000000Z or null
sent_at The time the notification was sent 2017-05-14T12:15:30.000000Z or null
notification_type The notification type email or sms
template_id The id of the template that was used UUID
template_version The version number of the template that was used 1

Delivery receipts

When you send an email or text message, Notify will send a receipt to your callback URL with the status of the message. This is an automated method to get the status of messages.

This functionality works with test API keys, but does not work with smoke testing phone numbers or email addresses.

The callback message is formatted in JSON. All of the values are strings, apart from the template version, which is a number. The key, description and format of the callback message arguments will be:

Key Description Format
id Notify’s id for the status receipts UUID
reference The reference sent by the service 12345678 or null
to The email address or phone number of the recipient hello@gov.uk or 07700912345
status The status of the notification delivered, permanent-failure, temporary-failure or technical-failure
created_at The time the service sent the request 2017-05-14T12:15:30.000000Z
completed_at The last time the status was updated 2017-05-14T12:15:30.000000Z or null
sent_at The time the notification was sent 2017-05-14T12:15:30.000000Z or null
notification_type The notification type email or sms
template_id The id of the template that was used UUID
template_version The version number of the template that was used 1

Delivery receipts

When you send an email or text message, Notify will send a receipt to your callback URL with the status of the message. This is an automated method to get the status of messages.

This functionality works with test API keys, but does not work with smoke testing phone numbers or email addresses.

The callback message is formatted in JSON. All of the values are strings, apart from the template version, which is a number. The key, description and format of the callback message arguments will be:

Key Description Format
id Notify’s id for the status receipts UUID
reference The reference sent by the service 12345678 or null
to The email address or phone number of the recipient hello@gov.uk or 07700912345
status The status of the notification delivered, permanent-failure, temporary-failure or technical-failure
created_at The time the service sent the request 2017-05-14T12:15:30.000000Z
completed_at The last time the status was updated 2017-05-14T12:15:30.000000Z or null
sent_at The time the notification was sent 2017-05-14T12:15:30.000000Z or null
notification_type The notification type email or sms
template_id The id of the template that was used UUID
template_version The version number of the template that was used 1

Delivery receipts

When you send an email or text message, Notify will send a receipt to your callback URL with the status of the message. This is an automated method to get the status of messages.

This functionality works with test API keys, but does not work with smoke testing phone numbers or email addresses.

The callback message is formatted in JSON. All of the values are strings, apart from the template version, which is a number. The key, description and format of the callback message arguments will be:

Key Description Format
id Notify’s id for the status receipts UUID
reference The reference sent by the service 12345678 or null
to The email address or phone number of the recipient hello@gov.uk or 07700912345
status The status of the notification delivered, permanent-failure, temporary-failure or technical-failure
created_at The time the service sent the request 2017-05-14T12:15:30.000000Z
completed_at The last time the status was updated 2017-05-14T12:15:30.000000Z or null
sent_at The time the notification was sent 2017-05-14T12:15:30.000000Z or null
notification_type The notification type email or sms
template_id The id of the template that was used UUID
template_version The version number of the template that was used 1

Delivery receipts

When you send an email or text message, Notify will send a receipt to your callback URL with the status of the message. This is an automated method to get the status of messages.

This functionality works with test API keys, but does not work with smoke testing phone numbers or email addresses.

The callback message is formatted in JSON. All of the values are strings, apart from the template version, which is a number. The key, description and format of the callback message arguments will be:

Key Description Format
id Notify’s id for the status receipts UUID
reference The reference sent by the service 12345678 or null
to The email address or phone number of the recipient hello@gov.uk or 07700912345
status The status of the notification delivered, permanent-failure, temporary-failure or technical-failure
created_at The time the service sent the request 2017-05-14T12:15:30.000000Z
completed_at The last time the status was updated 2017-05-14T12:15:30.000000Z or null
sent_at The time the notification was sent 2017-05-14T12:15:30.000000Z or null
notification_type The notification type email or sms
template_id The id of the template that was used UUID
template_version The version number of the template that was used 1

Phone network limits

If you repeatedly send text messages to the same number the phone networks will block them.

There’s an hourly limit of:

  • 20 messages with the same content
  • 100 messages with any content

Your messages may not be delivered if you exceed these limits.

Received text messages

If your service receives text messages in Notify, Notify can forward them to your callback URL as soon as they arrive.

Find out how to let people send text messages to your service.

The callback message is formatted in JSON. All of the values are strings. The key, description and format of the callback message arguments will be:

Key Description Format
id Notify’s id for the received message UUID
source_number The phone number the message was sent from 447700912345
destination_number The number the message was sent to (your number) 07700987654
message The received message Hello Notify!
date_received The UTC datetime that the message was received by Notify 2017-05-14T12:15:30.000000Z

Received text messages

If your service receives text messages in Notify, Notify can forward them to your callback URL as soon as they arrive.

Find out how to let people send text messages to your service.

The callback message is formatted in JSON. All of the values are strings. The key, description and format of the callback message arguments will be:

Key Description Format
id Notify’s id for the received message UUID
source_number The phone number the message was sent from 447700912345
destination_number The number the message was sent to (your number) 07700987654
message The received message Hello Notify!
date_received The UTC datetime that the message was received by Notify 2017-05-14T12:15:30.000000Z

Received text messages

If your service receives text messages in Notify, Notify can forward them to your callback URL as soon as they arrive.

Find out how to let people send text messages to your service.

The callback message is formatted in JSON. All of the values are strings. The key, description and format of the callback message arguments will be:

Key Description Format
id Notify’s id for the received message UUID
source_number The phone number the message was sent from 447700912345
destination_number The number the message was sent to (your number) 07700987654
message The received message Hello Notify!
date_received The UTC datetime that the message was received by Notify 2017-05-14T12:15:30.000000Z

Received text messages

If your service receives text messages in Notify, Notify can forward them to your callback URL as soon as they arrive.

Find out how to let people send text messages to your service.

The callback message is formatted in JSON. All of the values are strings. The key, description and format of the callback message arguments will be:

Key Description Format
id Notify’s id for the received message UUID
source_number The phone number the message was sent from 447700912345
destination_number The number the message was sent to (your number) 07700987654
message The received message Hello Notify!
date_received The UTC datetime that the message was received by Notify 2017-05-14T12:15:30.000000Z

Received text messages

If your service receives text messages in Notify, Notify can forward them to your callback URL as soon as they arrive.

Find out how to let people send text messages to your service.

The callback message is formatted in JSON. All of the values are strings. The key, description and format of the callback message arguments will be:

Key Description Format
id Notify’s id for the received message UUID
source_number The phone number the message was sent from 447700912345
destination_number The number the message was sent to (your number) 07700987654
message The received message Hello Notify!
date_received The UTC datetime that the message was received by Notify 2017-05-14T12:15:30.000000Z

Received text messages

If your service receives text messages in Notify, Notify can forward them to your callback URL as soon as they arrive.

Find out how to let people send text messages to your service.

The callback message is formatted in JSON. All of the values are strings. The key, description and format of the callback message arguments will be:

Key Description Format
id Notify’s id for the received message UUID
source_number The phone number the message was sent from 447700912345
destination_number The number the message was sent to (your number) 07700987654
message The received message Hello Notify!
date_received The UTC datetime that the message was received by Notify 2017-05-14T12:15:30.000000Z

API architecture

API architecture

API architecture

API architecture

API architecture

API architecture

Callbacks

Callbacks are when GOV.UK Notify sends POST requests to your service. You can get callbacks when:

  • a text message or email you’ve sent is delivered or fails
  • your service receives a text message

Architecture for sending a text message

  1. The service sends a text message notification to Notify.
  2. Notify sends the text message to the provider.
  3. The provider delivers the text message to the recipient.
  4. The recipient receives the text message and sends a delivery receipt to the provider.
  5. The provider sends the delivery receipt to Notify.
  6. Notify receives the delivery receipt and sends an API response to the service.
  7. The service receives the API response.

Architecture for sending a text message

  1. The service sends a text message notification to Notify.
  2. Notify sends the text message to the provider.
  3. The provider delivers the text message to the recipient.
  4. The recipient receives the text message and sends a delivery receipt to the provider.
  5. The provider sends the delivery receipt to Notify.
  6. Notify receives the delivery receipt and sends an API response to the service.
  7. The service receives the API response.

Architecture for sending a text message

  1. The service sends a text message notification to Notify.
  2. Notify sends the text message to the provider.
  3. The provider delivers the text message to the recipient.
  4. The recipient receives the text message and sends a delivery receipt to the provider.
  5. The provider sends the delivery receipt to Notify.
  6. Notify receives the delivery receipt and sends an API response to the service.
  7. The service receives the API response.

Architecture for sending a text message

  1. The service sends a text message notification to Notify.
  2. Notify sends the text message to the provider.
  3. The provider delivers the text message to the recipient.
  4. The recipient receives the text message and sends a delivery receipt to the provider.
  5. The provider sends the delivery receipt to Notify.
  6. Notify receives the delivery receipt and sends an API response to the service.
  7. The service receives the API response.

Architecture for sending a text message

  1. The service sends a text message notification to Notify.
  2. Notify sends the text message to the provider.
  3. The provider delivers the text message to the recipient.
  4. The recipient receives the text message and sends a delivery receipt to the provider.
  5. The provider sends the delivery receipt to Notify.
  6. Notify receives the delivery receipt and sends an API response to the service.
  7. The service receives the API response.

Architecture for sending a text message

  1. The service sends a text message notification to Notify.
  2. Notify sends the text message to the provider.
  3. The provider delivers the text message to the recipient.
  4. The recipient receives the text message and sends a delivery receipt to the provider.
  5. The provider sends the delivery receipt to Notify.
  6. Notify receives the delivery receipt and sends an API response to the service.
  7. The service receives the API response.

Set up callbacks

You must provide:

  • a URL where Notify will post the callback to
  • a bearer token which Notify will put in the authorisation header of the requests

To do this:

  1. Sign in to GOV.UK Notify.
  2. Go to the API integration page.
  3. Select Callbacks.

Architecture for sending an email

  1. The service sends an email notification to Notify.
  2. Notify sends the email to the provider.
  3. The provider delivers the email to the recipient.
  4. The recipient receives the email and sends a delivery receipt to the provider.
  5. The provider sends the delivery receipt to Notify.
  6. Notify receives the delivery receipt and sends an API response to the service.
  7. The service receives the API response.

Architecture for sending an email

  1. The service sends an email notification to Notify.
  2. Notify sends the email to the provider.
  3. The provider delivers the email to the recipient.
  4. The recipient receives the email and sends a delivery receipt to the provider.
  5. The provider sends the delivery receipt to Notify.
  6. Notify receives the delivery receipt and sends an API response to the service.
  7. The service receives the API response.

Architecture for sending an email

  1. The service sends an email notification to Notify.
  2. Notify sends the email to the provider.
  3. The provider delivers the email to the recipient.
  4. The recipient receives the email and sends a delivery receipt to the provider.
  5. The provider sends the delivery receipt to Notify.
  6. Notify receives the delivery receipt and sends an API response to the service.
  7. The service receives the API response.

Architecture for sending an email

  1. The service sends an email notification to Notify.
  2. Notify sends the email to the provider.
  3. The provider delivers the email to the recipient.
  4. The recipient receives the email and sends a delivery receipt to the provider.
  5. The provider sends the delivery receipt to Notify.
  6. Notify receives the delivery receipt and sends an API response to the service.
  7. The service receives the API response.

Architecture for sending an email

  1. The service sends an email notification to Notify.
  2. Notify sends the email to the provider.
  3. The provider delivers the email to the recipient.
  4. The recipient receives the email and sends a delivery receipt to the provider.
  5. The provider sends the delivery receipt to Notify.
  6. Notify receives the delivery receipt and sends an API response to the service.
  7. The service receives the API response.

Architecture for sending an email

  1. The service sends an email notification to Notify.
  2. Notify sends the email to the provider.
  3. The provider delivers the email to the recipient.
  4. The recipient receives the email and sends a delivery receipt to the provider.
  5. The provider sends the delivery receipt to Notify.
  6. Notify receives the delivery receipt and sends an API response to the service.
  7. The service receives the API response.

Retry callbacks

If Notify sends a POST request to your service, but the request fails then we will retry.

We will retry every 5 minutes, up to a maximum of 5 times.

Architecture for sending a letter

  1. The service sends a letter notification to Notify.
  2. Notify sends the letter to the provider.
  3. The provider prints the letter and posts it.
  4. The postal service delivers the letter.
  5. The recipient receives the letter.

Architecture for sending a letter

  1. The service sends a letter notification to Notify.
  2. Notify sends the letter to the provider.
  3. The provider prints the letter and posts it.
  4. The postal service delivers the letter.
  5. The recipient receives the letter.

Architecture for sending a letter

  1. The service sends a letter notification to Notify.
  2. Notify sends the letter to the provider.
  3. The provider prints the letter and posts it.
  4. The postal service delivers the letter.
  5. The recipient receives the letter.

Architecture for sending a letter

  1. The service sends a letter notification to Notify.
  2. Notify sends the letter to the provider.
  3. The provider prints the letter and posts it.
  4. The postal service delivers the letter.
  5. The recipient receives the letter.

Architecture for sending a letter

  1. The service sends a letter notification to Notify.
  2. Notify sends the letter to the provider.
  3. The provider prints the letter and posts it.
  4. The postal service delivers the letter.
  5. The recipient receives the letter.

Architecture for sending a letter

  1. The service sends a letter notification to Notify.
  2. Notify sends the letter to the provider.
  3. The provider prints the letter and posts it.
  4. The postal service delivers the letter.
  5. The recipient receives the letter.

Delivery receipts

When you send an email or text message, Notify will send a receipt to your callback URL with the status of the message. This is an automated method to get the status of messages.

This functionality works with test API keys, but does not work with smoke testing phone numbers or email addresses.

The callback message is formatted in JSON. All of the values are strings, apart from the template version, which is a number. The key, description and format of the callback message arguments will be:

Key Description Format
id Notify’s id for the status receipts UUID
reference The reference sent by the service 12345678 or null
to The email address or phone number of the recipient hello@gov.uk or 07700912345
status The status of the notification delivered, permanent-failure, temporary-failure or technical-failure
created_at The time the service sent the request 2017-05-14T12:15:30.000000Z
completed_at The last time the status was updated 2017-05-14T12:15:30.000000Z or null
sent_at The time the notification was sent 2017-05-14T12:15:30.000000Z or null
notification_type The notification type email or sms
template_id The id of the template that was used UUID
template_version The version number of the template that was used 1

Architecture for getting the status of a message

  1. The service requests a notification status from Notify.
  2. Notify queries the database and retrieves the notification status.
  3. Notify sends the API response with the notification status to the service.
  4. The service receives the API response.

Architecture for getting the status of a message

  1. The service requests a notification status from Notify.
  2. Notify queries the database and retrieves the notification status.
  3. Notify sends the API response with the notification status to the service.
  4. The service receives the API response.

Architecture for getting the status of a message

  1. The service requests a notification status from Notify.
  2. Notify queries the database and retrieves the notification status.
  3. Notify sends the API response with the notification status to the service.
  4. The service receives the API response.

Architecture for getting the status of a message

  1. The service requests a notification status from Notify.
  2. Notify queries the database and retrieves the notification status.
  3. Notify sends the API response with the notification status to the service.
  4. The service receives the API response.

Architecture for getting the status of a message

  1. The service requests a notification status from Notify.
  2. Notify queries the database and retrieves the notification status.
  3. Notify sends the API response with the notification status to the service.
  4. The service receives the API response.

Architecture for getting the status of a message

  1. The service requests a notification status from Notify.
  2. Notify queries the database and retrieves the notification status.
  3. Notify sends the API response with the notification status to the service.
  4. The service receives the API response.

Received text messages

If your service receives text messages in Notify, Notify can forward them to your callback URL as soon as they arrive.

Find out how to let people send text messages to your service.

The callback message is formatted in JSON. All of the values are strings. The key, description and format of the callback message arguments will be:

Key Description Format
id Notify’s id for the received message UUID
source_number The phone number the message was sent from 447700912345
destination_number The number the message was sent to (your number) 07700987654
message The received message Hello Notify!
date_received The UTC datetime that the message was received by Notify 2017-05-14T12:15:30.000000Z

Architecture for getting received text messages

  1. Recipients send text messages.
  2. Notify receives the text messages.
  3. The service requests all or specific received text messages from Notify.
  4. Notify receives the request for received text messages.
  5. Notify sends the received text messages to the service.
  6. The service receives the received text messages.

Architecture for getting received text messages

  1. Recipients send text messages.
  2. Notify receives the text messages.
  3. The service requests all or specific received text messages from Notify.
  4. Notify receives the request for received text messages.
  5. Notify sends the received text messages to the service.
  6. The service receives the received text messages.

Architecture for getting received text messages

  1. Recipients send text messages.
  2. Notify receives the text messages.
  3. The service requests all or specific received text messages from Notify.
  4. Notify receives the request for received text messages.
  5. Notify sends the received text messages to the service.
  6. The service receives the received text messages.

Architecture for getting received text messages

  1. Recipients send text messages.
  2. Notify receives the text messages.
  3. The service requests all or specific received text messages from Notify.
  4. Notify receives the request for received text messages.
  5. Notify sends the received text messages to the service.
  6. The service receives the received text messages.

Architecture for getting received text messages

  1. Recipients send text messages.
  2. Notify receives the text messages.
  3. The service requests all or specific received text messages from Notify.
  4. Notify receives the request for received text messages.
  5. Notify sends the received text messages to the service.
  6. The service receives the received text messages.

Architecture for getting received text messages

  1. Recipients send text messages.
  2. Notify receives the text messages.
  3. The service requests all or specific received text messages from Notify.
  4. Notify receives the request for received text messages.
  5. Notify sends the received text messages to the service.
  6. The service receives the received text messages.

Support

Report any problems via the GOV.UK Notify support page.

You can also:

Support

Report any problems via the GOV.UK Notify support page.

You can also:

Support

Report any problems via the GOV.UK Notify support page.

You can also:

Support

Report any problems via the GOV.UK Notify support page.

You can also:

Support

Report any problems via the GOV.UK Notify support page.

You can also:

Support

Report any problems via the GOV.UK Notify support page.

You can also:

API architecture

Architecture for sending a text message

  1. The service sends a text message notification to Notify.
  2. Notify sends the text message to the provider.
  3. The provider delivers the text message to the recipient.
  4. The recipient receives the text message and sends a delivery receipt to the provider.
  5. The provider sends the delivery receipt to Notify.
  6. Notify receives the delivery receipt and sends an API response to the service.
  7. The service receives the API response.

Architecture for sending an email

  1. The service sends an email notification to Notify.
  2. Notify sends the email to the provider.
  3. The provider delivers the email to the recipient.
  4. The recipient receives the email and sends a delivery receipt to the provider.
  5. The provider sends the delivery receipt to Notify.
  6. Notify receives the delivery receipt and sends an API response to the service.
  7. The service receives the API response.

Architecture for sending a letter

  1. The service sends a letter notification to Notify.
  2. Notify sends the letter to the provider.
  3. The provider prints the letter and posts it.
  4. The postal service delivers the letter.
  5. The recipient receives the letter.

Architecture for getting the status of a message

  1. The service requests a notification status from Notify.
  2. Notify queries the database and retrieves the notification status.
  3. Notify sends the API response with the notification status to the service.
  4. The service receives the API response.

Architecture for getting received text messages

  1. Recipients send text messages.
  2. Notify receives the text messages.
  3. The service requests all or specific received text messages from Notify.
  4. Notify receives the request for received text messages.
  5. Notify sends the received text messages to the service.
  6. The service receives the received text messages.

Support

Report any problems via the GOV.UK Notify support page.

You can also: