Give us feedback
gov-uk-notify-service
Service icon

GOV UK Notify

Stable version 1.0.2 (Compatible with OutSystems 11)
Uploaded on 23 November 2023 by 
Version 1
0.0
 (0 ratings)
gov-uk-notify-service

GOV UK Notify

Documentation
1.0.2

To start to use this component, please install the "GOV UK Notify Service" application in your factory.

It's provided an integration to send text messages, emails (with or without a file), letters and precompiled letters. Additionally, you can verify the status of a single message or multiple messages, as well as get the details of a single template or multiple templates.

The authentication/authorization of each request is made by converting the API key of your service account into JSON Web Token (JWT) of JWT the forge component. The outcome is then added to the HTTP request "Authorization" header.


Authorization

Authorization header

JSON Web Tokens (JWT) are encoded using a secret key with the format of 3d844edf-8d35-48ac-975b-e847b4f122b0.

That secret key forms a part of your API key, which follows the format {key_name}-{iss-uuid}-{secret-key-uuid}.

For example, if your API key is my_test_key-26785a09-ab16-4eb0-8407-a37497a57506-3d844edf-8d35-48ac-975b-e847b4f122b0:

  • your API key name is my_test_key
  • your iss (your service id) is 26785a09-ab16-4eb0-8407-a37497a57506
  • your secret key is 3d844edf-8d35-48ac-975b-e847b4f122b0

iat (issued at) is the current time in UTC in epoch seconds. The token expires within 30 seconds of the current time.

Refer to the JSON Web Tokens website for more information on encoding your authorisation header.

When you have an encoded and signed token, add that token to a header as follows:

"Authorization": "Bearer encoded_jwt_token".


Implementation

In the "OnBeforeRequest" of GovUKNotifyAPIv2 consumed REST API is called a server action wrapper "OnBeforeRequest_GovUKNotifyAPI".

This wrapper manipulates the HTTP Request before it is sent, and one of the actions taken into consideration is a wrapper "GenerateTokenFromHTTPHeaderAPIKey". The main goal of this wrapper is to gather the API Key from the header request and with it to generate a JWT bearer token to be appended and defined as a value of the "Authorization" HTTP request header.

The "GenerateTokenFromHTTPHeaderAPIKey" server action receives as an input parameter a list of all HTTP Request Headers and returns the encoded token. From the Headers parameter will be extracted the API Key that was originally sent. For this extraction, we are using a private server action (GetAPIKeyFromHeaders) that filters the Headers list by a specific header name.  

After obtaining the API Key, it is used as an input parameter for a new wrapper (GenerateJWT) that will be used to generate the final encoded token.
To keep the token's lifetime short, no value is defined in the "Expires" parameter, meaning the token must be used within 30 seconds after its generation.

Inside the "GenerateJWT" wrapper, a local action "SplitAPIKey" is invoked which, after validating whether the API Key matches the intended format, returns: Name, Service Id and Secret Key (as indicated in the "Authorization Header" section).

For the proper generation of the JWT token, it is used the Service Id as the Issuer, HS256 as the Algorithm, and the Secret Key as the Key and KeyId. If the encoded token is generated successfully, its value is returned. To know a little bit more about how to use the service below, please click here.

Finally, after the encoded token has been generated, it is added to the "Authorization" header of the HTTP request, such as the "Content-Type" header as "application/json".


Send a message

Send a text message

An Integration with the "postSMS" method of  GovUKNotifyAPIv2 is done through the service action "Send_SMS" implemented in the GovUKNotify_IS module.

This service action includes all the flow needed to validate the required fields APIKey and TemplateID, through a "CheckRequest" server action wrapper, and checks if the MobileNumber is empty.

Additionally, the "Request" input parameter is converted to the required structure of the "postSMS" API method, and the integration response is converted to a local "Response" structure.

Below are presented the required and optional request fields for this integration and also its definitions:

  • APIKey(required)

    To get an API key, sign in to GOV.UK Notify and go to the API integration page.

    Your API key follows the format {key_name}-{iss-uuid}-{secret-key-uuid} that is validated using the regular expression ^\w+-([\da-fA-F]{8}-([\da-fA-F]{4}-){3}[\da-fA-F]{12}-?){2}$.

    The value of the API Key is then encoded to be sent in the "Authorization" header of the request.
    To see more details about the Authorization Header, please click here.

  • TemplateID(required)

    The SMS template ID is mapped with the argument template_id from the REST API.
    Your template ID follows a format that is validated using the regular expression ^[\da-fA-F]{8}-([\da-fA-F]{4}-){3}[\da-fA-F]{12}$.

    To find the template ID:

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

    The phone number of the recipient of the text message is mapped with the argument phone_number from the REST API. This can be a UK or international number.

  • SenderID(optional)

    A unique identifier of the sender of the text message notification that is mapped with the argument sms_sender_id from the REST API.

    To find the text message sender:

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


  • Reference(optional)

    An identifier you can create if necessary that is mapped with the argument reference from the REST API. This reference identifies a single notification or a batch of notifications. It must not contain any personal information such as name or postal address. 

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

  • Personalisation (optional)

    This is being mapped with the argument personalisation from the REST API.

    If a template has placeholder fields for personalised information such as name or reference number, you must provide their values in a dictionary with key-value pairs.

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

To use this integration you can create a server action wrapper, i.e. "SendSMSWrapper", that will call the service action "Send_SMS" from the GovUKNotify_IS module, passing the information required, and optional if needed, avoiding misbehaviour of this integration.

If your application needs to present the response on the screen, please check the following example or use this test page:


Send an email

An integration with the "postEmail" method of  GovUKNotifyAPIv2 is done through the service action "Send_Email" implemented in the GovUKNotify_IS module.

This service action includes all the flow needed to validate the required fields APIKey and TemplateID, through a "CheckRequest" server action wrapper, and checks if the EmailAddress is empty.

Additionally, the "Request" input parameter is converted to the required structure of the "postEmail" API method, and the integration response is converted to a local "Response" structure.


Below are presented the required and optional request fields for this integration and also its definitions:

  • APIKey(required)

    To get an API key, sign in to GOV.UK Notify and go to the API integration page.

    Your API key follows the format {key_name}-{iss-uuid}-{secret-key-uuid} that is validated using the regular expression ^\w+-([\da-fA-F]{8}-([\da-fA-F]{4}-){3}[\da-fA-F]{12}-?){2}$.

    The value of the API Key is then encoded to be sent in the "Authorization" header of the request.
    To see more details about the Authorization Header, please click here.

  • TemplateID(required)

    The email template ID is mapped with the argument template_id from the REST API.
    Your template ID follows a format that is validated using the regular expression ^[\da-fA-F]{8}-([\da-fA-F]{4}-){3}[\da-fA-F]{12}$.

    To find the template ID:

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

    The email address of the recipient is mapped with the argument email_address from the REST API. This can be a UK or international number.

  • EmailReplyToId(optional)

    This is an email address specified by you to receive replies from your users that is mapped with the argument email_reply_to_id from the REST API. You must add at least one reply-to email address before your service can go live.

    To add a reply-to email address:

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

    An identifier you can create if necessary that is mapped with the argument reference from the REST API. This reference identifies a single notification or a batch of notifications. It must not contain any personal information such as name or postal address. 

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

  • Personalisation(optional)

    This is being mapped with the argument personalisation from the REST API.

    If a template has placeholder fields for personalised information such as name or reference number, you must provide their values in a dictionary with key-value pairs.

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

To use this integration you can create a server action wrapper, i.e. "SendEmailWrapper", that will call the service action "Send_Email " from the GovUKNotify_IS module, passing the information required, and optional if needed, avoiding misbehaviour of this integration.

If your application needs to present the response on the screen, please check the following example or use this test page:

Send a file by email

An integration with the "postFileByEmail" method of  GovUKNotifyAPIv2 is done through the service action "Send_FileByEmail" implemented in the GovUKNotify_IS module.

This service action includes all the flow needed to validate the required fields APIKey and TemplateID, through a "CheckRequest" server action wrapper, and checks if the EmailAddress and Placeholder are empty, and the Content is an empty file.

Additionally, the "Request" input parameter is converted to the required structure of the "postFileByEmail" API method, and the integration response is converted to a local "Response" structure.

Below are presented the required and optional request fields for this integration and also its definitions.

  • APIKey(required)

    To get an API key, sign in to GOV.UK Notify and go to the API integration page.

    Your API key follows the format {key_name}-{iss-uuid}-{secret-key-uuid} that is validated using the regular expression ^\w+-([\da-fA-F]{8}-([\da-fA-F]{4}-){3}[\da-fA-F]{12}-?){2}$.

    The value of the API Key is then encoded to be sent in the "Authorization" header of the request.
    To see more details about the Authorization Header, please click here.

  • TemplateID(required)

    The email template ID is mapped with the argument template_id from the REST API.
    Your template ID follows a format that is validated using the regular expression ^[\da-fA-F]{8}-([\da-fA-F]{4}-){3}[\da-fA-F]{12}$.

    To find the template ID:

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

    The email address of the recipient is mapped with the argument email_address from the REST API. This can be a UK or international number.

  • EmailReplyToId(optional)

    This is an email address specified by you to receive replies from your users that is mapped with the argument email_reply_to_id from the REST API. You must add at least one reply-to email address before your service can go live.

    To add a reply-to email address:

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

  • Reference(optional)

    An identifier you can create if necessary that is mapped with the argument reference from the REST API. This reference identifies a single notification or a batch of notifications. It must not contain any personal information such as name or postal address. 

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

  • FileToSend(required)

    Structure with attributes related to the file to send that will be converted to a JSON string and to be added as pair key-value in the Personalisation

    • Placeholder: Must match a placeholder in the template that will contain a secure link to download the file. For example, "link_to_file"
    • Content: The binary content of the file to download that must be smaller than 2MB. This content will be converted to a base64 encoded string before being sent.

      You can upload the following file types:
      • PDF (.pdf)
      • CSV (.csv)
      • Text (.odt, .txt, .rtf, .json)
      • MS Word Document (.doc, .docx)
      • Ms Excel Spreadsheet (.xlsx)
    • IsCSV: Uploads for CSV files should set this flag as true to ensure it’s downloaded as a .csv file.
    • RequireVerification: Set this flag as true to ensure the recipients will confirm the email address before they can download the file.

      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
    • AvailableWeeks: Set the number of weeks you want the file to be available.
      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
  • Personalisation(optional)

    This is being mapped with the argument personalisation from the REST API.

    If a template has placeholder fields for personalised information such as name or reference number, you must provide their values in a dictionary with key-value pairs.

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

To use this integration you can create a server action wrapper, i.e. "SendFileByEmailWrapper", that will call the service action "Send_FileByEmail" from the GovUKNotify_IS module, passing the information required, and optional if needed, avoiding misbehaviour of this integration.

If your application needs to present the response on the screen, please check the following example or use this test page:

Send a letter

An integration with the "postLetter" method of  GovUKNotifyAPIv2 is done through the service action "Send_Letter" implemented in the GovUKNotify_IS module.

This service action includes all the flow needed to validate the required fields APIKey and TemplateID, through a "CheckRequest" server action wrapper.

Additionally, the "Request" input parameter is converted to the required structure of the "postFileByEmail" API method, and the integration response is converted to a local "Response" structure.


Below are presented the required and optional request fields for this integration and also its definitions:

  • APIKey (required)

    To get an API key, sign in to GOV.UK Notify and go to the API integration page.

    Your API key follows the format {key_name}-{iss-uuid}-{secret-key-uuid} that is validated using the regular expression ^\w+-([\da-fA-F]{8}-([\da-fA-F]{4}-){3}[\da-fA-F]{12}-?){2}$.

    The value of the API Key is then encoded to be sent in the "Authorization" header of the request.
    To see more details about the Authorization Header, please click here.

  • TemplateID (required)

    The letter template ID is mapped with the argument template_id from the REST API.
    Your template ID follows a format that is validated using the regular expression ^[\da-fA-F]{8}-([\da-fA-F]{4}-){3}[\da-fA-F]{12}$.

    To find the template ID:

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

    An identifier you can create if necessary that is mapped with the argument reference from the REST API. This reference identifies a single notification or a batch of notifications. It must not contain any personal information such as name or postal address. 

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

  • AddressLines (required)

    Structure with attributes related to the recipient's address that will be transformed into pairs of key-value in the Personalisation

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

  • Personalisation(optional)

    This is being mapped with the argument personalisation from the REST API.

    If a template has placeholder fields different from AddressLines, you must provide their values in a dictionary with key-value pairs.

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

