Product
Introducing Enhanced Alert Actions and Triage Functionality
Socket now supports four distinct alert actions instead of the previous two, and alert triaging allows users to override the actions taken for all individual alerts.
notifications-node-client
Advanced tools
Changelog
[3.2.0] - 2017-09-22
setProxy(proxyUrl)
- specify the URL of a proxy for the client to use (optional)Readme
npm install --save notifications-node-client
var NotifyClient = require('notifications-node-client').NotifyClient,
notifyClient = new NotifyClient(apiKey);
Generate an API key by logging in to GOV.UK Notify and going to the API integration page.
notifyClient.setProxy(proxyUrl);
notifyClient
.sendSms(templateId, phoneNumber, personalisation, reference)
.then(response => console.log(response))
.catch(err => console.error(err))
;
If the request is successful, response
will be a Dictionary
:
{
"id": "bfb50d92-100d-4b8b-b559-14fa3b091cda",
"reference": None,
"content": {
"body": "Some words",
"from_number": "40604"
},
"uri": "https://api.notifications.service.gov.uk/v2/notifications/ceb50d92-100d-4b8b-b559-14fa3b091cd",
"template": {
"id": "ceb50d92-100d-4b8b-b559-14fa3b091cda",
"version": 1,
"uri": "https://api.notifications.service.gov.uk/v2/templates/bfb50d92-100d-4b8b-b559-14fa3b091cda"
}
}
Otherwise the client will return an error err
:
`err.error.status_code` | `err.error.errors` |
---|---|
429 |
[{ "error": "RateLimitError", "message": "Exceeded rate limit for key type TEAM of 10 requests per 10 seconds" }] |
429 |
[{ "error": "TooManyRequestsError", "message": "Exceeded send limits (50) for today" }] |
400 |
[{ "error": "BadRequestError", "message": "Can"t send to this recipient using a team-only API key" ]} |
400 |
[{ "error": "BadRequestError", "message": "Can"t send to this recipient when service is in trial mode - see https://www.notifications.service.gov.uk/trial-mode" }] |
notifyClient
.sendEmail(templateId, emailAddress, personalisation, reference)
.then(response => console.log(response))
.catch(err => console.error(err))
;
If the request is successful, response
will be a Dictionary
:
{
"id": "bfb50d92-100d-4b8b-b559-14fa3b091cda",
"reference": None,
"content": {
"subject": "Licence renewal",
"body": "Dear Bill, your licence is due for renewal on 3 January 2016.",
"from_email": "the_service@gov.uk"
},
"uri": "https://api.notifications.service.gov.uk/v2/notifications/ceb50d92-100d-4b8b-b559-14fa3b091cd",
"template": {
"id": "ceb50d92-100d-4b8b-b559-14fa3b091cda",
"version": 1,
"uri": "https://api.notificaitons.service.gov.uk/service/your_service_id/templates/bfb50d92-100d-4b8b-b559-14fa3b091cda"
}
}
Otherwise the client will return an error err
:
`err.error.status_code` | `err.error.errors` |
---|---|
429 |
[{ "error": "RateLimitError", "message": "Exceeded rate limit for key type TEAM of 10 requests per 10 seconds" }] |
429 |
[{ "error": "TooManyRequestsError", "message": "Exceeded send limits (50) for today" }] |
400 |
[{ "error": "BadRequestError", "message": "Can"t send to this recipient using a team-only API key" ]} |
400 |
[{ "error": "BadRequestError", "message": "Can"t send to this recipient when service is in trial mode - see https://www.notifications.service.gov.uk/trial-mode" }] |
templateId
Find by clicking API info for the template you want to send.
personalisation
If a template has placeholders you need to provide their values. For example:
personalisation={
'first_name': 'Amala',
'reference_number': '300241',
}
Otherwise the parameter can be omitted or undefined
can be passed in its place.
reference
An optional identifier you generate if you don’t want to use Notify’s id
. It can be used to identify a single notification or a batch of notifications.
notifyClient
.getNotificationById(notificationId)
.then((response) => { })
.catch((err) => {})
;
If the request is successful, response
will be a Dictionary
:
{
"id": "notify_id",
"body": "Hello Foo",
"subject": "null|email_subject",
"reference": "client reference",
"email_address": "email address",
"phone_number": "phone number",
"line_1": "full name of a person or company",
"line_2": "123 The Street",
"line_3": "Some Area",
"line_4": "Some Town",
"line_5": "Some county",
"line_6": "Something else",
"postcode": "postcode",
"type": "sms|letter|email",
"status": "current status",
"template": {
"version": 1,
"id": 1,
"uri": "/template/{id}/{version}"
},
"created_at": "created at",
"sent_at": "sent to provider at",
}
Otherwise the client will return an error err
:
`err.error.status_code` | `err.error.errors` |
---|---|
404 |
[{ "error": "NoResultFound", "message": "No result found" }] |
400 |
[{ "error": "ValidationError", "message": "id is not a valid UUID" }] |
notifyClient
.getNotifications(templateType, status, reference, olderThan)
.then((response) => { })
.catch((err) => {})
;
If the request is successful, response
will be a Dictionary
:
{ "notifications":
[{
"id": "notify_id",
"reference": "client reference",
"email_address": "email address",
"phone_number": "phone number",
"line_1": "full name of a person or company",
"line_2": "123 The Street",
"line_3": "Some Area",
"line_4": "Some Town",
"line_5": "Some county",
"line_6": "Something else",
"postcode": "postcode",
"type": "sms | letter | email",
"status": sending | delivered | permanent-failure | temporary-failure | technical-failure
"template": {
"version": 1,
"id": 1,
"uri": "/template/{id}/{version}"
},
"created_at": "created at",
"sent_at": "sent to provider at",
},
…
],
"links": {
"current": "/notifications?template_type=sms&status=delivered",
"next": "/notifications?other_than=last_id_in_list&template_type=sms&status=delivered"
}
}
Otherwise the client will return an error err
:
`err.error.status_code` | `err.error.errors` |
---|---|
400 |
[{ 'error': 'ValidationError', 'message': 'bad status is not one of [created, sending, delivered, pending, failed, technical-failure, temporary-failure, permanent-failure]' }] |
400 |
[{ "error": "ValidationError", "message": "Apple is not one of [sms, email, letter]" }] |
templateType
If omitted all messages are returned. Otherwise you can filter by:
email
sms
letter
status
If omitted all messages are returned. Otherwise you can filter by:
sending
- the message is queued to be sent by the provider.delivered
- the message was successfully delivered.failed
- this will return all failure statuses permanent-failure
, temporary-failure
and technical-failure
.permanent-failure
- the provider was unable to deliver message, email or phone number does not exist; remove this recipient from your list.temporary-failure
- the provider was unable to deliver message, email box was full or the phone was turned off; you can try to send the message again.technical-failure
- Notify had a technical failure; you can try to send the message again.reference
This is the reference
you gave at the time of sending the notification. This can be omitted to ignore the filter.
olderThan
If omitted all messages are returned. Otherwise you can filter to retrieve all notifications older than the given notification id
.
notifyClient
.getTemplateById(templateId)
.then((response) => { })
.catch((err) => {})
;
If the request is successful, response
will be a Dictionary
:
{
"id": "template_id",
"type": "sms|email|letter",
"created_at": "created at",
"updated_at": "updated at",
"version": "version",
"created_by": "someone@example.com",
"body": "body",
"subject": "null|email_subject"
}
Otherwise the client will return an error err
:
`err.error.status_code` | `err.error.errors` |
---|---|
404 |
[{ "error": "NoResultFound", "message": "No result found" ]} |
templateId
Find by clicking API info for the template you want to send.
notifyClient
.getTemplateByIdAndVersion(templateId, version)
.then((response) => { })
.catch((err) => {})
;
If the request is successful, response
will be a Dictionary
:
{
"id": "template_id",
"type": "sms|email|letter",
"created_at": "created at",
"updated_at": "updated at",
"version": "version",
"created_by": "someone@example.com",
"body": "body",
"subject": "null|email_subject"
}
Otherwise the client will return an error err
:
`err.error.status_code` | `err.error.errors` |
---|---|
404 |
[{ "error": "NoResultFound", "message": "No result found" ]} |
templateId
Find by clicking API info for the template you want to send.
version
The version number of the template
notifyClient
.getAllTemplates(templateType)
.then((response) => { })
.catch((err) => {})
;
This will return the latest version for each template
If the request is successful, response
will be a Dictionary
:
{
"templates" : [
{
"id": "template_id",
"type": "sms|email|letter",
"created_at": "created at",
"updated_at": "updated at",
"version": "version",
"created_by": "someone@example.com",
"body": "body",
"subject": "null|email_subject"
},
{
... another template
}
]
}
If no templates exist for a template type or there no templates for a service, the response
will be a Dictionary
with an empty templates
list element:
{
"templates" : []
}
templateType
If omitted all messages are returned. Otherwise you can filter by:
email
sms
letter
personalisation = { "foo": "bar" };
notifyClient
.previewTemplateById(templateId, personalisation)
.then((response) => { })
.catch((err) => {})
;
If the request is successful, response
will be a Dictionary
:
{
"id": "notify_id",
"type": "sms|email|letter",
"version": "version",
"body": "Hello bar" // with substitution values,
"subject": "null|email_subject"
}
Otherwise the client will return an error err
:
`err.error.status_code` | `err.error.errors` |
---|---|
400 |
[{ "error": "BadRequestError", "message": "Missing personalisation: [name]" ]} |
404 |
[{ "error": "NoResultFound", "message": "No result found" ]} |
templateId
Find by clicking API info for the template you want to send.
personalisation
If a template has placeholders you need to provide their values. For example:
personalisation={
'first_name': 'Amala',
'reference_number': '300241',
}
Otherwise the parameter can be omitted or undefined
can be passed in its place.
There are unit and integration tests that can be run to test functionality of the client. You will need to have the relevant environment variables sourced to run the tests.
To run the unit tests:
npm test
To run the integration tests:
npm test --integration
FAQs
GOV.UK Notify Node.js client
The npm package notifications-node-client receives a total of 4,676,886 weekly downloads. As such, notifications-node-client popularity was classified as popular.
We found that notifications-node-client demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket now supports four distinct alert actions instead of the previous two, and alert triaging allows users to override the actions taken for all individual alerts.
Security News
Polyfill.io has been serving malware for months via its CDN, after the project's open source maintainer sold the service to a company based in China.
Security News
OpenSSF is warning open source maintainers to stay vigilant against reputation farming on GitHub, where users artificially inflate their status by manipulating interactions on closed issues and PRs.