Skip to content

Latest commit

 

History

History
787 lines (541 loc) · 30.4 KB

DOCUMENTATION.md

File metadata and controls

787 lines (541 loc) · 30.4 KB

Java client documentation

This documentation is for developers interested in using the VANotify Java client to send emails, text messages or letters.

Set up the client

Install the client

The vanotify-java-client artifacts are stored in github packages.

Go to the VANotify Java client maven packages on github [external link]:

  1. Select the most recent version.
  2. Copy the dependency configuration snippet for your build tool.

Refer to the client changelog for the version number and the latest updates.

Create a new instance of the client

Add this code to your application:

import gov.va.vanotify.NotificationClient;
NotificationClient client = new NotificationClient(apiKey);

To get an API key, sign in to VANotify and go to the API integration page. You can find more information in the API keys section of this documentation.

If you use a proxy you can pass it into the NotificationClient constructor.

import gov.va.vanotify.NotificationClient;
NotificationClient client = new NotificationClient(apiKey, proxy);

Send a message

You can use VANotify to send text messages and emails.

Send a text message

Method

SendSmsResponse response = client.sendSms(
    templateId,
    phoneNumber,
    personalisation,
    reference,
    smsSenderId,
    billingCode
);

Arguments

templateId (required)

To find the template ID:

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

For example:

String templateId="f33517ff-2a88-4f6e-b855-c550268ce08a";
phoneNumber (required)

The phone number of the recipient of the text message. This number can be a US or international number.

String phoneNumber="+16132532222";
personalisation (required)

If a template has placeholder fields for personalised information such as name or reference number, you must provide their values in a map. For example:

Map<String, Object> personalisation = new HashMap<>();
personalisation.put("first_name", "Amala");
personalisation.put("application_date", "2018-01-01");
personalisation.put("list", listOfItems); // Will appear as a comma separated list in the message

If a template does not have any placeholder fields for personalised information, you must pass in an empty map or null.

reference (required)

A unique identifier you create. This reference identifies a single unique notification or a batch of notifications. It must not contain any personal information such as name or postal address. If you do not have a reference, you must pass in an empty string or null.

String reference='STRING';
smsSenderId (optional)

A unique identifier of the sender of the text message notification.

To find the text message sender:

  1. Sign in to VANotify.

You can then either:

  • copy the sender ID that you want to use and paste it into the method
  • select Change to change the default sender that the service will use, and select Save
String smsSenderId='8e222534-7f05-4972-86e3-17c5d9f894e2'

You can leave out this argument if your service only has one text message sender, or if you want to use the default sender.

billingCode (optional)

A string that represents a billing code under which a notification will be reported. This can be used to group notifications of the same template in billing reports.

String billingCode='some-billing-code'

You can leave out this argument if you don't need to group notifications with billing codes.

Response

If the request to the client is successful, the client returns a SendSmsResponse:

UUID notificationId;
Optional<String> reference;
UUID templateId;
int templateVersion;
String templateUri;
String body;
Optional<String> fromNumber;
Optional<String> billingCode;

If you are using the test API key, all your messages come back with a delivered status.

All messages sent using the team and guest list or live keys appear on your dashboard.

Error codes

If the request is not successful, the client returns a NotificationClientException containing the relevant error code:

httpResult Message How to fix
400 [{
"error": "BadRequestError",
"message": "Can't send to this recipient using a team-only API key"
}]
Use the correct type of API key
400 [{
"error": "BadRequestError",
"message": "Can't send to this recipient when service is in trial mode - see https://notifications.va.gov"
}]
Your service cannot send this notification in trial mode
403 [{
"error": "AuthError",
"message": "Error: Your system clock must be accurate to within 30 seconds"
}]
Check your system clock
403 [{
"error": "AuthError",
"message": "Invalid token: API key not found"
}]
Use the correct API key. Refer to API keys for more information
429 [{
"error": "RateLimitError",
"message": "Exceeded rate limit for key type TEAM/TEST/LIVE of 3000 requests per 60 seconds"
}]
Refer to API rate limits for more information
429 [{
"error": "TooManyRequestsError",
"message": "Exceeded send limits (LIMIT NUMBER) for today"
}]
Refer to service limits for the limit number
500 [{
"error": "Exception",
"message": "Internal server error"
}]
Notify was unable to process the request, resend your notification

Send an email

Method

SendEmailResponse response = client.sendEmail(
    templateId,
    emailAddress,
    personalisation,
    reference,
    emailReplyToId,
    billingCode
);