To use this integration you can create a server action wrapper, i.e. "SendLetterWrapper", that will call the service action "Send_Letter" from the GovUKNotify_IS module, passing the information required, and optional if needed, avoiding misbehaviour of this integration.


If your application needs to present the response on the screen, please check the following example or use this test page:


Send a precompiled letter

An integration with the "postPrecompiledLetter" method of  GovUKNotifyAPIv2 is done through the service action "Send_PrecompiledLetter" implemented in the GovUKNotify_IS module.

This service action includes all the flow needed to validate the required field APIKey, through a "CheckRequest" server action wrapper, and checks if the Reference is empty, and the Content is an empty file.

Additionally, the "Request" input parameter is converted to the required structure of the "postPrecompiledLetter" API method, and the integration response is converted to a local "Response" structure.

Below are presented the required and optional request fields for this integration and also its definitions.

  • APIKey(required)

    To get an API key, sign in to GOV.UK Notify and go to the API integration page.

    Your API key follows the format {key_name}-{iss-uuid}-{secret-key-uuid} that is validated using the regular expression ^\w+-([\da-fA-F]{8}-([\da-fA-F]{4}-){3}[\da-fA-F]{12}-?){2}$.

    The value of the API Key is then encoded to be sent in the "Authorization" header of the request.
    To see more details about the Authorization Header, please click here.

  • Reference(required)

    An identifier you can create if necessary that is mapped with the argument reference from the REST API. This reference identifies a single notification or a batch of notifications. It must not contain any personal information such as name or postal address. 

  • Content(required)

    The precompiled letter must be a PDF file which meets the GOV.UK Notify letter specification that is mapped with the argument content from the REST API. This content will be converted to a base64 encoded string before being sent.

  • Postage(optional)

    This is being mapped with the argument postage.

    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 this argument, the postage will default to second class.

To use this integration you can create a server action wrapper, i.e. "SendPrecompiledLetterWrapper", that will call the service action "Send_PrecompiledLetter" from the GovUKNotify_IS module, passing the information required, and optional if needed, avoiding misbehaviour of this integration.


If your application needs to present the response on the screen, please check the following example or use this test page:


Get message status

Get the status of one message

An integration with the "getNotification" method of  GovUKNotifyAPIv2 is done through the service action "Get_Notification" implemented in the GovUKNotify_IS module.

This service action includes all the flow needed to validate the required field APIKey, through a "CheckRequest" server action wrapper, and checks if the NotificationId is empty.

Additionally, the "Request" input parameter is converted to the required structure of the "getNotification" API method, and the integration response is converted to a local "Response" structure.

Below are presented the required and optional request fields for this integration and also its definitions:

  • APIKey(required)

    To get an API key, sign in to GOV.UK Notify and go to the API integration page.

    Your API key follows the format {key_name}-{iss-uuid}-{secret-key-uuid} that is validated using the regular expression ^\w+-([\da-fA-F]{8}-([\da-fA-F]{4}-){3}[\da-fA-F]{12}-?){2}$.

    The value of the API Key is then encoded to be sent in the "Authorization" header of the request.
    To see more details about the Authorization Header, please click here.

  • NotificationId(required)

    The ID of the notification that is mapped with the argument notification_id from the REST API. You can find the notification ID in the response to the original notification method call.

To use this integration you can create a server action wrapper, i.e. "GetNotificationWrapper", that will call the service action "Get_Notification" from the GovUKNotify_IS module, passing the information required, and optional if needed, avoiding misbehaviour of this integration.

If your application needs to present the response on the screen, please check the following example or use this test page:

  • Text message

  • Email

  • File by email

  • Letter

  • Precompiled letter



Get the status of multiple messages

An integration with the "getNotifications" method of  GovUKNotifyAPIv2 is done through the service action "Get_Notifications" implemented in the GovUKNotify_IS module.

This API call returns one page of up to 250 messages and statuses. You can get either the most recent messages or older messages by specifying a particular notification ID in the OlderThan argument.


This service action includes all the flow needed to validate the required field APIKey through a "CheckRequest" server action wrapper.

Additionally, the "Request" input parameter is converted to the required structure of the "getNotifications" API method, and the integration response is converted to a local "Response" structure.

Below are presented the required and optional request fields for this integration and also its definitions:

  • APIKey(required)

    To get an API key, sign in to GOV.UK Notify and go to the API integration page.

    Your API key follows the format {key_name}-{iss-uuid}-{secret-key-uuid} that is validated using the regular expression ^\w+-([\da-fA-F]{8}-([\da-fA-F]{4}-){3}[\da-fA-F]{12}-?){2}$.

    The value of the API Key is then encoded to be sent in the "Authorization" header of the request.
    To see more details about the Authorization Header, please click here.

  • TemplateType(optional)

    This is being mapped with the argument template_type.

    You can leave out this argument to ignore this filter.

    You can filter by:

    • email
    • sms
    • letter
  • Status(optional)

    This is being mapped with the argument status.

    You can leave out this argument to ignore this filter.

    You can filter by:

  • Reference(optional)

    An identifier you can create if necessary that is mapped with the argument reference from the REST API. This reference identifies a single notification or a batch of notifications. It must not contain any personal information such as name or postal address. 

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

  • OlderThan(optional)

    Input the ID of a notification, i.e. 740e5834-3a29-46b4-9a6f-16142fde533a, into this argument that is mapped with the argument older_than from the REST API. If you use this argument, the method returns the next 250 received notifications older than the given ID

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

    The client only returns notifications that are 7 days old or newer. If the notification specified in this argument is older than 7 days, the client returns an empty response.

To use this integration you can create a server action wrapper, i.e. "GetNotificationsWrapper", that will call the service action "Get_Notifications" from the GovUKNotify_IS module, passing the information required, and optional if needed, avoiding misbehaviour of this integration.If your application needs to present the response on the screen, please check the following example or use this test page:

  • Get all messages

  • Get messages by template type

  • Get messages by status

  • Get messages by reference

  • Get messages from older than

As the above examples don't have all fields from the response, please check the expected full response from the API here.


Get a PDF for a letter

An integration with the "getLetterPDF" method of  GovUKNotifyAPIv2 is done through the service action "Get_LetterPDF" implemented in the GovUKNotify_IS module.

This API returns the PDF contents of a letter.

This service action includes all the flow needed to validate the required field APIKey, through a "CheckRequest" server action wrapper, and checks if the NotificationId is empty.

Additionally, the "Request" input parameter is converted to the required structure of the "getLetterPDF" API method, and the integration response is converted to a local "Response" structure.

Below are presented the required and optional request fields for this integration and also its definitions:

  • APIKey(required)

    To get an API key, sign in to GOV.UK Notify and go to the API integration page.

    Your API key follows the format {key_name}-{iss-uuid}-{secret-key-uuid} that is validated using the regular expression ^\w+-([\da-fA-F]{8}-([\da-fA-F]{4}-){3}[\da-fA-F]{12}-?){2}$.

    The value of the API Key is then encoded to be sent in the "Authorization" header of the request.
    To see more details about the Authorization Header, please click here.

  • NotificationId(required)

    The ID of the notification that is mapped with the argument notification_id from the REST API. You can find the notification ID in the response to the original notification method call.

To use this integration you can create a server action wrapper, i.e. "GetLetterPDFWrapper", that will call the service action "Get_LetterPDF" from the GovUKNotify_IS module, passing the information required, and optional if needed, avoiding misbehaviour of this integration.

If your application needs to provide the ability to download the PDF on the screen, please check the following examples or use this test page:


Get a template

Get a template by ID

An integration with the "getTemplate" method of  GovUKNotifyAPIv2 is done through the service action "Get_TemplateById" implemented in the GovUKNotify_IS module.

This returns the latest version of the template.

This service action includes all the flow needed to validate the required fields APIKey and TemplateID, through a "CheckRequest" server action wrapper.

Additionally, the "Request" input parameter is converted to the required structure of the "getTemplate" API method, and the integration response is converted to a local "Response" structure.

Below are presented the required and optional request fields for this integration and also its definitions:

  • APIKey (required)

    To get an API key, sign in to GOV.UK Notify and go to the API integration page.

    Your API key follows the format {key_name}-{iss-uuid}-{secret-key-uuid} that is validated using the regular expression ^\w+-([\da-fA-F]{8}-([\da-fA-F]{4}-){3}[\da-fA-F]{12}-?){2}$.

    The value of the API Key is then encoded to be sent in the "Authorization" header of the request.
    To see more details about the Authorization Header, please click here.

  • TemplateID (required)

    The ID of the template that is mapped with the argument template_id from the REST API.
    Your template ID follows a format that is validated using the regular expression ^[\da-fA-F]{8}-([\da-fA-F]{4}-){3}[\da-fA-F]{12}$.

    To find the template ID:

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


To use this integration you can create a server action wrapper, i.e. "GetTemplateWrapper", that will call the service action "Get_TemplateById" from the GovUKNotify_IS module, passing the information required, and optional if needed, avoiding misbehaviour of this integration.

If your application needs to present the response on the screen, please check the following example or use this test page:

Get a template by ID and version

An integration with the "getTemplateByVersion" method of  GovUKNotifyAPIv2 is done through the service action "Get_TemplateByIdAndVersion" implemented in the GovUKNotify_IS module.

This returns the version of the template.

This service action includes all the flow needed to validate the required fields APIKey and TemplateID, through a "CheckRequest" server action wrapper, and checks if the Version is greater than 0.

Additionally, the "Request" input parameter is converted to the required structure of the "getTemplateByVersion" API method, and the integration response is converted to a local "Response" structure.

Below are presented the required and optional request fields for this integration and also its definitions:

  • APIKey(required)

    To get an API key, sign in to GOV.UK Notify and go to the API integration page.

    Your API key follows the format {key_name}-{iss-uuid}-{secret-key-uuid} that is validated using the regular expression ^\w+-([\da-fA-F]{8}-([\da-fA-F]{4}-){3}[\da-fA-F]{12}-?){2}$.

    The value of the API Key is then encoded to be sent in the "Authorization" header of the request.
    To see more details about the Authorization Header, please click here.

  • TemplateID(required)

    The ID of the template that is mapped with the argument template_id from the REST API.
    Your template ID follows a format that is validated using the regular expression ^[\da-fA-F]{8}-([\da-fA-F]{4}-){3}[\da-fA-F]{12}$.

    To find the template ID:

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

    The version number of the template that is mapped with the argument version.

To use this integration you can create a server action wrapper, i.e. "GetTemplateByVersionWrapper", that will call the service action "Get_TemplateByIdAndVersion" from the GovUKNotify_IS module, passing the information required, and optional if needed, avoiding misbehaviour of this integration.

If your application needs to present the response on the screen, please check the following example or use this test page:

  • Empty version

  • Invalid version

  • Success



Get all templates

An integration with the "getTemplates" method of  GovUKNotifyAPIv2 is done through the service action "Get_Templates" implemented in the GovUKNotify_IS module.

This returns the latest version of all templates.

This service action includes all the flow needed to validate the required field APIKey, through a "CheckRequest" server action wrapper.

Additionally, the "Request" input parameter is converted to the required structure of the "templates" API method, and the integration response is converted to a local "Response" structure.

Below are presented the required and optional request fields for this integration and also its definitions:

  • APIKey(required)

    To get an API key, sign in to GOV.UK Notify and go to the API integration page.

    Your API key follows the format {key_name}-{iss-uuid}-{secret-key-uuid} that is validated using the regular expression ^\w+-([\da-fA-F]{8}-([\da-fA-F]{4}-){3}[\da-fA-F]{12}-?){2}$.

    The value of the API Key is then encoded to be sent in the "Authorization" header of the request.
    To see more details about the Authorization Header, please click here.

  • TemplateType(optional)

    This is being mapped with the argument type.

    If you leave out this argument, the method returns all templates.

    You can filter by:

    • email
    • sms
    • letter


To use this integration you can create a server action wrapper, i.e. "GetTemplatesWrapper", that will call the service action "Get_Templates" from the GovUKNotify_IS module, passing the information required, and optional if needed, avoiding misbehaviour of this integration.

