gemRuby client documentation

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

Set up the client

Install the client

Using Bundler (recommended)

Add notifications-ruby-client to your application’s Gemfile, for example:

gem "notifications-ruby-client"

Then run bundle install from your project’s directory.

Refer to the client changelogarrow-up-right for the version number and the latest updates.

Installing globally

Run the following from the command line:

gem install notifications-ruby-client

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 NotifyNLarrow-up-right and go to the API integration page. You can find more information in the API keys section of this documentation.

Send a message

You can use NotifyNL to send emails, text messages and letters.

Bulk sending

You cannot use a single API call to send messages in bulk.

To send a batch of messages, use the API to loop over your recipient list, sending one message at a time to each recipient.

Make sure you do not exceed our rate limits.

Send a text message

Method

Arguments

phone_number (required)

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

template_id (required)

To find the template ID:

  1. Go to the Templates page and select the relevant template.

  2. Select Copy template ID to clipboard.

For example:

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:

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

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:

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. Go to the Settings page.

  2. 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:

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 Notifications::Client:ResponseNotification object. In the example shown in the Method sectionarrow-up-right, 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 an error. To learn more about error structure, go to Errors section.

Error message
How to fix

ValidationError (status code 400)

phone_number Too many digits

Provide a valid recipient phone number.

phone_number Not enough digits

Provide a valid recipient phone number.

phone_number Not a NL mobile number

Provide a valid Dutch recipient phone number.

phone_number Must not contain letters or symbols

Provide a valid recipient phone number.

phone_number Not a valid country prefix

Provide a valid recipient phone number.

BadRequestError (status code 400)

sms_sender_id <sms_sender_id> does not exist in database for service id

Go to your service Settings and copy a valid sms_sender_id. Check that the API key you are using and the sms_sender_id belong to the same service.

Cannot send to this recipient when service is in trial mode - see https://admin.notifynl.nl/trial-mode

Your service cannot send this text message in trial mode. To fix, you need to request for your service to go live.

Cannot send to international mobile numbers

Sending to international mobile numbers is turned off for your service. You can change this in your service Settings.

Send an email

Method

Arguments

email_address (required)

The email address of the recipient. For example:

template_id (required)

To find the template ID:

  1. Go to the Templates page and select the relevant template.

  2. Select Copy template ID to clipboard.

For example:

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:

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

Find out how to reduce the risk of malicious content injection in placeholdersarrow-up-right.

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:

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

one_click_unsubscribe_url (recommended)

If you send subscription emails you must let recipients opt out of receiving them. Read our Using Notify page for more information about unsubscribe links.

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

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 8058arrow-up-right.

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

You must also add an unsubscribe link to the bottom of your email. The unsubscribe link at the bottom of your email should take the email recipient to a webpage where they can confirm that they want to unsubscribe.

Find out how to add a link when you create a New template or Edit an email template.

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. Go to the Settings page.

  2. In the Email section, select Manage on the Reply-to email addresses row.

  3. Select Add reply-to address.

  4. Enter the email address you want to use, and select Add.

For example:

Reducing the risk of malicious content injection in placeholders

Notify lets you personalise messages using placeholders.

You can format content or add links and urls into placeholders using Markdown.

If you pass in information from untrusted sources (such as online forms) into your Notify template using personalisation, this may be used to add malicious content and links to notifications you send via Notify.

The malicious content could be:

  • Markdown syntax intended to be rendered into HTML

  • a plain text URL which would be rendered into a clickable phishing link

An example of how malicious content can be injected into Notify personalisation:

Template in Notify:

Personalisation:

Email will appear as:

We recommend you sanitise all input from untrusted sources to prevent the injection of malicious content. You can use a backslash to escape individual charactersarrow-up-right. The characters of most concern are those that could be used to add a URL link such as [, ], ( or ).

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 Notifications::Client:ResponseNotification object. In the example shown in the Method sectionarrow-up-right, 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 client returns an error. To learn more about error structure, go to Errors section.

Error message
How to fix

ValidationError (status code 400)

email_address Not a valid email address

Provide a valid recipient email address.

one_click_unsubscribe_url is not a valid https url

Provide a valid https url for your unsubscribe link.

BadRequestError (status code 400)

email_reply_to_id <reply to id> does not exist in database for service id <service id>

Go to your service Settings and copy a valid email_reply_to_id. Double check that the API key you are using and the email_reply_to_id belong to the same service.

Emails cannot be longer than 2000000 bytes. Your message is <rendered template size in bytes> bytes.

Shorten your email message.

Cannot send to this recipient when service is in trial mode - see https://admin.notifynl.nl/trial-mode

