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.
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.
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.
Go to your project directory and run the following in the command line to install the client package:
dotnet add package GovukNotify
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].
Run the following in the NuGet package manager console to install the client package:
nuget install GovukNotify
Use the Package Manager UI to search for and install the client package [external link].
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);
You can use GOV.UK Notify to send text messages, emails and letters.
SmsNotificationResponse response = client.SendSms(
mobileNumber: "+447900900123",
templateId: "f33517ff-2a88-4f6e-b855-c550268ce08a",
);
The phone number of the recipient of the text message. This can be a UK or international number.
string mobileNumber: "+447900900123";
To find the template ID:
- Sign in to GOV.UK Notify.
- Go to the Templates page and select the relevant template.
- Select Copy template ID to clipboard.
For example:
string templateId: "f33517ff-2a88-4f6e-b855-c550268ce08a";
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.
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.
A unique identifier of the sender of the text message notification.
To find the text message sender:
- Sign in to GOV.UK Notify.
- Go to the Settings page.
- In the Text Messages section, select Manage on the Text Message sender row.
You can then either:
- copy the sender ID that you want to use and paste it into the method
- select Change to change the default sender that the service 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.
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.
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 |
EmailNotificationResponse response = client.SendEmail(emailAddress, templateId, personalisation, reference, emailReplyToId);
client.SendEmail(
emailAddress: "sender@something.com",
templateId: "f33517ff-2a88-4f6e-b855-c550268ce08a"
);
The email address of the recipient. For example:
string emailAddress: "sender@something.com";
To find the template ID:
- Sign in to GOV.UK Notify.
- Go to the Templates page and select the relevant template.
- Select Copy template ID to clipboard.
For example:
string templateId: "f33517ff-2a88-4f6e-b855-c550268ce08a";
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.
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.
This is an email address specified by you to receive replies from your users. You must add at least one reply-to email address before your service can go live.
To add a reply-to email address:
- Sign in to GOV.UK Notify.
- Go to the Settings page.
- In the Email section, select Manage on the Reply-to email addresses row.
- Select Add reply-to address.
- Enter the email address you want to use, and select Add.
For example:
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.
If the request to the client is successful, the client returns an EmailNotificationResponse
:
public String id;
public String reference;
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;
}
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. |
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
- Sign in to GOV.UK Notify.
- Go to the Settings page.
- In the Email section, select Manage on the Send files by email row.
- Enter the contact details you want to use, and select Save.
- Sign in to GOV.UK Notify.
- Go to the Templates page and select the relevant email template.
- Select Edit.
- Add a placeholder to the email template using double brackets. For example: "Download your file at: ((link_to_file))"
Your email should also tell recipients how long the file will be available to download.
You can upload PDF, CSV, .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.
- Convert the PDF to a
byte[]
. - Pass the
byte[]
to the personalisation argument. - 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)}
};
Uploads for CSV files should use the isCsv
parameter on the PrepareUpload()
function. For example:
byte[] documentContents = File.ReadAllBytes("<file path>");
Dictionary<String, dynamic> personalisation = new Dictionary<String, dynamic>
{
{ "name", "Foo" },
{ "link_to_file", NotificationClient.PrepareUpload(documentContents, isCsv = true)}
};
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 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)}
};
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")}
};
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": "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 |
When you add a new service it will start in trial mode. You can only send letters when your service is live.
To send Notify a request to go live:
- Sign in to GOV.UK Notify.
- Go to the Settings page.
- In the Your service is in trial mode section, select request to go live.
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);
To find the template ID:
- Sign in to GOV.UK Notify.
- Go to the Templates page and select the relevant template.
- Select Copy template ID to clipboard.
For example:
string templateId: "f33517ff-2a88-4f6e-b855-c550268ce08a";
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:
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"
}
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.
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;
}
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": "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. |
LetterNotificationsResponse response = client.SendPrecompiledLetter(
clientReference,
pdfContents,
postage
);
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.
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>");
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.
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
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": "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 |
You can only get the status of messages sent within the retention period. The default retention period is 7 days.
Notification notification = client.GetNotificationById(notificationId);
The ID of the notification. To find the notification ID, you can either:
- check the response to the original notification method call
- sign in to GOV.UK Notify and go to the API integration page
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;
}
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 |
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.
NotificationList notifications = client.GetNotifications(templateType, status, reference, olderThanId, includeSpreadsheetUploads);
You can leave out these arguments to ignore these filters.
You can filter by:
email
sms
letter
You can filter by each:
You can leave out this argument to ignore this filter.
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";
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.
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
.
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;
}
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 |
Status | Description |
---|---|
#created |
GOV.UK Notify has placed the message in a queue, ready to be sent to the provider. It should only remain in this state for a few seconds. |
#sending |
GOV.UK Notify has sent the message to the provider. The provider will try to deliver the message to the recipient for up to 72 hours. GOV.UK Notify is waiting for delivery information. |
#delivered |
The message was successfully delivered. |
#permanent-failure |
The provider could not deliver the message because the email address was wrong. You should remove these email addresses from your database. |
#temporary-failure |
The provider could not deliver the message. This can happen when the recipient’s inbox is full or their anti-spam filter rejects your email. Check your content does not look like spam before you try to send the message again. |
#technical-failure |
Your message was not sent because there was a problem between Notify and the provider. You’ll have to try sending your messages again. |
Status | Description |
---|---|
#created |
GOV.UK Notify has placed the message in a queue, ready to be sent to the provider. It should only remain in this state for a few seconds. |
#sending |
GOV.UK Notify has sent the message to the provider. The provider will try to deliver the message to the recipient for up to 72 hours. GOV.UK Notify is waiting for delivery information. |
#pending |
GOV.UK Notify is waiting for more delivery information. GOV.UK Notify received a callback from the provider but the recipient’s device has not yet responded. Another callback from the provider determines the final status of the text message. |
#sent |
The message was sent to an international number. The mobile networks in some countries do not provide any more delivery information. The GOV.UK Notify website displays this status as 'Sent to an international number'. |
#delivered |
The message was successfully delivered. |
#permanent-failure |
The provider could not deliver the message. This can happen if the phone number was wrong or if the network operator rejects the message. If you’re sure that these phone numbers are correct, you should contact GOV.UK Notify support. If not, you should remove them from your database. You’ll still be charged for text messages that cannot be delivered. |
#temporary-failure |
The provider could not deliver the message. This can happen when the recipient’s phone is off, has no signal, or their text message inbox is full. You can try to send the message again. You’ll still be charged for text messages to phones that are not accepting messages. |
#technical-failure |
Your message was not sent because there was a problem between Notify and the provider. You’ll have to try sending your messages again. You will not be charged for text messages that are affected by a technical failure. |
Status | Description |
---|---|
#accepted |
GOV.UK Notify has sent the letter to the provider to be printed. |
#received |
The provider has printed and dispatched the letter. |
#cancelled |
Sending cancelled. The letter will not be printed or dispatched. |
#technical-failure |
GOV.UK Notify had an unexpected error while sending the letter to our printing provider. |
#permanent-failure |
The provider cannot print the letter. Your letter will not be dispatched. |
Status | Description |
---|---|
#accepted |
GOV.UK Notify has sent the letter to the provider to be printed. |
#received |
The provider has printed and dispatched the letter. |
#cancelled |
Sending cancelled. The letter will not be printed or dispatched. |
#pending-virus-check |
GOV.UK Notify has not completed a virus scan of the precompiled letter file. |
#virus-scan-failed |
GOV.UK Notify found a potential virus in the precompiled letter file. |
#validation-failed |
Content in the precompiled letter file is outside the printable area. See the GOV.UK Notify letter specification for more information. |
#technical-failure |
GOV.UK Notify had an unexpected error while sending the letter to our printing provider. |
#permanent-failure |
The provider cannot print the letter. Your letter will not be dispatched. |
This returns the pdf contents of a letter notification.
byte[] pdfFile = client.GetPdfForLetter(notificationId);
The ID of the notification. To find the notification ID, you can either:
- check the response to the original notification method call
- sign in to GOV.UK Notify and go to the API integration page
If the request to the client is successful, the client will return a byte[]
object containing the raw PDF data.
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 |
This returns the latest version of the template.
TemplateResponse response = client.GetTemplateById(
"templateId"
);
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";
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
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 |
TemplateResponse response = client.GetTemplateByIdAndVersion(
"templateId",
1 // integer required for version number
);
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";
The version number of the template.
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
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 |
This returns the latest version of all templates.
TemplateList response = client.GetAllTemplates(
"sms" | "email" | "letter" // optional
);
If left out, the method returns all templates. Otherwise you can filter by:
email
sms
letter
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
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.
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";
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.
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
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 |
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.
To receive text messages:
- Go to the Text message settings section of the Settings page.
- Select Change on the Receive text messages row.
ReceivedTextListResponse response = client.GetReceivedTexts(olderThanId);
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.
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.
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 |