If your application needs to present the response on the screen, please check the following example or use this test page:

  • Get all templates

  • Get email templates

  • Get SMS templates

  • Get letter templates

    Generate a preview template

    An integration with the "postTemplatePreview" method of  GovUKNotifyAPIv2 is done through the service action "Get_TemplatePreview" implemented in the GovUKNotify_IS module.

    This generates a preview version of a template.

    This service action includes all the flow needed to validate the required fields APIKey and TemplateID, through a "CheckRequest" server action wrapper.

    Additionally, the "Request" input parameter is converted to the required structure of the "postTemplatePreview" API method, and the integration response is converted to a local "Response" structure.

    Below are presented the required and optional request fields for this integration and also its definitions:

    • APIKey(required)

      To get an API key, sign in to GOV.UK Notify and go to the API integration page.

      Your API key follows the format {key_name}-{iss-uuid}-{secret-key-uuid} that is validated using the regular expression ^\w+-([\da-fA-F]{8}-([\da-fA-F]{4}-){3}[\da-fA-F]{12}-?){2}$.

      The value of the API Key is then encoded to be sent in the "Authorization" header of the request.
      To see more details about the Authorization Header, please click here.

    • TemplateID(required)

      The ID of the template that is mapped with the argument template_id from the REST API.
      Your template ID follows a format that is validated using the regular expression ^[\da-fA-F]{8}-([\da-fA-F]{4}-){3}[\da-fA-F]{12}$.

      To find the template ID:

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

      This is being mapped with the argument personalisation from the REST API.

      If a template has placeholder fields for personalised information such as name or reference number, you must provide their values in a dictionary with key-value pairs.

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

  • To use this integration you can create a server action wrapper, i.e. "GetTemplatePreviewWrapper", that will call the service action "Get_TemplatePreview" from the GovUKNotify_IS module, passing the information required, and optional if needed, avoiding misbehaviour of this integration.

    If your application needs to present the response on the screen, please check the following example or use this test page:


Get received text messages

Get received text messages

An integration with the "getReceivedSMS" method of GovUKNotifyAPIv2 is done through the service action "Get_ReceivedSMS" implemented in the GovUKNotify_IS module.

This service action includes all the flow needed to validate the required field APIKey through a "CheckRequest" server action wrapper.

Additionally, the "Request" input parameter is converted to the required structure of the "getReceivedSMS" API method, and the integration response is converted to a local "Response" structure.

Below are presented the required and optional request fields for this integration and also its definitions:

  • APIKey(required)

    To get an API key, sign in to GOV.UK Notify and go to the API integration page.

    Your API key follows the format {key_name}-{iss-uuid}-{secret-key-uuid} that is validated using the regular expression ^\w+-([\da-fA-F]{8}-([\da-fA-F]{4}-){3}[\da-fA-F]{12}-?){2}$.

    The value of the API Key is then encoded to be sent in the "Authorization" header of the request.
    To see more details about the Authorization Header, please click here.

  • OlderThan(optional)

    The ID of a received text message, i.e. 740e5834-3a29-46b4-9a6f-16142fde533a, into this argument that is mapped with the argument older_than from the REST API. If this is passed, the response will only list text messages received before that message. 

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

    The client only returns messages that are 7 days old or newer. If the message specified in this argument is older than 7 days, the client returns an empty response.

To use this integration you can create a server action wrapper, i.e. "GetReceivedSMSWrapper", that will call the service action "Get_ReceivedSMS" from the GovUKNotify_IS module, passing the information required, and optional if needed, avoiding misbehaviour of this integration.

If your application needs to present the response on the screen, please check the following example or use this test page:


Callbacks

Authorization

The callback authorization is checked in the "OnAuthentication" event of each callback exposed REST API by validating the bearer token sent through the "Authorization" HTTP Request header. In the "OnAuthentication" is called a server action wrapper "ValidateCallbackAuthorization" that will validate the bearer token for the authorization.This is a wrapper to the "ReadTokenService" JWT integration which decodes and validates a signed token.

Besides the "EncodedToken", which is obtained through the "Authorization" HTTP Request header, the remaining parameters values are identified in the following site properties, which value must be set using the Service Center:

  • VerifySignature: Indicates if the token's signature should be verified, based on the signature info passed as parameters. 
  • SignatureKey: Key used to verify the token, needed only if VerifySignature is selected.
  • ExpectedSignatureKeyId: Expected ID to the key that was used for signing the token. Needed only if VerifySignature is selected, if empty the signature will still be validated but the key IDs.
  • VerifyLifetime: Indicates if the token has expired.
  • VerifyIssuer: Indicates the audience should be validated, based on an issuer as a parameter.
  • ExpectedIssuer: Expected issuer to be validated in the token.
  • VerifyAudience: Indicates the audience should be validated, based on an issuer as a parameter.
  • ExpectedAudience: Expected audience to be validated in the token.

If the encoded token is valid, the callback request is accepted. Otherwise, a 403 "Invalid token" exception is retrieved.


Delivery receipts

An exposed REST API method "postUpdateStatus" is available through the endpoint DeliveryReceiptCallback whose main goal is to update a notification status through the received request.This callback API only should be used/set up through GOV.UK Notify if you are using the service actions available in the GovUKNotify_CS to store the request/response of the email, SMS and letter sent.

Below are presented the request fields for this API and its definitions:

  • Id

    Notify’s ID for the status receipts.
    Format: UUID

  • To

    The email address or phone number of the recipient.
    Format: hello@gov.uk or 07700912345

  • Reference

    The reference was sent by the service. This reference identifies a single notification or a batch of notifications.
    Format: 12345678 or null

  • Status

    The status of the notification.
    Format: delivered, permanent-failure, temporary-failure or technical-failure

  • CreatedAt

    The time the service sent the request.
    Format: 2017-05-14T12:15:30.000000Z

  • CompletedAt

    The last time the status was updated.
    Format: 2017-05-14T12:15:30.000000Z or null

  • SentAt

    The time the notification was sent.
    Format: 2017-05-14T12:15:30.000000Z or null

  • NotificationType

    The notification type.
    Format: email or SMS

  • TemplateId

    The id of the template that was used.
    Format: UUID

  • TemplateVersion

    The version number of the template that was used.
    Format: 1

 

This API receives a request that will be serialized to JSON and its binary is stored as a record in NotificationToProcess database entity. If the request is successful, the status code of the response is 200.

If you don't want to process the request, a site property DisableUpdateStatus is available whose value "true" allows you to send the status code 200 in the response without the request having been sent for processing.

Being exposed to process events, when a record is created in the NotificationToProcess database entity, a light process execution activity UpdateNotificationActivity is automatically triggered.


Process activity

Before processing the notification status update begins, it's validated that the record exists in the NotificationToProcess entity and its request content is not empty. If any of the sentences fail, the process ends. 

Once a binary request is obtained from the NotificationToProcess entity, it's converted to JSON so that it can be deserialized into the correct structure and sent to the  "ProcessingUpdateNotificationActivity" wrapper so that it can be processed.


Processing update notification activity

This wrapper verifies if the notification to process is not processed yet, using the service action "GetNotificationNotProcessed" of the GovUKNotify_CS module (i.e. if the notification status is empty, created or sending). 

If the notification is not processed yet, its status is updated using the "UpdateNotificationStatus" service action of the GovUKNotify_CS module. However, before that, if the Gov.UK Notify ID of the notification being processed is not stored, it is updated using the "UpdateGovUkNotificationId" service action from the same module. 


Received text messages

If your service receives text messages in Notify, Notify can forward them to your callback URL as soon as they arrive.

Contact the Notify team using the support page or chat with us on Slack to request a unique number for text message replies.

An exposed REST API method "postReceiveSMS" is available through the endpoint ReceiveSMSCallback if you want to store received text messages (SMS) sent by users using your service. 


Below are presented the request fields for this API and its definitions:

  • Id

    Notify’s ID for the received message.
    Format: UUID

  • SourceNumber

    The phone number the message was sent from.
    Format: 07700912345

  • DestinationNumber

    The number the message was sent to (your number).
    Format: 07700987654

  • Message

    The received message.
    Format: Hello Notify!

  • DateReceived

    The UTC datetime that the message was received by Notify.
    Format: 2017-05-14T12:15:30.000000Z

This API receives a request that is saved locally using the service action "SaveSMS" of the GovUKNotify_CS module. If the request is successful, the status code of the response is 200.

If you don't want to process the request, a site property DisableReceiveSMS is available whose value "true" allows you to send the status code 200 in the response without the request having been saved locally.

To get the received text messages saved locally, a service action "GetSMS" of the GovUKNotify_CS module is provided for this purpose.




To get multiple notifications, or a single notification, saved locally, the service actions "GetNotifications" and "GetNotificationById" of the GovUKNotify_CS module are provided for this purpose.



1.0.1

To start to use this component, please install the "GOV UK Notify Service" application in your factory.

It's provided an integration to send text messages, emails (with or without a file), letters and precompiled letters. Additionally, you can verify the status of a single message or multiple messages, as well as get the details of a single template or multiple templates.

The authentication/authorization of each request is made by converting the API key of your service account into JSON Web Token (JWT) of JWT the forge component. The outcome is then added to the HTTP request "Authorization" header.


Authorization

Authorization header

JSON Web Tokens (JWT) are encoded using a secret key with the format of 3d844edf-8d35-48ac-975b-e847b4f122b0.

That secret key forms a part of your API key, which follows the format {key_name}-{iss-uuid}-{secret-key-uuid}.

For example, if your API key is my_test_key-26785a09-ab16-4eb0-8407-a37497a57506-3d844edf-8d35-48ac-975b-e847b4f122b0:

  • your API key name is my_test_key
  • your iss (your service id) is 26785a09-ab16-4eb0-8407-a37497a57506
  • your secret key is 3d844edf-8d35-48ac-975b-e847b4f122b0

iat (issued at) is the current time in UTC in epoch seconds. The token expires within 30 seconds of the current time.

Refer to the JSON Web Tokens website for more information on encoding your authorisation header.

When you have an encoded and signed token, add that token to a header as follows:

"Authorization": "Bearer encoded_jwt_token".


Implementation

In the "OnBeforeRequest" of GovUKNotifyAPIv2 consumed REST API is called a server action wrapper "OnBeforeRequest_GovUKNotifyAPI".

This wrapper manipulates the HTTP Request before it is sent, and one of the actions taken into consideration is a wrapper "GenerateTokenFromHTTPHeaderAPIKey". The main goal of this wrapper is to gather the API Key from the header request and with it to generate a JWT bearer token to be appended and defined as a value of the "Authorization" HTTP request header.

The "GenerateTokenFromHTTPHeaderAPIKey" server action receives as an input parameter a list of all HTTP Request Headers and returns the encoded token. From the Headers parameter will be extracted the API Key that was originally sent. For this extraction, we are using a private server action (GetAPIKeyFromHeaders) that filters the Headers list by a specific header name.  

After obtaining the API Key, it is used as an input parameter for a new wrapper (GenerateJWT) that will be used to generate the final encoded token.
To keep the token's lifetime short, no value is defined in the "Expires" parameter, meaning the token must be used within 30 seconds after its generation.

Inside the "GenerateJWT" wrapper, a local action "SplitAPIKey" is invoked which, after validating whether the API Key matches the intended format, returns: Name, Service Id and Secret Key (as indicated in the "Authorization Header" section).

For the proper generation of the JWT token, it is used the Service Id as the IssuerHS256 as the Algorithm, and the Secret Key as the Key and KeyId. If the encoded token is generated successfully, its value is returned. To know a little bit more about how to use the service below, please click here.

Finally, after the encoded token has been generated, it is added to the "Authorization" header of the HTTP request, such as the "Content-Type" header as "application/json".


Send a message

Send a text message

An Integration with the "postSMS" method of  GovUKNotifyAPIv2 is done through the service action "Send_SMS" implemented in the GovUKNotify_IS module.

This service action includes all the flow needed to validate the required fields APIKey and TemplateID, through a "CheckRequest" server action wrapper, and checks if the MobileNumber is empty.

Additionally, the "Request" input parameter is converted to the required structure of the "postSMS" API method, and the integration response is converted to a local "Response" structure.