Your service cannot send this email in trial mode. To fix, you need to request for your service to go live.

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. NotifyNL 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. Go to the Settings page.

  2. In the Email section, select Manage on the Send files by email row.

  3. Enter the contact details you want to use, and select Save.

Add a placeholder to the template

  1. Go to the Templates page and select the relevant email template.

  2. Select Edit.

  3. 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:

  • CSV (.csv)

  • image (.jpeg, .jpg, .png)

  • Microsoft Excel Spreadsheet (.xlsx)

  • Microsoft Word Document (.doc, .docx)

  • PDF (.pdf)

  • text (.json, .odt, .rtf, .txt)

Your file must be smaller than 2MB. Contact the NotifyNL teamarrow-up-right 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:

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.

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.

Turn off email address check (not recommended)

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:

To let the recipient download the file without confirming their email address, set the confirm_email_before_download flag to 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.

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

Response

If the request to the client is successful, the client returns a Notifications::Client:ResponseNotification object. In the example shown in the Method sectionarrow-up-right, 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 client returns an error. To learn more about error structure, go to Errors section.

Error message
How to fix

BadRequestError (status code 400)

Unsupported file type '(FILE TYPE)'. Supported types are: '(ALLOWED TYPES)'

Wrong file type. You can only upload .csv, .doc, .docx, .jpeg, .jpg, .odt, .pdf, .png, .rtf, .txt or .xlsx files

filename cannot be longer than 100 characters

Choose a shorter filename

filename must end with a file extension. For example, filename.csv

Include the file extension in your filename

Unsupported value for retention_period '(PERIOD)'. Supported periods are from 1 to 78 weeks.

Choose a period between 1 and 78 weeks

Unsupported value for confirm_email_before_download: '(VALUE)'. Use a boolean true or false value.

Use either True or False

File did not pass the virus scan

The file contains a virus

Send files by email has not been set up - add contact details for your service at https://admin.notifynl.nl/services/(SERVICE ID)/service-settings/send-files-by-email

Can only send a file by email

Make sure you are using an email template

Client error (no status code)

