public class NotificationClient extends Object implements NotificationClientApi
| Constructor and Description |
|---|
NotificationClient(String apiKey)
This client constructor given the api key.
|
NotificationClient(String apiKey,
Proxy proxy)
Use this client constructor if you require a proxy for https requests.
|
NotificationClient(String apiKey,
String baseUrl)
This client constructor is used for testing on other environments, used by the GOV.UK Notify team.
|
NotificationClient(String apiKey,
String baseUrl,
Proxy proxy) |
NotificationClient(String apiKey,
String baseUrl,
Proxy proxy,
SSLContext sslContext) |
| Modifier and Type | Method and Description |
|---|---|
TemplatePreview |
generateTemplatePreview(String templateId,
Map<String,Object> personalisation)
The generateTemplatePreview returns a template with the placeholders replaced with the given personalisation.
|
TemplateList |
getAllTemplates(String templateType)
Returns all the templates for your service.
|
String |
getApiKey() |
String |
getBaseUrl() |
Notification |
getNotificationById(String notificationId)
The getNotificationById method will return a
Notification for a given notification id. |
NotificationList |
getNotifications(String status,
String notification_type,
String reference,
String olderThanId)
The getNotifications method will create a GET HTTPS request to retrieve all the notifications.
|
byte[] |
getPdfForLetter(String notificationId)
The getPdfForLetter method will return a
byte[] containing the PDF contents of a given letter notification. |
Proxy |
getProxy() |
ReceivedTextMessageList |
getReceivedTextMessages(String olderThanId)
The getReceivedTextMessages returns a list of
ReceivedTextMessage, the list is sorted by createdAt descending. |
String |
getServiceId() |
Template |
getTemplateById(String templateId)
The getTemplateById returns a
Template given the template id. |
Template |
getTemplateVersion(String templateId,
int version)
The getTemplateVersion returns a
Template given the template id and version. |
String |
getUserAgent() |
static org.json.JSONObject |
prepareUpload(byte[] documentContents)
Use the prepareUpload method when uploading a document via sendEmail.
|
SendEmailResponse |
sendEmail(String templateId,
String emailAddress,
Map<String,?> personalisation,
String reference)
The sendEmail method will create an HTTPS POST request.
|
SendEmailResponse |
sendEmail(String templateId,
String emailAddress,
Map<String,?> personalisation,
String reference,
String emailReplyToId)
The sendEmail method will create an HTTPS POST request.
|
SendLetterResponse |
sendLetter(String templateId,
Map<String,?> personalisation,
String reference)
The sendLetter method will create an HTTPS POST request.
|
LetterResponse |
sendPrecompiledLetter(String reference,
File precompiledPDF)
The sendPrecompiledLetter method will create an HTTPS POST request.
|
LetterResponse |
sendPrecompiledLetter(String reference,
File precompiledPDF,
String postage)
The sendPrecompiledLetter method will create an HTTPS POST request.
|
LetterResponse |
sendPrecompiledLetterWithInputStream(String reference,
InputStream stream)
The sendPrecompiledLetterWithInputStream method will create an HTTPS POST request.
|
LetterResponse |
sendPrecompiledLetterWithInputStream(String reference,
InputStream stream,
String postage)
The sendPrecompiledLetterWithInputStream method will create an HTTPS POST request.
|
SendSmsResponse |
sendSms(String templateId,
String phoneNumber,
Map<String,?> personalisation,
String reference)
The sendSms method will create an HTTPS POST request.
|
SendSmsResponse |
sendSms(String templateId,
String phoneNumber,
Map<String,?> personalisation,
String reference,
String smsSenderId)
The sendSms method will create an HTTPS POST request.
|
public NotificationClient(String apiKey)
apiKey - Generate an API key by signing in to GOV.UK Notify, https://www.notifications.service.gov.uk, and going to the **API integration** pagepublic NotificationClient(String apiKey, Proxy proxy)
apiKey - Generate an API key by signing in to GOV.UK Notify, https://www.notifications.service.gov.uk, and going to the **API integration** pageproxy - Proxy used on the http requestspublic NotificationClient(String apiKey, String baseUrl)
apiKey - Generate an API key by signing in to GOV.UK Notify, https://www.notifications.service.gov.uk, and going to the **API integration** pagebaseUrl - base URL, defaults to https://api.notifications.service.gov.ukpublic NotificationClient(String apiKey, String baseUrl, Proxy proxy)
apiKey - Generate an API key by signing in to GOV.UK Notify, https://www.notifications.service.gov.uk, and going to the **API integration** pagebaseUrl - base URL, defaults to https://api.notifications.service.gov.ukproxy - Proxy used on the http requestspublic NotificationClient(String apiKey, String baseUrl, Proxy proxy, SSLContext sslContext)
public String getUserAgent()
public String getApiKey()
public String getServiceId()
public String getBaseUrl()
public Proxy getProxy()
public SendEmailResponse sendEmail(String templateId, String emailAddress, Map<String,?> personalisation, String reference) throws NotificationClientException
NotificationClientApisendEmail in interface NotificationClientApitemplateId - The template id is visible on the template page in the application.emailAddress - The email addresspersonalisation - Map representing the placeholders for the template if any. For example, key=name value=Bob
Can be an empty map or null when the template does not require placeholders.reference - A reference specified by the service for the notification. Get all notifications can be filtered by this reference.
This reference can be unique or used used to refer to a batch of notifications.
Can be an empty string or null, when you do not require a reference for the notifications.SendEmailResponseNotificationClientException - see https://docs.notifications.service.gov.uk/java.html#send-an-email-error-codespublic SendEmailResponse sendEmail(String templateId, String emailAddress, Map<String,?> personalisation, String reference, String emailReplyToId) throws NotificationClientException
NotificationClientApisendEmail in interface NotificationClientApitemplateId - The template id is visible on the template page in the application.emailAddress - The email addresspersonalisation - Map representing the placeholders for the template if any. For example, key=name value=Bob
Can be an empty map or null when the template does not require placeholders.reference - A reference specified by the service for the notification. Get all notifications can be filtered by this reference.
This reference can be unique or used used to refer to a batch of notifications.
Can be an empty string or null, when you do not require a reference for the notifications.emailReplyToId - An optional identifier for a reply to email address for the notification, rather than use the service default.
Service emailReplyToIds can be accessed via the service settings / manage email reply to addresses page.
Omit this argument to use the default service email reply to address.SendEmailResponseNotificationClientException - see https://docs.notifications.service.gov.uk/java.html#send-an-email-error-codespublic SendSmsResponse sendSms(String templateId, String phoneNumber, Map<String,?> personalisation, String reference) throws NotificationClientException
NotificationClientApisendSms in interface NotificationClientApitemplateId - The template id is visible from the template page in the application.phoneNumber - The mobile phone numberpersonalisation - Map representing the placeholders for the template if any. For example, key=name value=Bob
Can be an empty map or null when the template does not require placeholders.reference - A reference specified by the service for the notification. Get all notifications can be filtered by this reference.
This reference can be unique or used used to refer to a batch of notifications.
Can be an empty string or null, when you do not require a reference for the notifications.SendSmsResponseNotificationClientException - see https://docs.notifications.service.gov.uk/java.html#error-codespublic SendSmsResponse sendSms(String templateId, String phoneNumber, Map<String,?> personalisation, String reference, String smsSenderId) throws NotificationClientException
NotificationClientApisendSms in interface NotificationClientApitemplateId - The template id is visible from the template page in the application.phoneNumber - The mobile phone numberpersonalisation - Map representing the placeholders for the template if any. For example, key=name value=Bob
Can be an empty map or null when the template does not require placeholders.reference - A reference specified by the service for the notification. Get all notifications can be filtered by this reference.
This reference can be unique or used used to refer to a batch of notifications.
Can be an empty string or null, when you do not require a reference for the notifications.smsSenderId - An optional identifier for the text message sender of the notification, rather than use the service default.
Service smsSenderIds can be accessed via the service settings / manage text message senders page.
Omit this argument to use the default service text message sender.SendSmsResponseNotificationClientException - see https://docs.notifications.service.gov.uk/java.html#error-codespublic SendLetterResponse sendLetter(String templateId, Map<String,?> personalisation, String reference) throws NotificationClientException
NotificationClientApisendLetter in interface NotificationClientApitemplateId - Find templateId by clicking API info for the template you want to sendpersonalisation - Map representing the placeholders for the template if any. For example, key=name value=Bob.
Must include the keys "address_line_1", "address_line_2" and "postcode".reference - A reference specified by the service for the notification. Get all notifications can be filtered by this reference.
This reference can be unique or used used to refer to a batch of notifications.
Can be an empty string or null, when you do not require a reference for the notifications.SendLetterResponseNotificationClientException - see https://docs.notifications.service.gov.uk/java.html#send-a-letter-error-codespublic Notification getNotificationById(String notificationId) throws NotificationClientException
NotificationClientApiNotification for a given notification id.
The id can be retrieved from the NotificationResponse of a sendEmail, sendLetter or sendSms request.getNotificationById in interface NotificationClientApinotificationId - The id of the notification.NotificationNotificationClientException - see https://docs.notifications.service.gov.uk/java.html#get-the-status-of-one-message-error-codespublic byte[] getPdfForLetter(String notificationId) throws NotificationClientException
NotificationClientApibyte[] containing the PDF contents of a given letter notification.
The id can be retrieved from the NotificationResponse of a sendLetter.getPdfForLetter in interface NotificationClientApinotificationId - The id of the notification.byte[] The raw pdf data.NotificationClientException - see https://docs.notifications.service.gov.uk/java.html#get-a-pdf-for-a-letter-notification-error-codespublic NotificationList getNotifications(String status, String notification_type, String reference, String olderThanId) throws NotificationClientException
NotificationClientApigetNotifications in interface NotificationClientApistatus - If status is not empty or null notifications will only return notifications for the given status.
Possible statuses are created|sending|delivered|permanent-failure|temporary-failure|technical-failurenotification_type - If notification_type is not empty or null only notifications of the given status will be returned.
Possible notificationTypes are sms|emailreference - If reference is not empty or null only the notifications with that reference are returned.olderThanId - If olderThanId is not empty or null only the notifications older than that notification id are returned.NotificationListNotificationClientException - see https://docs.notifications.service.gov.uk/java.html#get-the-status-of-multiple-messages-error-codespublic Template getTemplateById(String templateId) throws NotificationClientException
NotificationClientApiTemplate given the template id.getTemplateById in interface NotificationClientApitemplateId - The template id is visible on the template page in the application.TemplateNotificationClientException - see https://docs.notifications.service.gov.uk/java.html#get-a-template-by-id-error-codespublic Template getTemplateVersion(String templateId, int version) throws NotificationClientException
NotificationClientApiTemplate given the template id and version.getTemplateVersion in interface NotificationClientApitemplateId - The template id is visible on the template page in the application.version - The version of the template to returnTemplateNotificationClientException - see https://docs.notifications.service.gov.uk/java.html#get-a-template-by-id-and-version-error-codespublic TemplateList getAllTemplates(String templateType) throws NotificationClientException
NotificationClientApigetAllTemplates in interface NotificationClientApitemplateType - If templateType is not empty or null templates will be filtered by type.
Possible template types are email|sms|letterTemplateListNotificationClientException - see https://docs.notifications.service.gov.uk/java.html#get-a-template-by-id-error-codespublic TemplatePreview generateTemplatePreview(String templateId, Map<String,Object> personalisation) throws NotificationClientException
NotificationClientApigenerateTemplatePreview in interface NotificationClientApitemplateId - The template id is visible from the template page in the application.personalisation - Map representing the placeholders for the template if any. For example, key=name value=Bob
Can be an empty map or null when the template does not require placeholders.TemplateNotificationClientException - see https://docs.notifications.service.gov.uk/java.html#generate-a-preview-template-error-codespublic ReceivedTextMessageList getReceivedTextMessages(String olderThanId) throws NotificationClientException
NotificationClientApiReceivedTextMessage, the list is sorted by createdAt descending.getReceivedTextMessages in interface NotificationClientApiolderThanId - If olderThanId is not empty or null only the received text messages older than that id are returned.ReceivedTextMessageListNotificationClientExceptionpublic static org.json.JSONObject prepareUpload(byte[] documentContents)
throws NotificationClientException
JSONObject which will need to be added to the personalisation map.documentContents - byte[] of the documentJSONObject a json object to be added to the personalisation is returnedNotificationClientExceptionpublic LetterResponse sendPrecompiledLetter(String reference, File precompiledPDF) throws NotificationClientException
NotificationClientApisendPrecompiledLetter in interface NotificationClientApireference - A reference specified by the service for the notification. Get all notifications can be filtered by this reference.
This reference can be unique or used used to refer to a batch of notifications.
Cannot be an empty string or null for precompiled PDF files.precompiledPDF - A file containing a PDF conforming to the Notify standards for printing.
The file must be a PDF and cannot be null.LetterResponseNotificationClientException - see https://docs.notifications.service.gov.uk/java.html#send-a-precompiled-letter-error-codespublic LetterResponse sendPrecompiledLetter(String reference, File precompiledPDF, String postage) throws NotificationClientException
NotificationClientApisendPrecompiledLetter in interface NotificationClientApireference - A reference specified by the service for the notification. Get all notifications can be filtered by this reference.
This reference can be unique or used used to refer to a batch of notifications.
Cannot be an empty string or null for precompiled PDF files.precompiledPDF - A file containing a PDF conforming to the Notify standards for printing.
The file must be a PDF and cannot be null.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 in this argument, the postage will default to second class.LetterResponseNotificationClientException - see https://docs.notifications.service.gov.uk/java.html#send-a-precompiled-letter-error-codespublic LetterResponse sendPrecompiledLetterWithInputStream(String reference, InputStream stream) throws NotificationClientException
NotificationClientApisendPrecompiledLetterWithInputStream in interface NotificationClientApireference - A reference specified by the service for the notification. Get all notifications can be filtered by this reference.
This reference can be unique or used used to refer to a batch of notifications.
Cannot be an empty string or null for precompiled PDF files.stream - An InputStream conforming to the Notify standards for printing.
The InputStream cannot be null.LetterResponseNotificationClientException - see https://docs.notifications.service.gov.uk/java.html#send-a-precompiled-letter-error-codespublic LetterResponse sendPrecompiledLetterWithInputStream(String reference, InputStream stream, String postage) throws NotificationClientException
NotificationClientApisendPrecompiledLetterWithInputStream in interface NotificationClientApireference - A reference specified by the service for the notification. Get all notifications can be filtered by this reference.
This reference can be unique or used used to refer to a batch of notifications.
Cannot be an empty string or null for precompiled PDF files.stream - An InputStream conforming to the Notify standards for printing.
The InputStream cannot be null.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 in this argument, the postage will default to second class.LetterResponseNotificationClientException - see https://docs.notifications.service.gov.uk/java.html#send-a-precompiled-letter-error-codesCopyright © 2019. All rights reserved.