Below are presented the required and optional request fields for this integration and also its definitions:

  • APIKey(required)

    To get an API key, sign in to GOV.UK Notify and go to the API integration page.

    Your API key follows the format {key_name}-{iss-uuid}-{secret-key-uuid} that is validated using the regular expression ^\w+-([\da-fA-F]{8}-([\da-fA-F]{4}-){3}[\da-fA-F]{12}-?){2}$.

    The value of the API Key is then encoded to be sent in the "Authorization" header of the request.
    To see more details about the Authorization Header, please click here.

  • TemplateID(required)

    The SMS template ID is mapped with the argument template_id from the REST API.
    Your template ID follows a format that is validated using the regular expression ^[\da-fA-F]{8}-([\da-fA-F]{4}-){3}[\da-fA-F]{12}$.

    To find the template ID:

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

    The phone number of the recipient of the text message is mapped with the argument phone_number from the REST API. This can be a UK or international number.

  • SenderID(optional)

    A unique identifier of the sender of the text message notification that is mapped with the argument sms_sender_id from the REST API.

    To find the text message sender:

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


  • Reference(optional)

    An identifier you can create if necessary that is mapped with the argument reference from the REST API. This reference identifies a single notification or a batch of notifications. It must not contain any personal information such as name or postal address. 

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

  • Personalisation (optional)

    This is being mapped with the argument personalisation from the REST API.

    If a template has placeholder fields for personalised information such as name or reference number, you must provide their values in a dictionary with key-value pairs.

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

To use this integration you can create a server action wrapper, i.e. "SendSMSWrapper", that will call the service action "Send_SMS" from the GovUKNotify_IS module, passing the information required, and optional if needed, avoiding misbehaviour of this integration. 

If your application needs to present the response on the screen, please check the following example or use this test page


Send an email

An integration with the "postEmail" method of  GovUKNotifyAPIv2 is done through the service action "Send_Email" implemented in the GovUKNotify_IS module.

This service action includes all the flow needed to validate the required fields APIKey and TemplateID, through a "CheckRequest" server action wrapper, and checks if the EmailAddress is empty.

Additionally, the "Request" input parameter is converted to the required structure of the "postEmail" API method, and the integration response is converted to a local "Response" structure.


Below are presented the required and optional request fields for this integration and also its definitions:

  • APIKey(required)

    To get an API key, sign in to GOV.UK Notify and go to the API integration page.

    Your API key follows the format {key_name}-{iss-uuid}-{secret-key-uuid} that is validated using the regular expression ^\w+-([\da-fA-F]{8}-([\da-fA-F]{4}-){3}[\da-fA-F]{12}-?){2}$.

    The value of the API Key is then encoded to be sent in the "Authorization" header of the request.
    To see more details about the Authorization Header, please click here.

  • TemplateID(required)

    The email template ID is mapped with the argument template_id from the REST API.
    Your template ID follows a format that is validated using the regular expression ^[\da-fA-F]{8}-([\da-fA-F]{4}-){3}[\da-fA-F]{12}$.

    To find the template ID:

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

    The email address of the recipient is mapped with the argument email_address from the REST API. This can be a UK or international number.

  • EmailReplyToId(optional)

    This is an email address specified by you to receive replies from your users that is mapped with the argument email_reply_to_id from the REST API. You must add at least one reply-to email address before your service can go live.

    To add a reply-to email address:

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

    An identifier you can create if necessary that is mapped with the argument reference from the REST API. This reference identifies a single notification or a batch of notifications. It must not contain any personal information such as name or postal address. 

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

  • Personalisation(optional)

    This is being mapped with the argument personalisation from the REST API.

    If a template has placeholder fields for personalised information such as name or reference number, you must provide their values in a dictionary with key-value pairs.

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

To use this integration you can create a server action wrapper, i.e. "SendEmailWrapper", that will call the service action "Send_Email " from the GovUKNotify_IS module, passing the information required, and optional if needed, avoiding misbehaviour of this integration.

If your application needs to present the response on the screen, please check the following example or use this test page:

Send a file by email

An integration with the "postFileByEmail" method of  GovUKNotifyAPIv2 is done through the service action "Send_FileByEmail" implemented in the GovUKNotify_IS module.

This service action includes all the flow needed to validate the required fields APIKey and TemplateID, through a "CheckRequest" server action wrapper, and checks if the EmailAddress and Placeholder are empty, and the Content is an empty file.

Additionally, the "Request" input parameter is converted to the required structure of the "postFileByEmail" API method, and the integration response is converted to a local "Response" structure.

Below are presented the required and optional request fields for this integration and also its definitions.

  • APIKey(required)

    To get an API key, sign in to GOV.UK Notify and go to the API integration page.

    Your API key follows the format {key_name}-{iss-uuid}-{secret-key-uuid} that is validated using the regular expression ^\w+-([\da-fA-F]{8}-([\da-fA-F]{4}-){3}[\da-fA-F]{12}-?){2}$.

    The value of the API Key is then encoded to be sent in the "Authorization" header of the request.
    To see more details about the Authorization Header, please click here.

  • TemplateID(required)

    The email template ID is mapped with the argument template_id from the REST API.
    Your template ID follows a format that is validated using the regular expression ^[\da-fA-F]{8}-([\da-fA-F]{4}-){3}[\da-fA-F]{12}$.

    To find the template ID:

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

    The email address of the recipient is mapped with the argument email_address from the REST API. This can be a UK or international number.

  • EmailReplyToId(optional)

    This is an email address specified by you to receive replies from your users that is mapped with the argument email_reply_to_id from the REST API. You must add at least one reply-to email address before your service can go live.

    To add a reply-to email address:

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

  • Reference(optional)

    An identifier you can create if necessary that is mapped with the argument reference from the REST API. This reference identifies a single notification or a batch of notifications. It must not contain any personal information such as name or postal address. 

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

  • FileToSend(required)

    Structure with attributes related to the file to send that will be converted to a JSON string and to be added as pair key-value in the Personalisation

    • Placeholder: Must match a placeholder in the template that will contain a secure link to download the file. For example, "link_to_file"
    • Content: The binary content of the file to download that must be smaller than 2MB. This content will be converted to a base64 encoded string before being sent.

      You can upload the following file types:
      • PDF (.pdf)
      • CSV (.csv)
      • Text (.odt, .txt, .rtf, .json)
      • MS Word Document (.doc, .docx)
      • Ms Excel Spreadsheet (.xlsx)
    • IsCSV: Uploads for CSV files should set this flag as true to ensure it’s downloaded as a .csv file.
    • RequireVerification: Set this flag as true to ensure the recipients will confirm the email address before they can download the file.

      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
    • AvailableWeeks: Set the number of weeks you want the file to be available.
      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
  • Personalisation(optional)

    This is being mapped with the argument personalisation from the REST API.

    If a template has placeholder fields for personalised information such as name or reference number, you must provide their values in a dictionary with key-value pairs.

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

To use this integration you can create a server action wrapper, i.e. "SendFileByEmailWrapper", that will call the service action "Send_FileByEmail" from the GovUKNotify_IS module, passing the information required, and optional if needed, avoiding misbehaviour of this integration.

If your application needs to present the response on the screen, please check the following example or use this test page:

Send a letter

An integration with the "postLetter" method of  GovUKNotifyAPIv2 is done through the service action "Send_Letter" implemented in the GovUKNotify_IS module.

This service action includes all the flow needed to validate the required fields APIKey and TemplateID, through a "CheckRequest" server action wrapper.

Additionally, the "Request" input parameter is converted to the required structure of the "postFileByEmail" API method, and the integration response is converted to a local "Response" structure.


Below are presented the required and optional request fields for this integration and also its definitions:

  • APIKey (required)

    To get an API key, sign in to GOV.UK Notify and go to the API integration page.

    Your API key follows the format {key_name}-{iss-uuid}-{secret-key-uuid} that is validated using the regular expression ^\w+-([\da-fA-F]{8}-([\da-fA-F]{4}-){3}[\da-fA-F]{12}-?){2}$.

    The value of the API Key is then encoded to be sent in the "Authorization" header of the request.
    To see more details about the Authorization Header, please click here.

  • TemplateID (required)

    The letter template ID is mapped with the argument template_id from the REST API.
    Your template ID follows a format that is validated using the regular expression ^[\da-fA-F]{8}-([\da-fA-F]{4}-){3}[\da-fA-F]{12}$.

    To find the template ID:

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

    An identifier you can create if necessary that is mapped with the argument reference from the REST API. This reference identifies a single notification or a batch of notifications. It must not contain any personal information such as name or postal address. 

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

  • AddressLines (required)

    Structure with attributes related to the recipient's address that will be transformed into pairs of key-value in the Personalisation

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

  • Personalisation(optional)

    This is being mapped with the argument personalisation from the REST API.

    If a template has placeholder fields different from AddressLines, you must provide their values in a dictionary with key-value pairs.

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

To use this integration you can create a server action wrapper, i.e. "SendLetterWrapper", that will call the service action "Send_Letter" from the GovUKNotify_IS module, passing the information required, and optional if needed, avoiding misbehaviour of this integration.


If your application needs to present the response on the screen, please check the following example or use this test page:


Send a precompiled letter

An integration with the "postPrecompiledLetter" method of  GovUKNotifyAPIv2 is done through the service action "Send_PrecompiledLetter" implemented in the GovUKNotify_IS module.

This service action includes all the flow needed to validate the required field APIKey, through a "CheckRequest" server action wrapper, and checks if the Reference is empty, and the Content is an empty file.

Additionally, the "Request" input parameter is converted to the required structure of the "postPrecompiledLetter" API method, and the integration response is converted to a local "Response" structure.

Below are presented the required and optional request fields for this integration and also its definitions.

  • APIKey(required)

    To get an API key, sign in to GOV.UK Notify and go to the API integration page.

    Your API key follows the format {key_name}-{iss-uuid}-{secret-key-uuid} that is validated using the regular expression ^\w+-([\da-fA-F]{8}-([\da-fA-F]{4}-){3}[\da-fA-F]{12}-?){2}$.

    The value of the API Key is then encoded to be sent in the "Authorization" header of the request.
    To see more details about the Authorization Header, please click here.

  • Reference(required)

    An identifier you can create if necessary that is mapped with the argument reference from the REST API. This reference identifies a single notification or a batch of notifications. It must not contain any personal information such as name or postal address. 

  • Content(required)

    The precompiled letter must be a PDF file which meets the GOV.UK Notify letter specification that is mapped with the argument content from the REST API. This content will be converted to a base64 encoded string before being sent.

  • Postage(optional)

    This is being mapped with the argument postage.

    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 this argument, the postage will default to second class.

To use this integration you can create a server action wrapper, i.e. "SendPrecompiledLetterWrapper", that will call the service action "Send_PrecompiledLetter" from the GovUKNotify_IS module, passing the information required, and optional if needed, avoiding misbehaviour of this integration.


If your application needs to present the response on the screen, please check the following example or use this test page:


Get message status

Get the status of one message

An integration with the "getNotification" method of  GovUKNotifyAPIv2 is done through the service action "Get_Notification" implemented in the GovUKNotify_IS module.

This service action includes all the flow needed to validate the required field APIKey, through a "CheckRequest" server action wrapper, and checks if the NotificationId is empty.

Additionally, the "Request" input parameter is converted to the required structure of the "getNotification" API method, and the integration response is converted to a local "Response" structure.

Below are presented the required and optional request fields for this integration and also its definitions:

  • APIKey(required)

    To get an API key, sign in to GOV.UK Notify and go to the API integration page.

    Your API key follows the format {key_name}-{iss-uuid}-{secret-key-uuid} that is validated using the regular expression ^\w+-([\da-fA-F]{8}-([\da-fA-F]{4}-){3}[\da-fA-F]{12}-?){2}$.

    The value of the API Key is then encoded to be sent in the "Authorization" header of the request.
    To see more details about the Authorization Header, please click here.

  • NotificationId(required)

    The ID of the notification that is mapped with the argument notification_id from the REST API. You can find the notification ID in the response to the original notification method call.

To use this integration you can create a server action wrapper, i.e. "GetNotificationWrapper", that will call the service action "Get_Notification" from the GovUKNotify_IS module, passing the information required, and optional if needed, avoiding misbehaviour of this integration.

If your application needs to present the response on the screen, please check the following example or use this test page:

  • Text message

  • Email

  • File by email

  • Letter

  • Precompiled letter



Get the status of multiple messages

An integration with the "getNotifications" method of  GovUKNotifyAPIv2 is done through the service action "Get_Notifications" implemented in the GovUKNotify_IS module.

This API call returns one page of up to 250 messages and statuses. You can get either the most recent messages or older messages by specifying a particular notification ID in the OlderThan argument.


This service action includes all the flow needed to validate the required field APIKey through a "CheckRequest" server action wrapper.

Additionally, the "Request" input parameter is converted to the required structure of the "getNotifications" API method, and the integration response is converted to a local "Response" structure.