Arguments

templateId (required)

To find the template ID:

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

For example:

String templateId="f33517ff-2a88-4f6e-b855-c550268ce08a";
emailAddress (required)

The email address of the recipient.

String emailAddress='[email protected]';
personalisation (required)

If a template has placeholder fields for personalised information such as name or application date, you must provide their values in a map. For example:

Map<String, Object> personalisation = new HashMap<>();
personalisation.put("first_name", "Amala");
personalisation.put("application_date", "2018-01-01");
personalisation.put("list", listOfItems); // Will appear as a bulleted list in the message

If a template does not have any placeholder fields for personalised information, you must pass in an empty map or null.

reference (required)

A unique identifier you create. This reference identifies a single unique notification or a batch of notifications. It must not contain any personal information such as name or postal address. If you do not have a reference, you must pass in an empty string or null.

String reference='STRING';
emailReplyToId (optional)

This is an email address specified by you to receive replies from your users. 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 VANotify.
  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.
String emailReplyToId='8e222534-7f05-4972-86e3-17c5d9f894e2'

You can leave out this argument if your service only has one reply-to email address, or you want to use the default email address.

billingCode (optional)

A string that represents a billing code under which a notification will be reported. This can be used to group notifications of the same template in billing reports.

String billingCode='some-billing-code'

You can leave out this argument if you don't need to group notifications with billing codes.

Response

If the request to the client is successful, the client returns a SendEmailResponse:

UUID notificationId;
Optional<String> reference;
UUID templateId;
int templateVersion;
String templateUri;
String body;
String subject;
Optional<String> fromEmail;
Optional<String> billingCode;

Error codes

If the request is not successful, the client returns a NotificationClientException containing the relevant error code:

httpResult Message How to fix
400 [{
"error": "BadRequestError",
"message": "Can't send to this recipient using a team-only API key"
}]
Use the correct type of API key
400 [{
"error": "BadRequestError",
"message": "Can't send to this recipient when service is in trial mode - see https://notifications.va.gov/trial-mode"
}]
Your service cannot send this notification in trial mode
403 [{
"error": "AuthError",
"message": "Error: Your system clock must be accurate to within 30 seconds"
}]
Check your system clock
403 [{
"error": "AuthError",
"message": "Invalid token: API key not found"
}]
Use the correct API key. Refer to API keys for more information
429 [{
"error": "RateLimitError",
"message": "Exceeded rate limit for key type TEAM/TEST/LIVE of 3000 requests per 60 seconds"
}]
Refer to API rate limits for more information
429 [{
"error": "TooManyRequestsError",
"message": "Exceeded send limits (LIMIT NUMBER) for today"
}]
Refer to service limits for the limit number
500 [{
"error": "Exception",
"message": "Internal server error"
}]
Notify was unable to process the request, resend your notification

Send a file by email

To send a file by email, add a placeholder to the template then upload a file. The placeholder will contain a secure link to download the file.

The file will be available for the recipient to download for 18 months.

The links are unique and unguessable. VANotify cannot access or decrypt your file.

Add a placeholder to the template

  1. Sign in to VANotify.
  2. Go to the Templates page and select the relevant email template.
  3. Select Edit.
  4. Add a placeholder to the email template using double brackets. For example:

"Download your file at: ((link_to_file))"

Upload your file

You can upload PDF, CSV, .odt, .txt, .rtf, .xlsx and MS Word Document files. Your file must be smaller than 2MB. Contact the VANotify team if you need to send other file types.

  1. Convert the PDF to a byte[].
  2. Pass the byte[] to the personalisation argument.
  3. Call the sendEmail method.

For example:

ClassLoader classLoader = getClass().getClassLoader();
File file = new File(classLoader.getResource("document_to_upload.pdf").getFile());
byte [] fileContents = FileUtils.readFileToByteArray(file);

HashMap<String, Object> personalisation = new HashMap();
personalisation.put("link_to_file", client.prepareUpload(fileContents));
client.sendEmail(templateId,
                 emailAddress,
                 personalisation,
                 reference,
                 emailReplyToId);
CSV Files

Uploads for CSV files should use the isCsv parameter on the prepareUpload() function. For example:

ClassLoader classLoader = getClass().getClassLoader();
File file = new File(classLoader.getResource("document_to_upload.pdf").getFile());
byte [] fileContents = FileUtils.readFileToByteArray(file);

