-
Notifications
You must be signed in to change notification settings - Fork 19
Java API Library Documentation
This documentation is for developers interested in using the GOV.UK Notify Java client to send emails, text messages or letters.
We recommend that you use this client library rather than use the GOV.UK Notify API directly, as there is no documentation for using the API in this way.
The notifications-java-client deploys to Bintray.
Go to the GOV.UK Notify Java client page on Bintray [external link]:
- Select Set me up! and use the appropriate download instructions.
- Go to the Maven build settings section of the page and copy the appropriate dependency code snippet.
Refer to the client changelog for the version number and the latest updates.
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 the documentation.
You can use GOV.UK Notify to send text messages, emails and letters.
SendSmsResponse response = client.sendSms(
templateId,
phoneNumber,
personalisation,
reference,
smsSenderId
);Sign in to GOV.UK Notify and go to the Templates page to find the template ID.
String templateId="f33517ff-2a88-4f6e-b855-c550268ce08a";
The phone number of the recipient of the text message. This number can be a UK or international number.
String phoneNumber="+447900900123";
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 messageIf a template does not have any placeholder fields for personalised information, you must pass in an empty map or null.
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';
A unique identifier of the sender of the text message notification. To find this information, go to the Text Message sender settings screen:
- Sign in to your GOV.UK Notify account.
- Go to Settings.
- If you need to change to another service, select Switch service in the top right corner of the screen and select the correct one.
- Go to the Text Messages section and select Manage on the Text Message sender row.
In this screen, 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'
If you do not have an smsSenderId, you can leave out this argument.
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 whitelist or live keys appear on your dashboard.
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: signature, api token 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 |
SendEmailResponse response = client.sendEmail(
templateId,
emailAddress,
personalisation,
reference,
emailReplyToId
);Sign in to GOV.UK Notify and go to the Templates page to find the template ID.
String templateId="f33517ff-2a88-4f6e-b855-c550268ce08a";
The email address of the recipient.
String emailAddress='sender@something.com';
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");
personalisation.put("list", listOfItems); // Will appear as a bulleted list in the messageIf a template does not have any placeholder fields for personalised information, you must pass in an empty map or null.
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';
This is an email reply-to address specified by you to receive replies from your users. Your service cannot go live until you set up at least one of these email addresses. To set up:
- Sign into your GOV.UK Notify account.
- Go to Settings.
- If you need to change to another service, select Switch service in the top right corner of the screen and select the correct one.
- Go to the Email section and select Manage on the Email reply-to addresses row.
- Select Change to specify the email address to receive replies, and select Save.
String emailReplyToId='8e222534-7f05-4972-86e3-17c5d9f894e2'
If you do not have an emailReplyToId, you can leave out this argument.
If the request to the client is successful, the client returns a SendEmailResponse:
UUID notificationId;
Optional<String> reference;
UUID templateId;
int templateVersion;
String templateUri;
String body;
String subject;
Optional<String> fromEmail;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: signature, api token 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 files without the need for email attachments.
This is an invitation-only feature. Contact the GOV.UK Notify team to enable this function for your service.
To send a file by email, add a placeholder field to the template then upload a file. The placeholder field will contain a secure link to download the file.
- Sign in to GOV.UK Notify.
- Go to the Templates page and select the relevant email template.
- Add a placeholder field to the email template using double brackets. For example:
"Download your file at: ((link_to_document))"
The file you upload must be a PDF file smaller than 2MB.
- Convert the PDF to a
byte[]. - Pass the
byte[]to the personalisation argument. - 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_document", client.prepareUpload(fileContents));
client.sendEmail(templateId,
emailAddress,
personalisation,
reference,
emailReplyToId);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 document type '{}'. Supported types are: {}"}]
|
The document you upload must be a PDF file |
400 |
[{"error": "BadRequestError","message": "Document didn't pass the virus scan"}]
|
The document you upload must be virus free |
400 |
[{"error": "BadRequestError","message": "Service is not allowed to send documents"}]
|
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: signature, api token not found"}]
|
Use the correct type of API key |
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 |
Document is larger than 2MB |
Document is larger than 2MB |
When your service first signs up to GOV.UK Notify, you’ll start in trial mode. You can only send letters in live mode. You must ask GOV.UK Notify to make your service live.
- Sign in to GOV.UK Notify.
- Select Using Notify.
- Select requesting to go live.
SendLetterResponse response = client.sendLetter(
templateId,
personalisation,
reference
);Sign in to GOV.UK Notify and go to the Templates page to find the template ID.
String templateId = "f33517ff-2a88-4f6e-b855-c550268ce08a";
The personalisation argument always contains the following parameters for the letter recipient's address:
address_line_1address_line_2postcode
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("postcode", "SW14 6BH"); // mandatory address field
personalisation.put("first_name", "Amala"); // field from template
personalisation.put("application_date", "2018-01-01"); // field from template
personalisation.put("list", listOfItems); // Will appear as a bulleted list in the messageIf a template does not have any placeholder fields for personalised information, you must pass in an empty map or null.
The following parameters in the letter recipient's address are optional:
personalisation.put("address_line_3", "123 High Street"); // optional address field
personalisation.put("address_line_4", "Richmond upon Thames"); // optional address field
personalisation.put("address_line_5", "London"); // optional address field
personalisation.put("address_line_6", "Middlesex"); // optional address fieldA 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';
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;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": "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 |
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: signature, api token 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 |
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
);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";
The precompiled letter must be a PDF file which meets the GOV.UK Notify PDF 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>");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);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 LetterResponse:
UUID notificationId;
String reference;
String postageIf the request is not successful, the client returns a NotificationClientException containing the relevant error code:
| httpResult | 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: signature, api token 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 |
Message status depends on the type of message you have sent.
You can only get the status of messages that are 7 days old or newer.
| Status | Information |
|---|---|
| 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. GOV.UK Notify is waiting for delivery information. |
| Delivered | The message was successfully delivered. |
| Failed | This covers all failure statuses: - permanent-failure - "The provider could not deliver the message because the email address or phone number was wrong. You should remove these email addresses or phone numbers from your database. You’ll still be charged for text messages to numbers that do not exist."- temporary-failure - "The provider could not deliver the message after trying for 72 hours. This can happen when the recipient's inbox is full or their phone is off. 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 | 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 notification. |
| Sent / Sent internationally | 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 client API returns this status as sent. The GOV.UK Notify client app returns this status as Sent internationally. |
| Status | information |
|---|---|
| Failed | The only failure status that applies to letters is technical-failure. GOV.UK Notify had an unexpected error while sending to our printing provider. |
| Accepted | GOV.UK Notify has sent the letter to the provider to be printed. |
| Received | The provider has printed and dispatched the letter. |
| Status | information |
|---|---|
| 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 PDF letter specification for more information. |
Notification notification = client.getNotificationById(notificationId);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 in your GOV.UK Notify Dashboard.
- Sign into GOV.UK Notify and select Dashboard.
- Select either emails sent, text messages sent, or letters sent.
- Select the relevant notification.
- Copy the notification ID from the end of the page URL, for example
https://www.notifications.service.gov.uk/services/af90d4cb-ae88-4a7c-a197-5c30c7db423b/notification/ID.
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> postcode;
Optional<String> postage;
String notificationType;
String status;
UUID templateId;
int templateVersion;
String templateUri;
String body;
Optional<String subject;
DateTime createdAt;
Optional<DateTime> sentAt;
Optional<DateTime> completedAt;
Optional<DateTime> estimatedDelivery;
Optional<String> createdByName;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: signature, api token not found"}]
|
Use the correct API key. Refer to API keys for more information |
404 |
[{"error": "NoResultFound","message": "No result found"}]
|
Check the notification ID |
This API call returns one page of up to 250 messages and statuses. You can get either the most recent messages, or get older messages by specifying a particular notification ID in the olderThanId argument.
You can only get the status of messages that are 7 days old or newer.
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.
You can pass in empty arguments or null to ignore these filters.
| status | description | text | letter | Precompiled letter | |
|---|---|---|---|---|---|
| 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. | Yes | Yes | ||
| sending | GOV.UK Notify has sent the message to the provider. The provider will try to deliver the message to the recipient. GOV.UK Notify is waiting for delivery information. | Yes | Yes | ||
| delivered | The message was successfully delivered | Yes | Yes | ||
| sent / sent internationally | The message was sent to an international number. The mobile networks in some countries do not provide any more delivery information. | Yes | |||
| 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 notification. |
Yes | |||
| failed | This returns all failure statuses: - permanent-failure - temporary-failure - technical-failure |
Yes | Yes | ||
| permanent-failure | The provider could not deliver the message because the email address or phone number was wrong. You should remove these email addresses or phone numbers from your database. You’ll still be charged for text messages to numbers that do not exist. | Yes | Yes | ||
| temporary-failure | The provider could not deliver the message after trying for 72 hours. This can happen when the recipient's inbox is full or their phone is off. You can try to send the message again. You’ll still be charged for text messages to phones that are not accepting messages. | Yes | Yes | ||
| technical-failure | Email / Text: 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: Notify had an unexpected error while sending to our printing provider. You can leave out this argument to ignore this filter. |
Yes | Yes | ||
| accepted | GOV.UK Notify has sent the letter to the provider to be printed. | Yes | |||
| received | The provider has printed and dispatched the letter. | Yes | |||
| pending-virus-check | GOV.UK Notify is scanning the precompiled letter file for viruses. | Yes | |||
| virus-scan-failed | GOV.UK Notify found a potential virus in the precompiled letter file. | Yes | |||
| validation-failed | Content in the precompiled letter file is outside the printable area. | Yes |
You can filter by:
emailsmsletter
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';
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.
If the request to the client is successful, the client returns a NotificationList:
List<Notification> notifications;
String currentPageLink;
Optional<String> nextPageLink;If the request is not successful, the client returns a NotificationClientException containing the relevant error code:
| httpResult | Message | |
|---|---|---|
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: signature, api token not found"}]
|
Use the correct API key. Refer to API keys for more information |
This returns the latest version of the template.
Template template = client.getTemplateById(templateId);Sign in to GOV.UK Notify and go to the Templates page to find the template ID.
String templateId='f33517ff-2a88-4f6e-b855-c550268ce08a';
If the request to the client is successful, the client returns a Template:
UUID id;
String name;
String templateType;
DateTime createdAt;
Optional<DateTime> updatedAt;
String createdBy;
int version;
String body;
Optional<String> subject;
Optional<Map<String, Object>> personalisation;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: signature, api token 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 |
Template template = client.getTemplateVersion(templateId, version);Sign in to GOV.UK Notify and go to the Templates page to find the template ID.
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 Template:
UUID id;
String name;
String templateType;
DateTime createdAt;
Optional<DateTime> updatedAt;
String createdBy;
int version;
String body;
Optional<String> subject;
Optional<Map<String, Object>> personalisation;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: signature, api token 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 templates = client.getAllTemplates(templateType);If you don’t use templateType, the client returns all templates. Otherwise you can filter by:
emailsmsletter
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.
This generates a preview version of a template.
TemplatePreview templatePreview = client.getTemplatePreview(
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.
Sign in to GOV.UK Notify and go to the Templates page to find the template ID.
String templateId='f33517ff-2a88-4f6e-b855-c550268ce08a';
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.
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;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: signature, api token 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 messages that are 7 days old or newer.
You can also set up callbacks for received text messages.
Contact the GOV.UK Notify team on the support page or through the Slack channel to enable receiving text messages for your service.
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.
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.
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 DateTime createdAt;If the notification specified in the olderThanId argument is older than 7 days, the client returns an empty response.
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: signature, api token not found"}]
|
Use the correct API key. Refer to API keys for more information |