Below are presented the required and optional request fields for this integration and also its definitions:

  • APIKey(required)

    To get an API key, sign in to GOV.UK Notify and go to the API integration page.

    Your API key follows the format {key_name}-{iss-uuid}-{secret-key-uuid} that is validated using the regular expression ^\w+-([\da-fA-F]{8}-([\da-fA-F]{4}-){3}[\da-fA-F]{12}-?){2}$.

    The value of the API Key is then encoded to be sent in the "Authorization" header of the request.
    To see more details about the Authorization Header, please click here.

  • TemplateType(optional)

    This is being mapped with the argument template_type.

    You can leave out this argument to ignore this filter.

    You can filter by:

    • email
    • sms
    • letter
  • Status(optional)

    This is being mapped with the argument status.

    You can leave out this argument to ignore this filter.

    You can filter by:

  • Reference(optional)

    An identifier you can create if necessary that is mapped with the argument reference from the REST API. This reference identifies a single notification or a batch of notifications. It must not contain any personal information such as name or postal address. 

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

  • OlderThan(optional)

    Input the ID of a notification, i.e. 740e5834-3a29-46b4-9a6f-16142fde533a, into this argument that is mapped with the argument older_than from the REST API. If you use this argument, the method returns the next 250 received notifications older than the given ID

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

    The client only returns notifications that are 7 days old or newer. If the notification specified in this argument is older than 7 days, the client returns an empty response.

To use this integration you can create a server action wrapper, i.e. "GetNotificationsWrapper", that will call the service action "Get_Notifications" from the GovUKNotify_IS module, passing the information required, and optional if needed, avoiding misbehaviour of this integration.If your application needs to present the response on the screen, please check the following example or use this test page:

  • Get all messages

  • Get messages by template type

  • Get messages by status

  • Get messages by reference

  • Get messages from older than

As the above examples don't have all fields from the response, please check the expected full response from the API here.


Get a PDF for a letter

An integration with the "getLetterPDF" method of  GovUKNotifyAPIv2 is done through the service action "Get_LetterPDF" implemented in the GovUKNotify_IS module.

This API returns the PDF contents of a letter.

This service action includes all the flow needed to validate the required field APIKey, through a "CheckRequest" server action wrapper, and checks if the NotificationId is empty.

Additionally, the "Request" input parameter is converted to the required structure of the "getLetterPDF" API method, and the integration response is converted to a local "Response" structure.

Below are presented the required and optional request fields for this integration and also its definitions:

  • APIKey(required)

    To get an API key, sign in to GOV.UK Notify and go to the API integration page.

    Your API key follows the format {key_name}-{iss-uuid}-{secret-key-uuid} that is validated using the regular expression ^\w+-([\da-fA-F]{8}-([\da-fA-F]{4}-){3}[\da-fA-F]{12}-?){2}$.

    The value of the API Key is then encoded to be sent in the "Authorization" header of the request.
    To see more details about the Authorization Header, please click here.

  • NotificationId(required)

    The ID of the notification that is mapped with the argument notification_id from the REST API. You can find the notification ID in the response to the original notification method call.

To use this integration you can create a server action wrapper, i.e. "GetLetterPDFWrapper", that will call the service action "Get_LetterPDF" from the GovUKNotify_IS module, passing the information required, and optional if needed, avoiding misbehaviour of this integration.

If your application needs to provide the ability to download the PDF on the screen, please check the following examples or use this test page


Get a template

Get a template by ID

An integration with the "getTemplate" method of  GovUKNotifyAPIv2 is done through the service action "Get_TemplateById" implemented in the GovUKNotify_IS module.

This returns the latest version of the template.

This service action includes all the flow needed to validate the required fields APIKey and TemplateID, through a "CheckRequest" server action wrapper.

Additionally, the "Request" input parameter is converted to the required structure of the "getTemplate" API method, and the integration response is converted to a local "Response" structure.

Below are presented the required and optional request fields for this integration and also its definitions:

  • APIKey (required)

    To get an API key, sign in to GOV.UK Notify and go to the API integration page.

    Your API key follows the format {key_name}-{iss-uuid}-{secret-key-uuid} that is validated using the regular expression ^\w+-([\da-fA-F]{8}-([\da-fA-F]{4}-){3}[\da-fA-F]{12}-?){2}$.

    The value of the API Key is then encoded to be sent in the "Authorization" header of the request.
    To see more details about the Authorization Header, please click here.

  • TemplateID (required)

    The ID of the template that is mapped with the argument template_id from the REST API.
    Your template ID follows a format that is validated using the regular expression ^[\da-fA-F]{8}-([\da-fA-F]{4}-){3}[\da-fA-F]{12}$.

    To find the template ID:

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


To use this integration you can create a server action wrapper, i.e. "GetTemplateWrapper", that will call the service action "Get_TemplateById" from the GovUKNotify_IS module, passing the information required, and optional if needed, avoiding misbehaviour of this integration. 

If your application needs to present the response on the screen, please check the following example or use this test page:

Get a template by ID and version

An integration with the "getTemplateByVersion" method of  GovUKNotifyAPIv2 is done through the service action "Get_TemplateByIdAndVersion" implemented in the GovUKNotify_IS module.

This returns the version of the template.

This service action includes all the flow needed to validate the required fields APIKey and TemplateID, through a "CheckRequest" server action wrapper, and checks if the Version is greater than 0.

Additionally, the "Request" input parameter is converted to the required structure of the "getTemplateByVersion" API method, and the integration response is converted to a local "Response" structure.

Below are presented the required and optional request fields for this integration and also its definitions:

  • APIKey(required)

    To get an API key, sign in to GOV.UK Notify and go to the API integration page.

    Your API key follows the format {key_name}-{iss-uuid}-{secret-key-uuid} that is validated using the regular expression ^\w+-([\da-fA-F]{8}-([\da-fA-F]{4}-){3}[\da-fA-F]{12}-?){2}$.

    The value of the API Key is then encoded to be sent in the "Authorization" header of the request.
    To see more details about the Authorization Header, please click here.

  • TemplateID(required)

    The ID of the template that is mapped with the argument template_id from the REST API.
    Your template ID follows a format that is validated using the regular expression ^[\da-fA-F]{8}-([\da-fA-F]{4}-){3}[\da-fA-F]{12}$.

    To find the template ID:

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

    The version number of the template that is mapped with the argument version.

To use this integration you can create a server action wrapper, i.e. "GetTemplateByVersionWrapper", that will call the service action "Get_TemplateByIdAndVersion" from the GovUKNotify_IS module, passing the information required, and optional if needed, avoiding misbehaviour of this integration. 

If your application needs to present the response on the screen, please check the following example or use this test page:

  • Empty version

  • Invalid version

  • Success



Get all templates

An integration with the "getTemplates" method of  GovUKNotifyAPIv2 is done through the service action "Get_Templates" implemented in the GovUKNotify_IS module.

This returns the latest version of all templates.

This service action includes all the flow needed to validate the required field APIKey, through a "CheckRequest" server action wrapper.

Additionally, the "Request" input parameter is converted to the required structure of the "templates" API method, and the integration response is converted to a local "Response" structure.

Below are presented the required and optional request fields for this integration and also its definitions:

  • APIKey(required)

    To get an API key, sign in to GOV.UK Notify and go to the API integration page.

    Your API key follows the format {key_name}-{iss-uuid}-{secret-key-uuid} that is validated using the regular expression ^\w+-([\da-fA-F]{8}-([\da-fA-F]{4}-){3}[\da-fA-F]{12}-?){2}$.

    The value of the API Key is then encoded to be sent in the "Authorization" header of the request.
    To see more details about the Authorization Header, please click here.

  • TemplateType(optional)

    This is being mapped with the argument type.

    If you leave out this argument, the method returns all templates.

    You can filter by:

    • email
    • sms
    • letter


To use this integration you can create a server action wrapper, i.e. "GetTemplatesWrapper", that will call the service action "Get_Templates" from the GovUKNotify_IS module, passing the information required, and optional if needed, avoiding misbehaviour of this integration.

If your application needs to present the response on the screen, please check the following example or use this test page:

  • Get all templates

  • Get email templates

  • Get SMS templates

  • Get letter templates

    Generate a preview template

    An integration with the "postTemplatePreview" method of  GovUKNotifyAPIv2 is done through the service action "Get_TemplatePreview" implemented in the GovUKNotify_IS module.

    This generates a preview version of a template.

    This service action includes all the flow needed to validate the required fields APIKey and TemplateID, through a "CheckRequest" server action wrapper.

    Additionally, the "Request" input parameter is converted to the required structure of the "postTemplatePreview" API method, and the integration response is converted to a local "Response" structure.

    Below are presented the required and optional request fields for this integration and also its definitions:

    • APIKey(required)

      To get an API key, sign in to GOV.UK Notify and go to the API integration page.

      Your API key follows the format {key_name}-{iss-uuid}-{secret-key-uuid} that is validated using the regular expression ^\w+-([\da-fA-F]{8}-([\da-fA-F]{4}-){3}[\da-fA-F]{12}-?){2}$.

      The value of the API Key is then encoded to be sent in the "Authorization" header of the request.
      To see more details about the Authorization Header, please click here.

    • TemplateID(required)

      The ID of the template that is mapped with the argument template_id from the REST API.
      Your template ID follows a format that is validated using the regular expression ^[\da-fA-F]{8}-([\da-fA-F]{4}-){3}[\da-fA-F]{12}$.

      To find the template ID:

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

      This is being mapped with the argument personalisation from the REST API.

      If a template has placeholder fields for personalised information such as name or reference number, you must provide their values in a dictionary with key-value pairs.

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

  • To use this integration you can create a server action wrapper, i.e. "GetTemplatePreviewWrapper", that will call the service action "Get_TemplatePreview" from the GovUKNotify_IS module, passing the information required, and optional if needed, avoiding misbehaviour of this integration.

    If your application needs to present the response on the screen, please check the following example or use this test page:


Get received text messages

Get received text messages

An integration with the "getReceivedSMS" method of GovUKNotifyAPIv2 is done through the service action "Get_ReceivedSMS" implemented in the GovUKNotify_IS module.

This service action includes all the flow needed to validate the required field APIKey through a "CheckRequest" server action wrapper.

Additionally, the "Request" input parameter is converted to the required structure of the "getReceivedSMS" API method, and the integration response is converted to a local "Response" structure.

Below are presented the required and optional request fields for this integration and also its definitions:

  • APIKey(required)

    To get an API key, sign in to GOV.UK Notify and go to the API integration page.

    Your API key follows the format {key_name}-{iss-uuid}-{secret-key-uuid} that is validated using the regular expression ^\w+-([\da-fA-F]{8}-([\da-fA-F]{4}-){3}[\da-fA-F]{12}-?){2}$.

    The value of the API Key is then encoded to be sent in the "Authorization" header of the request.
    To see more details about the Authorization Header, please click here.

  • OlderThan(optional)

    The ID of a received text message, i.e. 740e5834-3a29-46b4-9a6f-16142fde533a, into this argument that is mapped with the argument older_than from the REST API. If this is passed, the response will only list text messages received before that message. 

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

    The client only returns messages that are 7 days old or newer. If the message specified in this argument is older than 7 days, the client returns an empty response.

To use this integration you can create a server action wrapper, i.e. "GetReceivedSMSWrapper", that will call the service action "Get_ReceivedSMS" from the GovUKNotify_IS module, passing the information required, and optional if needed, avoiding misbehaviour of this integration.

If your application needs to present the response on the screen, please check the following example or use this test page:


Callbacks

Authorization

The callback authorization is checked in the "OnAuthentication" event of each callback exposed REST API by validating the bearer token sent through the "Authorization" HTTP Request header. In the "OnAuthentication" is called a server action wrapper "ValidateCallbackAuthorization" that will validate the bearer token for the authorization.This is a wrapper to the "ReadTokenService" JWT integration which decodes and validates a signed token.

Besides the "EncodedToken", which is obtained through the "Authorization" HTTP Request header, the remaining parameters values are identified in the following site properties, which value must be set using the Service Center:

  • VerifySignature: Indicates if the token's signature should be verified, based on the signature info passed as parameters. 
  • SignatureKey: Key used to verify the token, needed only if VerifySignature is selected.
  • ExpectedSignatureKeyId: Expected ID to the key that was used for signing the token. Needed only if VerifySignature is selected, if empty the signature will still be validated but the key IDs.
  • VerifyLifetime: Indicates if the token has expired.
  • VerifyIssuer: Indicates the audience should be validated, based on an issuer as a parameter.
  • ExpectedIssuer: Expected issuer to be validated in the token.
  • VerifyAudience: Indicates the audience should be validated, based on an issuer as a parameter.
  • ExpectedAudience: Expected audience to be validated in the token.

