Documentation Index Fetch the complete documentation index at: https://mintlify.com/alphagov/notifications-api/llms.txt
Use this file to discover all available pages before exploring further.
Generates a preview of a template with personalisation data filled in. This allows you to see what the final message will look like before sending it.
Path Parameters
The UUID of the template to preview
Request Body
Key-value pairs for filling in template placeholders. The keys must match the placeholder names in your template. If your template has no placeholders, you can send an empty request body.
Authentication
Requires an API key with appropriate service permissions.
Response
The type of template. One of:
sms - SMS message template
email - Email template
letter - Letter template
The version number of the template
The template content with personalisation values filled in
The subject line with personalisation values filled in (for email templates only)
The HTML version of the email body with personalisation values filled in (for email templates only)
The postage class for letter templates. One of:
first - First class
second - Second class
economy - Economy class
europe - Europe
rest-of-world - Rest of world
Example Requests
With personalisation
Empty personalisation
No request body (for templates without placeholders)
curl -X POST "https://api.notifications.service.gov.uk/v2/template/f33517ff-2a88-4f6e-b855-c550268ce08a/preview" \
-H "Authorization: Bearer your_api_key_here" \
-H "Content-Type: application/json" \
-d '{
"personalisation": {
"name": "John Smith",
"reference": "REF-12345"
}
}'
Example Responses
Email template
{
"id" : "f33517ff-2a88-4f6e-b855-c550268ce08a" ,
"type" : "email" ,
"version" : 3 ,
"body" : "Hello John Smith, \n\n Your reference number is REF-12345." ,
"subject" : "Your application has been received" ,
"html" : "<p>Hello John Smith,</p><p>Your reference number is REF-12345.</p>" ,
"postage" : null
}
SMS template
{
"id" : "a1b2c3d4-e5f6-4a5b-8c9d-0e1f2a3b4c5d" ,
"type" : "sms" ,
"version" : 1 ,
"body" : "Your security code is 123456. Do not share this code." ,
"subject" : null ,
"html" : null ,
"postage" : null
}
Letter template
{
"id" : "b2c3d4e5-f6a7-4b6c-9d0e-1f2a3b4c5d6e" ,
"type" : "letter" ,
"version" : 2 ,
"body" : "Dear Sarah Jones, \n\n This is to confirm your appointment on 15 March 2024." ,
"subject" : null ,
"html" : null ,
"postage" : "second"
}
Error Responses
Array of error objects describing what went wrong
400 Bad Request - Invalid UUID
Returned when the template ID is not a valid UUID.
{
"status_code" : 400 ,
"errors" : [
{
"error" : "ValidationError" ,
"message" : "id is not a valid UUID"
}
]
}
400 Bad Request - Missing personalisation
Returned when required personalisation fields are missing.
{
"status_code" : 400 ,
"errors" : [
{
"error" : "BadRequestError" ,
"message" : "Missing personalisation: name, reference"
}
]
}
400 Bad Request - Invalid JSON
Returned when the request body is not valid JSON.
{
"status_code" : 400 ,
"errors" : [
{
"error" : "ValidationError" ,
"message" : "Invalid JSON"
}
]
}
403 Forbidden
Returned when the API key doesn’t have permission to access the template.
{
"status_code" : 403 ,
"errors" : [
{
"error" : "AuthError" ,
"message" : "Invalid token: service not found"
}
]
}
404 Not Found
Returned when the template doesn’t exist.
{
"status_code" : 404 ,
"errors" : [
{
"error" : "NoResultFound" ,
"message" : "No result found"
}
]
}