ValueError('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. Go to the Settings page.

  2. In the Your service is in trial mode section, select request to go live.

Method

Arguments

template_id (required)

To find the template ID:

  1. Go to the Templates page and select the relevant template.

  2. Select Copy template ID to clipboard.

For example:

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:

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:

Response

If the request to the client is successful, the client returns a Notifications::Client:ResponseNotification object. In the example shown in the Method sectionarrow-up-right, 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 an error. To learn more about error structure, go to Errors section.

Error message
How to fix

ValidationError (status code 400)

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.

Must be a real NL postcode

Ensure that the value for the last line of the address is a real NL postcode.

Must be a real address

Provide a real recipient address. We do not accept letters for “no fixed abode” addresses, as those cannot be delivered.

Last line of address must be a real NL postcode or another country

Ensure that the value for the last line of the address is a real NL postcode or the name of a country outside the NL.

The last line of a BFPO address must not be a country.

The last line of a BFPO address must not be a country.

Address must be at least 3 lines

Provide at least 3 lines of address.

Address must be no more than 7 lines

Provide no more than 7 lines of address.

Address lines must not start with any of the following characters: @ ( ) = [ ] ” \ / , < >

Change the start of an address line, so it doesn’t start with one of these characters. This is a requirement from our printing provider.

postage invalid. It must be either first, second or economy.

Specify valid postage option.

BadRequestError (status code 400)

Cannot send letters when service is in trial mode - see https://admin.notifynl.nl/trial-mode

Your service cannot send this letter in trial mode.

Service is not allowed to send letters

Turn on sending letters in your service Settings on NotifyNL webpage

letter_contact_id <letter_contact_id> does not exist in database for service id <service id>

Go to your service Settings and copy a valid letter_contact_id. Check that the API key you are using and the letter_contact_id belong to the same service.

BadRequestError (status code 403)

Cannot send letters with a team api key

Use the correct type of API key.

Send a precompiled letter

Method

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.

pdf_file (required)

The precompiled letter must be a PDF file which meets the GOV.UK Notify letter specificationarrow-up-right.

postage (optional)

You can choose first class, second class or economy mail postage for your precompiled letter. Set the value to first for first class, second for second class or economy for economy mail. 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 Notifications::Client:ResponsePrecompiledLetter object. In the example shown in the Method sectionarrow-up-right, 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 an error. To learn more about error structure, go to Errors section.

Error message
How to fix

ValidationError (status code 400)

reference is a required property

Add a reference argument to the method call

postage invalid. It must be either first, second or economy.

Change the value of postage argument in the method call to either "first", "second" or "economy"

BadRequestError (status code 400)

Letter content is not a valid PDF

PDF file format is required.

Cannot send letters when service is in trial mode - see https://admin.notifynl.nl/trial-mode

Your service cannot send this precompiled letter in trial mode.

BadRequestError (status code 403)

Cannot send letters with a team api key

Use the correct type of API key.

Get message data

Get the data for one message

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

Method

Arguments

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 returns a Notifications::Client::Notification object. In the example shown in the Method sectionarrow-up-right, 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.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.one_click_unsubscribe

URL that you provided so your recipients can unsubscribe (email only)

String

response.is_cost_data_ready

This field is true if cost data is ready, and false if it isn’t

Boolean

response.cost_in_pounds

Cost of the notification in pounds. The cost does not take free allowance into account

Float

response.cost_details.billable_sms_fragments

Number of billable SMS fragments in your text message (SMS only)

Integer

response.cost_details.international_rate_multiplier

For international SMS rate is multiplied by this value (SMS only)

Integer

response.cost_details.sms_rate

Cost of 1 SMS fragment (SMS only)

Float

response.cost_details.billable_sheets_of_paper

Number of sheets of paper in the letter you sent, that you will be charged for (letter only)

Integer

response.cost_details.postage

Postage class of the notification sent (letter only)

String

Error codes

If the request is not successful, the client returns an error. To learn more about error structure, go to Errors section.

Error message
How to fix

ValidationError (status code 400)

id is not a valid UUID

Check the notification ID.

NoResultFound (status code 404)

No result found

If it’s outside the retention period, you may no longer get the status of the message. The default retention period is 7 days.

Get the data for multiple messages

This API call returns one page with data for up to 250 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 messages that are within your data retention period. The default data retention period is 7 days. It can be changed in your Service Settings.

Method

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.

Arguments

You can leave out these arguments to ignore these filters.

status (optional)

The possible statuses that a notification can be in depends on the type of notification:

You can specify a single status:

Or multiple, by specifying an array:

You can leave out this argument to ignore this filter.

templateType (optional)

You can filter by:

  • email

  • sms

  • letter

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:

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:

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.

Response

If the request to the client is successful, the client returns a Notifications::Client::NotificationsCollection object. In the example shown in the Method sectionarrow-up-right, 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.postage

Postage class of the notification sent (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

response.one_click_unsubscribe

URL that you provided so your recipients can unsubscribe (email only)

String

response.is_cost_data_ready

This field is true if cost data is ready, and false if it isn’t

Boolean

response.cost_in_pounds

Cost of the notification in pounds. The cost does not take free allowance into account

Float

response.cost_details.billable_sms_fragments

Number of billable SMS fragments in your text message (SMS only)

Integer

response.cost_details.international_rate_multiplier

For international SMS rate is multiplied by this value (SMS only)

Integer

response.cost_details.sms_rate

Cost of 1 SMS fragment (SMS only)

Float

response.cost_details.billable_sheets_of_paper

Number of sheets of paper in the letter you sent, that you will be charged for (letter only)

Integer

response.cost_details.postage

Postage class of the notification sent (letter only)

String

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

Error codes

If the request is not successful, the client returns an error. To learn more about error structure, go to Errors sectionarrow-up-right.

Error message
How to fix

BadRequestError (status code 400)

ValidationError: 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]

ValidationError: ‘Apple’ is not one of [sms, email, letter]

In addition to the above, you may also encounter:

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 spamarrow-up-right 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.

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 ID 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 supportarrow-up-right. 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.

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 specificationarrow-up-right 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

Method

This returns the pdf contents of a letter notification.

Arguments

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 string containing the raw PDF data.

Error codes

If the request is not successful, the client returns an error. To learn more about error structure, go to Errors sectionarrow-up-right.

Error message
How to fix

BadRequestError (status code 400)

ValidationError: id is not a valid UUID

Check the notification ID.

ValidationError: Notification is not a letter

Check that you are looking up the correct notification.

PDFNotReadyError: PDF not available yet, try again later

Wait for the letter to finish processing. This usually takes a few seconds.

BadRequestError: File did not pass the virus scan

You cannot retrieve the contents of a letter that contains a virus.

BadRequestError: PDF not available for letters in technical-failure

You cannot retrieve the contents of a letter in technical-failure.

BadRequestError: Notification is not a letter

Check that you are looking up the correct notification.

NotFoundError (status code 404)

NoResultFound: No result found

Check the notification ID.

In addition to the above, you may also encounter:

Get a template

Get a template by ID

Method

This returns the latest version of the template.

Arguments

id (required)

The ID of the template. Sign in to GOV.UK Notifyarrow-up-right and go to the Templates page to find it. For example:

Response

If the request to the client is successful, the client returns a Notifications::Client::Template object. In the example shown in the Method sectionarrow-up-right, 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

Error codes

If the request is not successful, the client returns an error. To learn more about error structure, go to Errors sectionarrow-up-right.

Error message
How to fix

NotFoundError (status code 404)

NoResultFound: No Result Found

In addition to the above, you may also encounter:

Get a template by ID and version

Method

Arguments

id (required)

The ID of the template. Sign in to GOV.UK Notifyarrow-up-right and go to the Templates page to find it. For example:

version (required)

The version number of the template.

Response

If the request to the client is successful, the client returns a Notifications::Client::Template object. In the example shown in the Method sectionarrow-up-right, 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

Error codes

If the request is not successful, the client returns an error. To learn more about error structure, go to Errors sectionarrow-up-right.

Error message
How to fix

NotFoundError (status code 404)

NoResultFound: No Result Found

In addition to the above, you may also encounter:

Get all templates

Method

This returns the latest version of all templates inside a collection object.

Arguments

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 Notifications::Client::TemplateCollection object. In the example shown in the Method sectionarrow-up-right, 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 returns an error. To learn more about error structure, go to Errors sectionarrow-up-right.

Error message
How to fix

BadRequestError (status code 400)

ValidationError: Template type is not one of [sms, email, letter]

In addition to the above, you may also encounter:

Generate a preview template

Method

This generates a preview version of a template.

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

id (required)

The ID of the template. Sign in to GOV.UK Notifyarrow-up-right and go to the Templates page to find it. For example:

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:

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 Notifications::Client::TemplatePreview object. In the example shown in the Method sectionarrow-up-right, 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 an error. To learn more about error structure, go to Errors sectionarrow-up-right.

Error message
How to fix

BadRequestError (status code 400)

BadRequestError: Missing personalisation: [PERSONALISATION FIELD]

Check that the personalisation arguments in the method match the placeholder fields in the template.

NotFoundError (status code 404)

NoResultFound: No Result Found

In addition to the above, you may also encounter:

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

You can also set up callbacksarrow-up-right for received text messages.

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 page of received text messages

Method

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.

Arguments

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:

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.

Response

If the request to the client is successful, the client returns a Notifications::Client::ReceivedTextCollection object. In the example shown in the Method sectionarrow-up-right, 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.

Error codes

If the request is not successful, the client returns an error. To learn more about error structure, go to Errors sectionarrow-up-right.

There are no errors specific to this endpoint, but you may encounter:

Errors

Error handling

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

This error consists of:

  • a status code, for example 400

  • an error class, for example BadRequestError

  • a message, for example Mobile numbers can only include: 0 1 2 3 4 5 6 7 8 9 ( ) + -

To access these details about the error, read its error.code, error.class, and error.message fields, for example:

Error’s message field is a string, for example:

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 type instead, as these will not change.

General errors

You may encounter following errors when making requests to a number of Notify’s API endpoints.

Error message
How to fix

BadRequestError (status code 400)

BadRequestError: Cannot send to this recipient using a team-only API key.

Use a live API key, or add recipient to Guest list (located in API Integration section)

BadRequestError: Cannot send to this recipient when service is in trial mode – see https://www.notifications.service.gov.uk/trial-mode

You need to request for your service to go live before you can send messages to people outside your team.

AuthError (status code 403)

BadRequestError: Error: Your system clock must be accurate to within 30 seconds

Check your system clock

BadRequestError: Invalid token: API key not found

Use the correct API key. Refer to API keysarrow-up-right for more information

RateLimitError (status code 429)

RateLimitError: Exceeded rate limit for key type <team/test/live> of 3000/<custom limit> requests per 60 seconds

Refer to API rate limitsarrow-up-right for more information

TooManyRequestsError: Exceeded send limits (<sms/email/letter/international_sms>: <LIMIT SIZE>) for today

Refer to service limitsarrow-up-right for the limit size

ServerError (status code 500)

Exception: Internal server error

Notify was unable to process the request, resend your notification.

Schema validation errors

The following are a few examples of schema validation errors you may encounter when making a request to a Notify endpoint.

Error message
How to fix

BadRequestError (status code 400)

ValidationError: template_id is a required property

Provide the missing argument.

ValidationError: sms_sender_id is not a valid UUID

Check the argument to make sure that it is valid for the given data type.

ValidationError: personalisation <data type of argument you sent> is not of type object

Provide argument in the correct type.

ValidationError: reference <reference string you provided> is too long

Provide a shorter string.

ValidationError: template_type <invalid type> is not one of [sms, email, letter]

Make sure that the argument matches one of the items in the list.

ValidationError: Additional properties are not allowed (<list of unexpected properties> was unexpected)

Only provide allowed arguments for the endpoint.

Endpoint-specific errors

In addition to the above, you may also encounter endpoint-specific errors, which are listed under each relevant API endpoint section.

Find references for endpoint-specific errors in:


Last updated