If the encoded token is valid, the callback request is accepted. Otherwise, a 403 "Invalid token" exception is retrieved.


Delivery receipts

An exposed REST API method "postUpdateStatus" is available through the endpoint DeliveryReceiptCallback whose main goal is to update a notification status through the received request.This callback API only should be used/set up through GOV.UK Notify if you are using the service actions available in the GovUKNotify_CS to store the request/response of the emailSMS and letter sent.

Below are presented the request fields for this API and its definitions:

  • Id

    Notify’s ID for the status receipts.
    Format: UUID

  • To

    The email address or phone number of the recipient.
    Format: hello@gov.uk or 07700912345

  • Reference

    The reference was sent by the service. This reference identifies a single notification or a batch of notifications.
    Format: 12345678 or null

  • Status

    The status of the notification.
    Format: deliveredpermanent-failuretemporary-failure or technical-failure

  • CreatedAt

    The time the service sent the request.
    Format: 2017-05-14T12:15:30.000000Z

  • CompletedAt

    The last time the status was updated.
    Format: 2017-05-14T12:15:30.000000Z or null

  • SentAt

    The time the notification was sent.
    Format: 2017-05-14T12:15:30.000000Z or null

  • NotificationType

    The notification type.
    Format: email or SMS

  • TemplateId

    The id of the template that was used.
    Format: UUID

  • TemplateVersion

    The version number of the template that was used.
    Format: 1

 

This API receives a request that will be serialized to JSON and its binary is stored as a record in NotificationToProcess database entity. If the request is successful, the status code of the response is 200.

If you don't want to process the request, a site property DisableUpdateStatus is available whose value "true" allows you to send the status code 200 in the response without the request having been sent for processing.

Being exposed to process events, when a record is created in the NotificationToProcess database entity, a light process execution activity UpdateNotificationActivity is automatically triggered.


Process activity

Before processing the notification status update begins, it's validated that the record exists in the NotificationToProcess entity and its request content is not empty. If any of the sentences fail, the process ends. 

Once a binary request is obtained from the NotificationToProcess entity, it's converted to JSON so that it can be deserialized into the correct structure and sent to the  "ProcessingUpdateNotificationActivity" wrapper so that it can be processed.


Processing update notification activity

This wrapper verifies if the notification to process is not processed yet, using the service action "GetNotificationNotProcessed" of the GovUKNotify_CS module (i.e. if the notification status is empty, created or sending). 

If the notification is not processed yet, its status is updated using the "UpdateNotificationStatus" service action of the GovUKNotify_CS module. However, before that, if the Gov.UK Notify ID of the notification being processed is not stored, it is updated using the "UpdateGovUkNotificationId" service action from the same module. 


Received text messages

If your service receives text messages in Notify, Notify can forward them to your callback URL as soon as they arrive.

Contact the Notify team using the support page or chat with us on Slack to request a unique number for text message replies.

An exposed REST API method "postReceiveSMS" is available through the endpoint ReceiveSMSCallback if you want to store received text messages (SMS) sent by users using your service. 


Below are presented the request fields for this API and its definitions:

  • Id

    Notify’s ID for the received message.
    Format: UUID

  • SourceNumber

    The phone number the message was sent from.
    Format: 07700912345

  • DestinationNumber

    The number the message was sent to (your number).
    Format: 07700987654

  • Message

    The received message.
    Format: Hello Notify!

  • DateReceived

    The UTC datetime that the message was received by Notify.
    Format: 2017-05-14T12:15:30.000000Z

This API receives a request that is saved locally using the service action "SaveSMS" of the GovUKNotify_CS module. If the request is successful, the status code of the response is 200.

If you don't want to process the request, a site property DisableReceiveSMS is available whose value "true" allows you to send the status code 200 in the response without the request having been saved locally.

To get the received text messages saved locally, a service action "GetSMS" of the GovUKNotify_CS module is provided for this purpose.




To get multiple notifications, or a single notification, saved locally, the service actions "GetNotifications" and "GetNotificationById" of the GovUKNotify_CS module are provided for this purpose.



1.0.0

To start to use this component, please install the "GOV UK Notify Service" application in your factory.

It's provided an integration to send text messages, emails (with or without a file), letters and precompiled letters. Additionally, you can verify the status of a single message or multiple messages, as well as get the details of a single template or multiple templates.

The authentication/authorization of each request is made by converting the API key of your service account into JSON Web Token (JWT) of JWT the forge component. The outcome is then added to the HTTP request "Authorization" header.


Authorization

Authorization header

JSON Web Tokens (JWT) are encoded using a secret key with the format of 3d844edf-8d35-48ac-975b-e847b4f122b0.

That secret key forms a part of your API key, which follows the format {key_name}-{iss-uuid}-{secret-key-uuid}.

For example, if your API key is my_test_key-26785a09-ab16-4eb0-8407-a37497a57506-3d844edf-8d35-48ac-975b-e847b4f122b0:

  • your API key name is my_test_key
  • your iss (your service id) is 26785a09-ab16-4eb0-8407-a37497a57506
  • your secret key is 3d844edf-8d35-48ac-975b-e847b4f122b0

iat (issued at) is the current time in UTC in epoch seconds. The token expires within 30 seconds of the current time.

Refer to the JSON Web Tokens website for more information on encoding your authorisation header.

When you have an encoded and signed token, add that token to a header as follows:

"Authorization": "Bearer encoded_jwt_token".


Implementation

In the "OnBeforeRequest" of GovUKNotifyAPIv2 consumed REST API is called a server action wrapper "OnBeforeRequest_GovUKNotifyAPI".

This wrapper manipulate the HTTP Request before it is sent, and one of the actions taken in consideration is a wrapper "GenerateTokenFromHTTPHeaderAPIKey". The main goal of this wrapper is to gather the API Key from the header request and with it to generate a JWT bearer token to be appended defined as a value of "Authorization" HTTP request header.

The "GenerateTokenFromHTTPHeaderAPIKey" server action receives as input parameter a list of all HTTP Request Headers and returns the encoded token. From the Headers parameter will be extracted the API Key that was originally sent. For this extraction, we are using a private server action (GetAPIKeyFromHeaders) that filters the Headers list by a specific header name.  

After obtaining the API Key, it is used an input parameter for a new wrapper (GenerateJWT) that will be used to generate the final encoded token.
In order to keep the token's lifetime short, no value is defined in the "Expires" parameter, meaning the token must be used within 30 seconds after its generation.

Inside the "GenerateJWT" wrapper, a local action "SplitAPIKey" is invoked which, after validating whether the API Key matches the intended format, returns: NameService Id and Secret Key (as indicated in the "Authorization Header" section).

For the proper generation of the JWT token, it is used the Service Id as the Issuer, HS256 as the Algorithm, and Secret Key  as the Key and KeyId. If the encoded token is generated successfuly, its value is returned. To know a little bit more about how to use the service below, please click here.

Finally, after the encoded token has been generated, it is added to the "Authorization" header of the HTTP request, such as the "Content-Type" header as "application/json".


Send a message

Send a text message

An integration with the "postSMS" method of  GovUKNotifyAPIv2 is done through the service action "Send_SMS" implemented in the GovUKNotify_IS module.

This service action includes all the flow needed to validate the required fields APIKey and TemplateID, through a "CheckRequest" server action wrapper, and checks if the MobileNumber is empty.

Additionally, the "Request" input parameter is converted to the required structure of the "postSMS" API method, and the integration response is converted to a local "Response" structure.

Below are presented the required and optional request fields for this integration and also its definitions:

  • APIKey(required)

    To get an API key, sign in to GOV.UK Notify and go to the API integration page.

    Your API key follows the format {key_name}-{iss-uuid}-{secret-key-uuid} that is validated using the regular expression ^\w+-([\da-fA-F]{8}-([\da-fA-F]{4}-){3}[\da-fA-F]{12}-?){2}$.

    The value of the API Key is then encoded to be sent in the "Authorization" header of the request.
    To see more details about the Authorization Header, please click here.

  • TemplateID(required)

    The SMS template ID is mapped with the argument template_id from the REST API.
    Your template ID follows a format that is validated using the regular expression ^[\da-fA-F]{8}-([\da-fA-F]{4}-){3}[\da-fA-F]{12}$.

    To find the template ID:

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

    The phone number of the recipient of the text message is mapped with the argument phone_number from the REST API. This can be a UK or international number.

  • SenderID(optional)

    A unique identifier of the sender of the text message notification that is mapped with the argument sms_sender_id from the REST API.

    To find the text message sender:

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


  • Reference(optional)

    An identifier you can create if necessary that is mapped with the argument reference from the REST API. This reference identifies a single notification or a batch of notifications. It must not contain any personal information such as name or postal address. 

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

  • Personalisation (optional)

    This is being mapped with the argument personalisation from the REST API.

    If a template has placeholder fields for personalised information such as name or reference number, you must provide their values in a dictionary with key-value pairs.

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

To use this integration you can create a server action wrapper, i.e. "SendSMSWrapper", that will call the service action "Send_SMS" from the GovUKNotify_IS module, passing the information required, and optional if needed, avoiding misbehaviour of this integration. 

If your application needs to present the response on the screen, please check the following example or use this test page


Send an email

An integration with the "postEmail" method of  GovUKNotifyAPIv2 is done through the service action "Send_Email" implemented in the GovUKNotify_IS module.

This service action includes all the flow needed to validate the required fields APIKey and TemplateID, through a "CheckRequest" server action wrapper, and checks if the EmailAddress is empty.

Additionally, the "Request" input parameter is converted to the required structure of the "postEmail" API method, and the integration response is converted to a local "Response" structure.


Below are presented the required and optional request fields for this integration and also its definitions:

  • APIKey(required)

    To get an API key, sign in to GOV.UK Notify and go to the API integration page.

    Your API key follows the format {key_name}-{iss-uuid}-{secret-key-uuid} that is validated using the regular expression ^\w+-([\da-fA-F]{8}-([\da-fA-F]{4}-){3}[\da-fA-F]{12}-?){2}$.

    The value of the API Key is then encoded to be sent in the "Authorization" header of the request.
    To see more details about the Authorization Header, please click here.

  • TemplateID(required)

    The email template ID is mapped with the argument template_id from the REST API.
    Your template ID follows a format that is validated using the regular expression ^[\da-fA-F]{8}-([\da-fA-F]{4}-){3}[\da-fA-F]{12}$.

    To find the template ID:

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

    The email address of the recipient is mapped with the argument email_address from the REST API. This can be a UK or international number.

  • EmailReplyToId(optional)

    This is an email address specified by you to receive replies from your users that is mapped with the argument email_reply_to_id from the REST API. You must add at least one reply-to email address before your service can go live.

    To add a reply-to email address:

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

    An identifier you can create if necessary that is mapped with the argument reference from the REST API. This reference identifies a single notification or a batch of notifications. It must not contain any personal information such as name or postal address. 

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

  • Personalisation(optional)

    This is being mapped with the argument personalisation from the REST API.

    If a template has placeholder fields for personalised information such as name or reference number, you must provide their values in a dictionary with key-value pairs.

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

To use this integration you can create a server action wrapper, i.e. "SendEmailWrapper", that will call the service action "Send_Email " from the GovUKNotify_IS module, passing the information required, and optional if needed, avoiding misbehaviour of this integration.

If your application needs to present the response on the screen, please check the following example or use this test page:

Send a file by email

An integration with the "postFileByEmail" method of  GovUKNotifyAPIv2 is done through the service action "Send_FileByEmail" implemented in the GovUKNotify_IS module.

This service action includes all the flow needed to validate the required fields APIKey and TemplateID, through a "CheckRequest" server action wrapper, and checks if the EmailAddress and Placeholder are empty, and the Content is an empty file.

Additionally, the "Request" input parameter is converted to the required structure of the "postFileByEmail" API method, and the integration response is converted to a local "Response" structure.