HashMap<String, Object> personalisation = new HashMap();
personalisation.put("link_to_file", client.prepareUpload(fileContents, true));
client.sendEmail(templateId,
                 emailAddress,
                 personalisation,
                 reference,
                 emailReplyToId);

Error codes

If the request is not successful, the client returns an HTTPError containing the relevant error code.

error.status_code error.message How to fix
400 [{
"error": "BadRequestError",
"message": "Can't send to this recipient using a team-only API key"
}]
Use the correct type of API key
400 [{
"error": "BadRequestError",
"message": "Can't send to this recipient when service is in trial mode - see https://notifications.va.gov"
}]
Your service cannot send this notification in trial mode
400 [{
"error": "BadRequestError",
"message": "Unsupported file type '(FILE TYPE)'. Supported types are: '(ALLOWED TYPES)'"
}]
Wrong file type. You can only upload .pdf, .csv, .txt, .doc, .docx, .xlsx, .rtf or .odt files
400 [{
"error": "BadRequestError",
"message": "File did not pass the virus scan"
}]
The file contains a virus
400 [{
"error": "BadRequestError",
"message": "Send files by email has not been set up - add contact details for your service at https://notifications.va.gov"
}]
See how to add contact details to the file download page
403 [{
"error": "AuthError",
"message": "Error: Your system clock must be accurate to within 30 seconds"
}]
Check your system clock
403 [{
"error": "AuthError",
"message": "Invalid token: API key not found"
}]
Use the correct type of API key
413 File is larger than 2MB The file is too big. Files must be smaller than 2MB
429 [{
"error": "RateLimitError",
"message": "Exceeded rate limit for key type TEAM/TEST/LIVE of 3000 requests per 60 seconds"
}]
Refer to API rate limits for more information
429 [{
"error": "TooManyRequestsError",
"message": "Exceeded send limits (LIMIT NUMBER) for today"
}]
Refer to service limits for the limit number
500 [{
"error": "Exception",
"message": "Internal server error"
}]
Notify was unable to process the request, resend your notification.

Get message status

Get the status of one message

You can only get the status of messages sent within the retention period. The default retention period is 7 days.

Method

Notification notification = client.getNotificationById(notificationId);

Arguments

notificationId (required)

The ID of the notification. To find the notification ID, you can either:

Response

If the request to the client is successful, the client returns a Notification:

UUID id;
Optional<String> reference;
Optional<String> emailAddress;
Optional<String> phoneNumber;
Optional<String> line1;
Optional<String> line2;
Optional<String> line3;
Optional<String> line4;
Optional<String> line5;
Optional<String> line6;
Optional<String> line7;
Optional<String> postage;
String notificationType;
String status;
UUID templateId;
int templateVersion;
String templateUri;
String body;
Optional<String subject;
DateTime createdAt;
Optional<DateTime> sentAt;
Optional<DateTime> completedAt;
Optional<DateTime> estimatedDelivery;
Optional<String> createdByName;
Optional<String> billingCode;

Error codes

If the request is not successful, the client returns a NotificationClientException containing the relevant error code:

httpResult Message How to fix
400 [{
"error": "ValidationError",
"message": "id is not a valid UUID"
}]
Check the notification ID
403 [{
"error": "AuthError",
"message": "Error: Your system clock must be accurate to within 30 seconds"
}]
Check your system clock
403 [{
"error": "AuthError",
"message": "Invalid token: API key not found"
}]
Use the correct API key. Refer to API keys for more information
404 [{
"error": "NoResultFound",
"message": "No result found"
}]
Check the notification ID

Get the status of multiple messages

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

You can only get the status of messages that are 7 days old or newer.

Method

NotificationList notification = client.getNotifications(
    status,
    notificationType,
    reference,
    olderThanId
);

To get the most recent messages, you must pass in an empty olderThanId argument or null.

To get older messages, pass the ID of an older notification into the olderThanId argument. This returns the next oldest messages from the specified notification ID.

Arguments

You can pass in empty arguments or null to ignore these filters.

status (optional)

You can filter by each:

You can leave out this argument to ignore this filter.

notificationType (optional)

You can filter by:

  • email
  • sms
reference (optional)

A unique identifier you create if necessary. This reference identifies a single unique notification or a batch of notifications. It must not contain any personal information such as name or postal address.

String reference='STRING';
olderThanId (optional)

Input the ID of a notification into this argument. If you use this argument, the client returns the next 250 received notifications older than the given ID.

