2016-04-04 14:37:35 +01:00
About this document
2016-04-04 13:42:41 +01:00
==========================
2016-04-12 10:19:25 +01:00
This document is for public sector [?] developers, technical architects, and service managers who want to use the GOV.UK Notify platform to send notifications to users of their digital service.
2016-04-04 13:42:41 +01:00
About GOV.UK Notify
====================
2016-04-05 10:17:18 +01:00
GOV.UK Notify is a cross-government platform, currently in beta, that lets government services and agencies [?] send notifications by sms or email.
2016-04-04 13:42:41 +01:00
There are two ways to send notifications:
2016-04-05 10:17:18 +01:00
* use the [GOV.UK Notify ](https://www.notifications.service.gov.uk/ ) web application
2016-04-12 09:21:34 +01:00
* [integrate your web applications or back office systems ](#integrateNotify ) with the GOV.UK Notify API
2016-04-04 13:42:41 +01:00
To find out more about GOV.UK Notify, see the [Government as a Platform ](https://governmentasaplatform.blog.gov.uk/ ) blog.
Before you start
==================
To use GOV.UK Notify, you need:
2016-04-05 10:17:18 +01:00
2016-04-04 13:42:41 +01:00
* an email address from a local or central government organisation
* a mobile number for 2-factor authentication
Quick start guide to GOV.UK Notify
===================================
2016-04-05 10:17:18 +01:00
To get started:
2016-04-04 13:42:41 +01:00
1. Register for a [GOV.UK Notify ](https://www.notifications.service.gov.uk/ ) account. You will need your mobile phone for 2-factor authentication.
2016-04-05 10:17:18 +01:00
2. Add a new service.
2016-04-04 13:42:41 +01:00
2016-04-12 13:09:18 +01:00
At first your service will be in trial mode. In trial mode you will only be able to send test sms and email notifications to your own mobile number or email address. When you’ re fully integrated and ready to go live, send a request to the GOV.UK Notify team.
2016-04-04 13:42:41 +01:00
2016-04-05 10:17:18 +01:00
3. Add a template so you can send sms and email notifications. You can personalise the template using double brackets for replaceables. For example:
2016-04-04 13:42:41 +01:00
Dear ((name))
2016-04-05 10:17:18 +01:00
Your ((item)) will expire on ((date)).
2016-04-04 13:42:41 +01:00
2016-04-06 10:12:51 +01:00
4. Upload a csv file containing a header row with the replaceables in your template, and data rows with values for the replaceables.
2016-04-04 13:42:41 +01:00
5. Send an sms or email notification.
2016-04-04 14:37:35 +01:00
6. Create a new API key. This will be used to connect to the API.
2016-04-05 10:17:18 +01:00
You can provide all your developers with test keys so they can experiment in the Sandbox environment. But keep the number of keys for real integrations to a minimum number of people on your team.
2016-04-04 14:37:35 +01:00
2016-04-12 13:26:47 +01:00
<a name="integrateNotify"></a>
2016-04-12 13:12:30 +01:00
Integrate the GOV.UK Notify API into your service
===================================================
2016-04-04 13:42:41 +01:00
2016-04-12 13:31:56 +01:00
GOV.UK Notify provides an API that allows you to create text and email notifications and get the status of notifications you have sent.
2016-04-11 15:33:56 +01:00
API integration
------------------
2016-04-04 14:37:35 +01:00
2016-04-11 12:15:38 +01:00

2016-04-11 09:31:24 +01:00
There are two ways to integrate the API into your service:
2016-04-12 13:21:14 +01:00
* use a client library provided by GOV.UK Notify - there is currently a [python library ](https://github.com/alphagov/notifications-python-client ) and more will be added in different languages
2016-04-11 15:33:56 +01:00
* develop your own integration to produce requests in the correct format
2016-04-11 09:31:24 +01:00
2016-04-12 13:31:56 +01:00
GOV.UK Notify uses [JWT tokens ](https://jwt.io/ ) for authentication and identification. JWT tokens are built into the GOV.UK Notify client library. If you don't use this library, you must manually create tokens yourself.
2016-04-06 15:44:02 +01:00
2016-04-11 15:33:56 +01:00
A JWT token contains, in encrypted format:
* your service ID - identifies your service
2016-04-12 10:19:25 +01:00
* your API key (in JWT token terms this is called the client ID) - used to sign tokens during requests for API resources
2016-04-11 16:16:38 +01:00
* an indication of what you're trying to do - GET, POST, etc.
2016-04-11 15:33:56 +01:00
* the endpoint you're trying to access
2016-04-06 15:44:02 +01:00
2016-04-11 15:33:56 +01:00
Use the [GOV.UK Notify ](https://www.notifications.service.gov.uk/ ) web application to find your service ID and create API keys.
2016-04-06 15:44:02 +01:00
2016-04-11 16:16:38 +01:00
**Important:** API keys are secret, so save them somewhere safe. Do not commit API keys to public source code repositories.
2016-04-04 13:42:41 +01:00
2016-04-12 09:58:09 +01:00
API client libraries
------------------
GOV.UK Notify supports a python client library:
[GOV.UK Notify Python client ](https://github.com/alphagov/notifications-python-client )
This provides example code for calling the API and for constructing the API tokens [are they not built in?].
2016-04-11 16:27:23 +01:00
[Information below needs to be expanded]
2016-04-12 10:19:25 +01:00
-----------------------------------------
2016-04-11 16:27:23 +01:00
JWT tokens have a series of standard and application-specific claims.
GOV.UK Notify standard claims:
```
{
"typ": "JWT",
"alg": "HS256"
}
```
GOV.UK Notify application-specific claims:
```
{
iss: 'string', // service id
iat: 0, // creation time in epoch seconds (UTC)
req: 'string', // signed request
pay: 'string', // signed payload (POST requests only)
}
```
2016-04-12 09:58:09 +01:00
GOV.UK Notify API tokens sign both the request being made, and for POST requests, the payload.
2016-04-11 16:27:23 +01:00
The signing algorithm is HMAC signature, using provided key SHA256 hashing algorithm.
Request signing is of the form HTTP METHOD PATH.
```
GET /notification/1234
```
Payload signing requires the actual payload to be signed, NOT the JSON object. Serialize the object first then sign the serialized object.
2016-04-04 13:42:41 +01:00
API endpoints
----------------
2016-04-12 13:21:14 +01:00
You can use the GOV.UK Notify API to:
2016-04-06 15:44:02 +01:00
* send a notification
* retrieve one notification
2016-04-04 14:37:35 +01:00
* retrieve all notifications
2016-04-05 10:17:18 +01:00
To send a text notification:
2016-04-04 14:37:35 +01:00
```
POST /notifications/sms
```
```
{
'to': '+447700900404',
2016-04-06 15:44:02 +01:00
'template': 1,
'personalisation': {
'name': 'myname',
'date': '2016'
}
2016-04-04 14:37:35 +01:00
}
```
2016-04-06 15:44:02 +01:00
To send an email notification:
```
POST /notifications/email
```
```
{
'to': 'email@gov .uk',
'template': 1,
'personalisation': {
'name': 'myname',
'date': '2016'
}
}
```
2016-04-11 16:16:38 +01:00
where:
2016-04-12 13:31:56 +01:00
* `to` is the phone number (required)
* `template` is the template ID to send (required)
* `personalisation` (optional) specifies the replaceables [where do these come from, the csv file?]
2016-04-11 16:16:38 +01:00
2016-04-12 13:21:14 +01:00
<a id="coderesponse"></a>
2016-04-11 16:16:38 +01:00
The response will be:
```
{
'data':{
'notification': {
'id':1
}
}
}
```
2016-04-06 15:44:02 +01:00
To retrieve the status of a single text or email notification:
2016-04-04 14:37:35 +01:00
```
GET /notifications/{id}
```
```
{
'data':{
'notification': {
'status':'sent',
'createdAt':'2016-01-01T09:00:00.999999Z',
'to':'+447827992607',
'method':'sms',
'sentAt':'2016-01-01T09:01:00.999999Z',
'id':1,
'message':'...',
2016-04-11 15:33:56 +01:00
'job_id':1,
2016-04-04 14:37:35 +01:00
'sender':'sms-partner'
}
}
}
```
2016-04-12 13:21:14 +01:00
where:
2016-04-12 13:31:56 +01:00
* `status` is the the status of the notification; this can be `sending` , `delivered` , `failed` [change status in message above?]
* `method` is `sms` or `email`
* `job_id` is the unique identifier for the process of sending [change to retrieving?] the notification
* `message` is the content of message
* `sender` may be the provider [?]
2016-04-06 15:44:02 +01:00
2016-04-12 13:21:14 +01:00
The above fields are populated once the message has been processed; initially you get back the [response ](#coderesponse ) indicated above.
2016-04-06 15:44:02 +01:00
To get the status of all notifications:
```
GET /notifications
```
```
{
'data':[{
'notification': {
'status':'sent',
'createdAt':'2016-01-01T09:00:00.999999Z',
'to':'+447827992607',
'method':'sms',
'sentAt':'2016-01-01T09:01:00.999999Z',
'id':1,
'message':'...',
'jobId':1,
'sender':'sms-partner'
}
},
{
'notification': {
'status':'sent',
'createdAt':'2016-01-01T09:00:00.999999Z',
'to':'+447827992607',
'method':'email',
'sentAt':'2016-01-01T09:01:00.999999Z',
'id':1,
'message':'...',
'jobId':1,
'sender':'email-partner'
}
}...]
}
```
2016-04-11 16:16:38 +01:00
This list is split into pages. To scroll through the pages run:
2016-04-04 14:37:35 +01:00
2016-04-06 15:44:02 +01:00
```
GET /notifications?&page=2
```
2016-04-04 14:37:35 +01:00
2016-04-12 09:58:09 +01:00
GOV.UK Notify API code
2016-04-12 10:19:25 +01:00
------------------------
2016-04-12 09:58:09 +01:00
2016-04-12 10:19:25 +01:00
The GOV.UK Notify API code is open sourced at:
2016-04-12 09:58:09 +01:00
[GOV.UK Notify API ](https://github.com/alphagov/notifications-api )
2016-04-04 13:42:41 +01:00
Functional testing
---------------------
[Some info in Rosalie’ s notes.]
2016-04-05 10:17:18 +01:00
2016-04-04 13:42:41 +01:00
Security
----------
[Some info in Rosalie’ s notes.]
Privacy
--------