Below are presented the required and optional request fields for this integration and also its definitions.

  • APIKey(required)

    To get an API key, sign in to GOV.UK Notify and go to the API integration page.

    Your API key follows the format {key_name}-{iss-uuid}-{secret-key-uuid} that is validated using the regular expression ^\w+-([\da-fA-F]{8}-([\da-fA-F]{4}-){3}[\da-fA-F]{12}-?){2}$.

    The value of the API Key is then encoded to be sent in the "Authorization" header of the request.
    To see more details about the Authorization Header, please click here.

  • TemplateID(required)

    The email template ID is mapped with the argument template_id from the REST API.
    Your template ID follows a format that is validated using the regular expression ^[\da-fA-F]{8}-([\da-fA-F]{4}-){3}[\da-fA-F]{12}$.

    To find the template ID:

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

    The email address of the recipient is mapped with the argument email_address from the REST API. This can be a UK or international number.

  • EmailReplyToId(optional)

    This is an email address specified by you to receive replies from your users that is mapped with the argument email_reply_to_id from the REST API. You must add at least one reply-to email address before your service can go live.

    To add a reply-to email address:

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

  • Reference(optional)

    An identifier you can create if necessary that is mapped with the argument reference from the REST API. This reference identifies a single notification or a batch of notifications. It must not contain any personal information such as name or postal address. 

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

  • FileToSend(required)

    Structure with attributes related to the file to send that will be converted to a JSON string and to be added as pair key-value in the Personalisation

    • Placeholder: Must match a placeholder in the template that will contain a secure link to download the file. For example, "link_to_file"
    • Content: The binary content of the file to download that must be smaller than 2MB. This content will be converted to a base64 encoded string before being sent.

      You can upload the following file types:
      • PDF (.pdf)
      • CSV (.csv)
      • Text (.odt, .txt, .rtf, .json)
      • MS Word Document (.doc, .docx)
      • Ms Excel Spreadsheet (.xlsx)
    • IsCSV: Uploads for CSV files should set this flag as true to ensure it’s downloaded as a .csv file.
    • RequireVerification: Set this flag as true to ensure the recipients will confirm the email address before they can download the file.

      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
    • AvailableWeeks: Set the number of weeks you want the file to be available.
      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
  • Personalisation(optional)

    This is being mapped with the argument personalisation from the REST API.

    If a template has placeholder fields for personalised information such as name or reference number, you must provide their values in a dictionary with key-value pairs.

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

To use this integration you can create a server action wrapper, i.e. "SendFileByEmailWrapper", that will call the service action "Send_FileByEmail" from the GovUKNotify_IS module, passing the information required, and optional if needed, avoiding misbehaviour of this integration.

If your application needs to present the response on the screen, please check the following example or use this test page:

Send a letter

An integration with the "postLetter" method of  GovUKNotifyAPIv2 is done through the service action "Send_Letter" implemented in the GovUKNotify_IS module.

This service action includes all the flow needed to validate the required fields APIKey and TemplateID, through a "CheckRequest" server action wrapper.

Additionally, the "Request" input parameter is converted to the required structure of the "postFileByEmail" API method, and the integration response is converted to a local "Response" structure.


Below are presented the required and optional request fields for this integration and also its definitions:

  • APIKey (required)

    To get an API key, sign in to GOV.UK Notify and go to the API integration page.

    Your API key follows the format {key_name}-{iss-uuid}-{secret-key-uuid} that is validated using the regular expression ^\w+-([\da-fA-F]{8}-([\da-fA-F]{4}-){3}[\da-fA-F]{12}-?){2}$.

    The value of the API Key is then encoded to be sent in the "Authorization" header of the request.
    To see more details about the Authorization Header, please click here.

  • TemplateID (required)

    The letter template ID is mapped with the argument template_id from the REST API.
    Your template ID follows a format that is validated using the regular expression ^[\da-fA-F]{8}-([\da-fA-F]{4}-){3}[\da-fA-F]{12}$.

    To find the template ID:

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

    An identifier you can create if necessary that is mapped with the argument reference from the REST API. This reference identifies a single notification or a batch of notifications. It must not contain any personal information such as name or postal address. 

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

  • AddressLines (required)

    Structure with attributes related to the recipient's address that will be transformed into pairs of key-value in the Personalisation

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

  • Personalisation(optional)

    This is being mapped with the argument personalisation from the REST API.

    If a template has placeholder fields different from AddressLines, you must provide their values in a dictionary with key-value pairs.

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

To use this integration you can create a server action wrapper, i.e. "SendLetterWrapper", that will call the service action "Send_Letter" from the GovUKNotify_IS module, passing the information required, and optional if needed, avoiding misbehaviour of this integration.


If your application needs to present the response on the screen, please check the following example or use this test page:


Send a precompiled letter

An integration with the "postPrecompiledLetter" method of  GovUKNotifyAPIv2 is done through the service action "Send_PrecompiledLetter" implemented in the GovUKNotify_IS module.

This service action includes all the flow needed to validate the required field APIKey, through a "CheckRequest" server action wrapper, and checks if the Reference is empty, and the Content is an empty file.

Additionally, the "Request" input parameter is converted to the required structure of the "postPrecompiledLetter" API method, and the integration response is converted to a local "Response" structure.

Below are presented the required and optional request fields for this integration and also its definitions.

  • APIKey(required)

    To get an API key, sign in to GOV.UK Notify and go to the API integration page.

    Your API key follows the format {key_name}-{iss-uuid}-{secret-key-uuid} that is validated using the regular expression ^\w+-([\da-fA-F]{8}-([\da-fA-F]{4}-){3}[\da-fA-F]{12}-?){2}$.

    The value of the API Key is then encoded to be sent in the "Authorization" header of the request.
    To see more details about the Authorization Header, please click here.

  • Reference(required)

    An identifier you can create if necessary that is mapped with the argument reference from the REST API. This reference identifies a single notification or a batch of notifications. It must not contain any personal information such as name or postal address. 

  • Content(required)

    The precompiled letter must be a PDF file which meets the GOV.UK Notify letter specification that is mapped with the argument content from the REST API. This content will be converted to a base64 encoded string before being sent.

  • Postage(optional)

    This is being mapped with the argument postage.

    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 this argument, the postage will default to second class.

To use this integration you can create a server action wrapper, i.e. "SendPrecompiledLetterWrapper", that will call the service action "Send_PrecompiledLetter" from the GovUKNotify_IS module, passing the information required, and optional if needed, avoiding misbehaviour of this integration.


If your application needs to present the response on the screen, please check the following example or use this test page:


Get message status

Get the status of one message

An integration with the "getNotification" method of  GovUKNotifyAPIv2 is done through the service action "Get_Notification" implemented in the GovUKNotify_IS module.

This service action includes all the flow needed to validate the required field APIKey, through a "CheckRequest" server action wrapper, and checks if the NotificationId is empty.

Additionally, the "Request" input parameter is converted to the required structure of the "getNotification" API method, and the integration response is converted to a local "Response" structure.

Below are presented the required and optional request fields for this integration and also its definitions:

  • APIKey(required)

    To get an API key, sign in to GOV.UK Notify and go to the API integration page.

    Your API key follows the format {key_name}-{iss-uuid}-{secret-key-uuid} that is validated using the regular expression ^\w+-([\da-fA-F]{8}-([\da-fA-F]{4}-){3}[\da-fA-F]{12}-?){2}$.

    The value of the API Key is then encoded to be sent in the "Authorization" header of the request.
    To see more details about the Authorization Header, please click here.

  • NotificationId(required)

    The ID of the notification that is mapped with the argument notification_id from the REST API. You can find the notification ID in the response to the original notification method call.

To use this integration you can create a server action wrapper, i.e. "GetNotificationWrapper", that will call the service action "Get_Notification" from the GovUKNotify_IS module, passing the information required, and optional if needed, avoiding misbehaviour of this integration.

If your application needs to present the response on the screen, please check the following example or use this test page:

  • Text message
  • Email
  • File by email
  • Letter
  • Precompiled letter


Get the status of multiple messages

An integration with the "getNotifications" method of  GovUKNotifyAPIv2 is done through the service action "Get_Notifications" implemented in the GovUKNotify_IS module.

This API call returns one page of up to 250 messages and statuses. You can get either the most recent messages or older messages by specifying a particular notification ID in the OlderThan argument.


This service action includes all the flow needed to validate the required field APIKey through a "CheckRequest" server action wrapper.

Additionally, the "Request" input parameter is converted to the required structure of the "getNotifications" API method, and the integration response is converted to a local "Response" structure.

Below are presented the required and optional request fields for this integration and also its definitions:

  • APIKey(required)

    To get an API key, sign in to GOV.UK Notify and go to the API integration page.

    Your API key follows the format {key_name}-{iss-uuid}-{secret-key-uuid} that is validated using the regular expression ^\w+-([\da-fA-F]{8}-([\da-fA-F]{4}-){3}[\da-fA-F]{12}-?){2}$.

    The value of the API Key is then encoded to be sent in the "Authorization" header of the request.
    To see more details about the Authorization Header, please click here.

  • TemplateType(optional)

    This is being mapped with the argument template_type.

    You can leave out this argument to ignore this filter.

    You can filter by:

    • email
    • sms
    • letter
  • Status(optional)

    This is being mapped with the argument status.

    You can leave out this argument to ignore this filter.

    You can filter by:

  • Reference(optional)

    An identifier you can create if necessary that is mapped with the argument reference from the REST API. This reference identifies a single notification or a batch of notifications. It must not contain any personal information such as name or postal address. 

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

  • OlderThan(optional)

    Input the ID of a notification, i.e. 740e5834-3a29-46b4-9a6f-16142fde533a, into this argument that is mapped with the argument older_than from the REST API. If you use this argument, the method returns the next 250 received notifications older than the given ID

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

    The client only returns notifications that are 7 days old or newer. If the notification specified in this argument is older than 7 days, the client returns an empty response.

To use this integration you can create a server action wrapper, i.e. "GetNotificationsWrapper", that will call the service action "Get_Notifications" from the GovUKNotify_IS module, passing the information required, and optional if needed, avoiding misbehaviour of this integration.If your application needs to present the response on the screen, please check the following example or use this test page:

  • Get all messages
  • Get messages by template type
  • Get messages by status
  • Get messages by reference
  • Get messages from older than

As the above examples don't have all fields from the response, please check the expected full response from the API here.


Get a PDF for a letter

An integration with the "getLetterPDF" method of  GovUKNotifyAPIv2 is done through the service action "Get_LetterPDF" implemented in the GovUKNotify_IS module.

This API returns the PDF contents of a letter. 

This service action includes all the flow needed to validate the required field APIKey, through a "CheckRequest" server action wrapper, and checks if the NotificationId is empty.

Additionally, the "Request" input parameter is converted to the required structure of the "getLetterPDF" API method, and the integration response is converted to a local "Response" structure.

Below are presented the required and optional request fields for this integration and also its definitions:

  • APIKey(required)

    To get an API key, sign in to GOV.UK Notify and go to the API integration page.

    Your API key follows the format {key_name}-{iss-uuid}-{secret-key-uuid} that is validated using the regular expression ^\w+-([\da-fA-F]{8}-([\da-fA-F]{4}-){3}[\da-fA-F]{12}-?){2}$.

    The value of the API Key is then encoded to be sent in the "Authorization" header of the request.
    To see more details about the Authorization Header, please click here.

  • NotificationId(required)

    The ID of the notification that is mapped with the argument notification_id from the REST API. You can find the notification ID in the response to the original notification method call.

To use this integration you can create a server action wrapper, i.e. "GetLetterPDFWrapper", that will call the service action "Get_LetterPDF" from the GovUKNotify_IS module, passing the information required, and optional if needed, avoiding misbehaviour of this integration.

If your application needs to provide the ability to download the PDF on the screen, please check the following examples or use this test page


Get a template

Get a template by ID

An integration with the "getTemplate" method of  GovUKNotifyAPIv2 is done through the service action "Get_TemplateById" implemented in the GovUKNotify_IS module.

This returns the latest version of the template.

This service action includes all the flow needed to validate the required fields APIKey and TemplateID, through a "CheckRequest" server action wrapper.

Additionally, the "Request" input parameter is converted to the required structure of the "getTemplate" API method, and the integration response is converted to a local "Response" structure.