String olderThanId='8e222534-7f05-4972-86e3-17c5d9f894e2'

If you pass in an empty argument or null, the client returns the most recent 250 notifications.

Response

If the request to the client is successful, the client returns a NotificationList:

List<Notification> notifications;
String currentPageLink;
Optional<String> nextPageLink;

Error codes

If the request is not successful, the client returns a NotificationClientException containing the relevant error code:

httpResult Message How to fix
400 [{
"error": "ValidationError",
"message": "bad status is not one of [created, sending, sent, delivered, pending, failed, technical-failure, temporary-failure, permanent-failure, accepted, received]"
}]
Contact the VANotify team
400 [{
"error": "ValidationError",
"message": "Applet is not one of [sms, email, letter]"
}]
Contact the VANotify team
403 [{
"error": "AuthError",
"message": "Error: Your system clock must be accurate to within 30 seconds"
}]
Check your system clock
403 [{
"error": "AuthError",
"message": "Invalid token: API key not found"
}]
Use the correct API key. Refer to API keys for more information

Email status descriptions

Status Description
#created VANotify has placed the message in a queue, ready to be sent to the provider. It should only remain in this state for a few seconds.
#sending VANotify has sent the message to the provider. The provider will try to deliver the message to the recipient for up to 72 hours. VANotify is waiting for delivery information.
#delivered The message was successfully delivered.
#permanent-failure The provider could not deliver the message because the email address was wrong. You should remove these email addresses from your database.
#temporary-failure The provider could not deliver the message. This can happen when the recipient’s inbox is full or their anti-spam filter rejects your email. Check your content does not look like spam before you try to send the message again.
#technical-failure Your message was not sent because there was a problem between Notify and the provider.
You’ll have to try sending your messages again.

Text message status descriptions

Status Description
#created VANotify has placed the message in a queue, ready to be sent to the provider. It should only remain in this state for a few seconds.
#sending VANotify has sent the message to the provider. The provider will try to deliver the message to the recipient for up to 72 hours. VANotify is waiting for delivery information.
#pending VANotify is waiting for more delivery information.
VANotify received a callback from the provider but the recipient’s device has not yet responded. Another callback from the provider determines the final status of the text message.
#sent The message was sent to an international number. The mobile networks in some countries do not provide any more delivery information. The VANotify website displays this status as 'Sent to an international number'.
#delivered The message was successfully delivered.
#permanent-failure The provider could not deliver the message. This can happen if the phone number was wrong or if the network operator rejects the message. If you’re sure that these phone numbers are correct, you should contact VANotify support. If not, you should remove them from your database. You’ll still be charged for text messages that cannot be delivered.
#temporary-failure The provider could not deliver the message. This can happen when the recipient’s phone is off, has no signal, or their text message inbox is full. You can try to send the message again. You’ll still be charged for text messages to phones that are not accepting messages.
#technical-failure Your message was not sent because there was a problem between Notify and the provider.
You’ll have to try sending your messages again. You will not be charged for text messages that are affected by a technical failure.

Get a template

Get a template by ID

Method

This returns the latest version of the template.

Template template = client.getTemplateById(templateId);

Arguments

templateId (required)

The ID of the template. Sign in to VANotify and go to the Templates page to find it.

String templateId='f33517ff-2a88-4f6e-b855-c550268ce08a';

Response

If the request to the client is successful, the client returns a Template:

UUID id;
String name;
String templateType;
DateTime createdAt;
Optional<DateTime> updatedAt;
String createdBy;
int version;
String body;
Optional<String> subject;
Optional<Map<String, Object>> personalisation;
Optional<String> letterContactBlock;

Error codes

If the request is not successful, the client returns a NotificationClientException containing the relevant error code:

httpResult Message How to fix
403 [{
"error": "AuthError",
"message": "Error: Your system clock must be accurate to within 30 seconds"
}]
Check your system clock
403 [{
"error": "AuthError",
"message": "Invalid token: API key not found"
}]
Use the correct API key. Refer to API keys for more information
404 [{
"error": "NoResultFound",
"message": "No Result Found"
}]
Check your template ID

Get a template by ID and version

Method

Template template = client.getTemplateVersion(templateId, version);

Arguments

templateId (required)

The ID of the template. Sign in to VANotify and go to the Templates page to find it.

String templateId='f33517ff-2a88-4f6e-b855-c550268ce08a';
version (required)

The version number of the template.

Response

If the request to the client is successful, the client returns a Template:

UUID id;
String name;
String templateType;
DateTime createdAt;
Optional<DateTime> updatedAt;
String createdBy;
int version;
String body;
Optional<String> subject;
Optional<Map<String, Object>> personalisation;
Optional<String> letterContactBlock;

Error codes

If the request is not successful, the client returns a NotificationClientException containing the relevant error code:

httpResult message How to fix
400 [{
"error": "ValidationError",
"message": "id is not a valid UUID"
}]
Check the notification ID
403 [{
"error": "AuthError",
"message": "Error: Your system clock must be accurate to within 30 seconds"
}]
Check your system clock
403 [{
"error": "AuthError",
"message": "Invalid token: API key not found"
}]
Use the correct API key. Refer to API keys for more information
404 [{
"error": "NoResultFound",
"message": "No Result Found"
}]
Check your template ID and version

Get all templates

Method

This returns the latest version of all templates.

TemplateList templates = client.getAllTemplates(templateType);

Arguments

templateType (optional)

If you do not use templateType, the client returns all templates. Otherwise you can filter by:

  • email
  • sms

Response

If the request to the client is successful, the client returns a TemplateList:

List<Template> templates;

If no templates exist for a template type or there no templates for a service, the templates list is empty.

Generate a preview template

Method

This generates a preview version of a template.

TemplatePreview templatePreview = client.getTemplatePreview(
    templateId,
    personalisation
);

The parameters in the personalisation argument must match the placeholder fields in the actual template. The API notification client ignores any extra fields in the method.

Arguments

templateId (required)

The ID of the template. Sign in to VANotify and go to the Templates page to find it.

String templateId='f33517ff-2a88-4f6e-b855-c550268ce08a';
personalisation (required)

If a template has placeholder fields for personalised information such as name or application date, you must provide their values in a map. For example:

Map<String, Object> personalisation = new HashMap<>();
personalisation.put("first_name", "Amala");
personalisation.put("application_date", "2018-01-01");

If a template does not have any placeholder fields for personalised information, you must pass in an empty map or null.

Response

If the request to the client is successful, the client returns a TemplatePreview:

UUID id;
String templateType;
int version;
String body;
Optional<String> subject;
Optional<String> html;

Error codes

If the request is not successful, the client returns a NotificationClientException containing the relevant error code:

httpResult message How to fix
400 [{
"error": "BadRequestError",
"message": "Missing personalisation: [PERSONALISATION FIELD]"
}]
Check that the personalisation arguments in the method match the placeholder fields in the template
400 [{
"error": "NoResultFound",
"message": "No result found"
}]
Check the template ID
403 [{
"error": "AuthError",
"message": "Error: Your system clock must be accurate to within 30 seconds"
}]
Check your system clock
403 [{
"error": "AuthError",
"message": "Invalid token: API key not found"
}]
Use the correct API key. Refer to API keys for more information

Get received text messages

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

You can only get messages that are 7 days old or newer.

You can also set up callbacks for received text messages.

Enable received text messages

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

Get a page of received text messages

Method

ReceivedTextMessageList response = client.getReceivedTextMessages(olderThanId);

To get the most recent messages, you must pass in an empty argument or null.

To get older messages, pass the ID of an older notification into the olderThanId argument. This returns the next oldest messages from the specified notification ID.

Arguments

olderThanId (optional)

Input the ID of a received text message into this argument. If you use this argument, the client returns the next 250 received text messages older than the given ID.

String olderThanId='8e222534-7f05-4972-86e3-17c5d9f894e2'

If you pass in an empty argument or null, the client returns the most recent 250 text messages.

Response

If the request to the client is successful, the client returns a ReceivedTextMessageList that returns all received texts.

private List<ReceivedTextMessage> receivedTextMessages;
private String currentPageLink;
private String nextPageLink;

The ReceivedTextMessageList has the following properties:

private UUID id;
private String notifyNumber;
private String userNumber;
private UUID serviceId;
private String content;
private DateTime createdAt;

If the notification specified in the olderThanId argument is older than 7 days, the client returns an empty response.

Error codes

If the request is not successful, the client returns a NotificationClientException containing the relevant error code:

httpResult Message How to fix
403 [{
"error": "AuthError",
"message": "Error: Your system clock must be accurate to within 30 seconds"
}]
Check your system clock
403 [{
"error": "AuthError",
"message": "Invalid token: API key not found"
}]
Use the correct API key. Refer to API keys for more information