Below are presented the required and optional request fields for this integration and also its definitions:

  • APIKey (required)

    To get an API key, sign in to GOV.UK Notify and go to the API integration page.

    Your API key follows the format {key_name}-{iss-uuid}-{secret-key-uuid} that is validated using the regular expression ^\w+-([\da-fA-F]{8}-([\da-fA-F]{4}-){3}[\da-fA-F]{12}-?){2}$.

    The value of the API Key is then encoded to be sent in the "Authorization" header of the request.
    To see more details about the Authorization Header, please click here.

  • TemplateID (required)

    The ID of the template that is mapped with the argument template_id from the REST API.
    Your template ID follows a format that is validated using the regular expression ^[\da-fA-F]{8}-([\da-fA-F]{4}-){3}[\da-fA-F]{12}$.

    To find the template ID:

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


To use this integration you can create a server action wrapper, i.e. "GetTemplateWrapper", that will call the service action "Get_TemplateById" from the GovUKNotify_IS module, passing the information required, and optional if needed, avoiding misbehaviour of this integration. 

If your application needs to present the response on the screen, please check the following example or use this test page:

Get a template by ID and version

An integration with the "getTemplateByVersion" method of  GovUKNotifyAPIv2 is done through the service action "Get_TemplateByIdAndVersion" implemented in the GovUKNotify_IS module.

This returns the version of the template.

This service action includes all the flow needed to validate the required fields APIKey and TemplateID, through a "CheckRequest" server action wrapper, and checks if the Version is greater than 0.

Additionally, the "Request" input parameter is converted to the required structure of the "getTemplateByVersion" API method, and the integration response is converted to a local "Response" structure.

Below are presented the required and optional request fields for this integration and also its definitions:

  • APIKey(required)

    To get an API key, sign in to GOV.UK Notify and go to the API integration page.

    Your API key follows the format {key_name}-{iss-uuid}-{secret-key-uuid} that is validated using the regular expression ^\w+-([\da-fA-F]{8}-([\da-fA-F]{4}-){3}[\da-fA-F]{12}-?){2}$.

    The value of the API Key is then encoded to be sent in the "Authorization" header of the request.
    To see more details about the Authorization Header, please click here.

  • TemplateID(required)

    The ID of the template that is mapped with the argument template_id from the REST API.
    Your template ID follows a format that is validated using the regular expression ^[\da-fA-F]{8}-([\da-fA-F]{4}-){3}[\da-fA-F]{12}$.

    To find the template ID:

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

    The version number of the template that is mapped with the argument version.

To use this integration you can create a server action wrapper, i.e. "GetTemplateByVersionWrapper", that will call the service action "Get_TemplateByIdAndVersion" from the GovUKNotify_IS module, passing the information required, and optional if needed, avoiding misbehaviour of this integration. 

If your application needs to present the response on the screen, please check the following example or use this test page:

  • Empty version
  • Invalid version
  • Success


Get all templates

An integration with the "getTemplates" method of  GovUKNotifyAPIv2 is done through the service action "Get_Templates" implemented in the GovUKNotify_IS module.

This returns the latest version of all templates.

This service action includes all the flow needed to validate the required field APIKey, through a "CheckRequest" server action wrapper.

Additionally, the "Request" input parameter is converted to the required structure of the "templates" API method, and the integration response is converted to a local "Response" structure.

Below are presented the required and optional request fields for this integration and also its definitions:

  • APIKey(required)

    To get an API key, sign in to GOV.UK Notify and go to the API integration page.

    Your API key follows the format {key_name}-{iss-uuid}-{secret-key-uuid} that is validated using the regular expression ^\w+-([\da-fA-F]{8}-([\da-fA-F]{4}-){3}[\da-fA-F]{12}-?){2}$.

    The value of the API Key is then encoded to be sent in the "Authorization" header of the request.
    To see more details about the Authorization Header, please click here.

  • TemplateType(optional)

    This is being mapped with the argument type.

    If you leave out this argument, the method returns all templates.

    You can filter by:

    • email
    • sms
    • letter


To use this integration you can create a server action wrapper, i.e. "GetTemplatesWrapper", that will call the service action "Get_Templates" from the GovUKNotify_IS module, passing the information required, and optional if needed, avoiding misbehaviour of this integration.

If your application needs to present the response on the screen, please check the following example or use this test page:
  • Get all templates
  • Get email templates
  • Get SMS templates
  • Get letter templates

    Generate a preview template

    An integration with the "postTemplatePreview" method of  GovUKNotifyAPIv2 is done through the service action "Get_TemplatePreview" implemented in the GovUKNotify_IS module.

    This generates a preview version of a template.

    This service action includes all the flow needed to validate the required fields APIKey and TemplateID, through a "CheckRequest" server action wrapper.

    Additionally, the "Request" input parameter is converted to the required structure of the "postTemplatePreview" API method, and the integration response is converted to a local "Response" structure.

    Below are presented the required and optional request fields for this integration and also its definitions:

    • APIKey(required)

      To get an API key, sign in to GOV.UK Notify and go to the API integration page.

      Your API key follows the format {key_name}-{iss-uuid}-{secret-key-uuid} that is validated using the regular expression ^\w+-([\da-fA-F]{8}-([\da-fA-F]{4}-){3}[\da-fA-F]{12}-?){2}$.

      The value of the API Key is then encoded to be sent in the "Authorization" header of the request.
      To see more details about the Authorization Header, please click here.

    • TemplateID(required)

      The ID of the template that is mapped with the argument template_id from the REST API.
      Your template ID follows a format that is validated using the regular expression ^[\da-fA-F]{8}-([\da-fA-F]{4}-){3}[\da-fA-F]{12}$.

      To find the template ID:

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

      This is being mapped with the argument personalisation from the REST API.

      If a template has placeholder fields for personalised information such as name or reference number, you must provide their values in a dictionary with key-value pairs.

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

    To use this integration you can create a server action wrapper, i.e. "GetTemplatePreviewWrapper", that will call the service action "Get_TemplatePreview" from the GovUKNotify_IS module, passing the information required, and optional if needed, avoiding misbehaviour of this integration.

    If your application needs to present the response on the screen, please check the following example or use this test page:


Get received text messages

Get received text messages

An integration with the "getReceivedSMS" method of GovUKNotifyAPIv2 is done through the service action "Get_ReceivedSMS" implemented in the GovUKNotify_IS module.

This service action includes all the flow needed to validate the required field APIKey through a "CheckRequest" server action wrapper.

Additionally, the "Request" input parameter is converted to the required structure of the "getReceivedSMS" API method, and the integration response is converted to a local "Response" structure.

Below are presented the required and optional request fields for this integration and also its definitions:

  • APIKey(required)

    To get an API key, sign in to GOV.UK Notify and go to the API integration page.

    Your API key follows the format {key_name}-{iss-uuid}-{secret-key-uuid} that is validated using the regular expression ^\w+-([\da-fA-F]{8}-([\da-fA-F]{4}-){3}[\da-fA-F]{12}-?){2}$.

    The value of the API Key is then encoded to be sent in the "Authorization" header of the request.
    To see more details about the Authorization Header, please click here.

  • OlderThan(optional)

    The ID of a received text message, i.e. 740e5834-3a29-46b4-9a6f-16142fde533a, into this argument that is mapped with the argument older_than from the REST API. If this is passed, the response will only list text messages received before that message. 

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

    The client only returns messages that are 7 days old or newer. If the message specified in this argument is older than 7 days, the client returns an empty response.

To use this integration you can create a server action wrapper, i.e. "GetReceivedSMSWrapper", that will call the service action "Get_ReceivedSMS" from the GovUKNotify_IS module, passing the information required, and optional if needed, avoiding misbehaviour of this integration.

If your application needs to present the response on the screen, please check the following example or use this test page:


Callbacks

Authorization

The callback authorization is checked in the "OnAuthentication" event of each callback exposed REST API by validating the bearer token sent through the "Authorization" HTTP Request header. In the "OnAuthentication" is called a server action wrapper "ValidateCallbackAuthorization" that will validate the bearer token for the authorization. This is a wrapper to the "ReadTokenService" JWT integration which decodes and validates a signed token.

Besides the "EncodedToken", which is obtained through the "Authorization" HTTP Request header, the remaining parameters values are identified in the following site properties, which value must be set using the Service Center:

  • VerifySignature: Indicates if the token's signature should be verified, based on the signature info passed as parameters. 
  • SignatureKey: Key used to verify the token, needed only if VerifySignature is selected.
  • ExpectedSignatureKeyId: Expected ID to the key that was used for signing the token. Needed only if VerifySignature is selected, if empty the signature will still be validated but the key IDs.
  • VerifyLifetime: Indicates if the token has expired.
  • VerifyIssuer: Indicates the audience should be validated, based on an issuer as a parameter.
  • ExpectedIssuer: Expected issuer to be validated in the token.
  • VerifyAudience: Indicates the audience should be validated, based on an issuer as a parameter.
  • ExpectedAudience: Expected audience to be validated in the token.

If the encoded token is valid, the callback request is accepted. Otherwise, a 403 "Invalid token" exception is retrieved.


Delivery receipts

An exposed REST API method "postUpdateStatus" is available through the endpoint DeliveryReceiptCallback whose main goal is to update a notification status through the received request.This callback API only should be used/set up through GOV.UK Notify if you are using the service actions available in the GovUKNotify_CS to store the request/response of the email, SMS and letter sent.

Below are presented the request fields for this API and its definitions:

  • Id

    Notify’s ID for the status receipts.
    Format: UUID

  • To

    The email address or phone number of the recipient.
    Format: hello@gov.uk or 07700912345

  • Reference

    The reference was sent by the service. This reference identifies a single notification or a batch of notifications.
    Format: 12345678 or null

  • Status

    The status of the notification.
    Format: delivered, permanent-failure, temporary-failure or technical-failure

  • CreatedAt

    The time the service sent the request.
    Format: 2017-05-14T12:15:30.000000Z

  • CompletedAt

    The last time the status was updated.
    Format: 2017-05-14T12:15:30.000000Z or null

  • SentAt

    The time the notification was sent.
    Format: 2017-05-14T12:15:30.000000Z or null

  • NotificationType

    The notification type.
    Format: email or SMS

  • TemplateId

    The id of the template that was used.
    Format: UUID

  • TemplateVersion

    The version number of the template that was used.
    Format: 1

 

This API receives a request that will be serialized to JSON and its binary is stored as a record in NotificationToProcess database entity. If the request is successful, the status code of the response is 200.

If you don't want to process the request, a site property DisableUpdateStatus is available whose value "true" allows you to send the status code 200 in the response without the request having been sent for processing.

Being exposed to process events, when a record is created in the NotificationToProcess database entity, a light process execution activity UpdateNotificationActivity is automatically triggered.


Process activity

Before processing the notification status update begins, it's validated that the record exists in the NotificationToProcess entity and its request content is not empty. If any of the sentences fail, the process ends. 

Once a binary request is obtained from the NotificationToProcess entity, it's converted to JSON so that it can be deserialized into the correct structure and sent to the  "ProcessingUpdateNotificationActivity" wrapper so that it can be processed.


Processing update notification activity

This wrapper verifies if the notification to process is not processed yet, using the service action "GetNotificationNotProcessed" of the GovUKNotify_CS module (i.e. if the notification status is empty, created or sending). 

If the notification is not processed yet, its status is updated using the "UpdateNotificationStatus" service action of the GovUKNotify_CS module. However, before that, if the Gov.UK Notify ID of the notification being processed is not stored, it is updated using the "UpdateGovUkNotificationId" service action from the same module. 


Received text messages

If your service receives text messages in Notify, Notify can forward them to your callback URL as soon as they arrive.

Contact the Notify team using the support page or chat with us on Slack to request a unique number for text message replies.

An exposed REST API method "postReceiveSMS" is available through the endpoint ReceiveSMSCallback if you want to store received text messages (SMS) sent by users using your service. 


Below are presented the request fields for this API and its definitions:

  • Id

    Notify’s ID for the received message.
    Format: UUID

  • SourceNumber

    The phone number the message was sent from.
    Format: 07700912345

  • DestinationNumber

    The number the message was sent to (your number).
    Format: 07700987654

  • Message

    The received message.
    Format: Hello Notify!

  • DateReceived

    The UTC datetime that the message was received by Notify.
    Format: 2017-05-14T12:15:30.000000Z

This API receives a request that is saved locally using the service action "SaveSMS" of the GovUKNotify_CS module. If the request is successful, the status code of the response is 200.

If you don't want to process the request, a site property DisableReceiveSMS is available whose value "true" allows you to send the status code 200 in the response without the request having been saved locally.

To get the received text messages saved locally, a service action "GetSMS" of the GovUKNotify_CS module is provided for this purpose.