Skip to content

Node.js (npm package)

Send emails with even less code from your Node.js application by using the Waypoint npm package. In addition to being a helpful API wrapper, this npm package provides alias functions that enforce typescript payloads.

Setup

Install the npm package

Terminal window
npm install @usewaypoint/client --save

Import and initialize a client

Learn more about setting up API keys.

const { createClient } = require("@usewaypoint/client");
const client = createClient(API_KEY_USERNAME, API_KEY_PASSWORD);

Send a templated message

Learn more about sending templated emails API .

await client.emailMessages.createTemplated({
templateId: // template id example: 'wptemplate_xxxxxxxxxxxxxxxx',
to: // email address of recipient,
variables: // variables expected by the template,
});

Code example

const { createClient } = require("@usewaypoint/client");
const client = createClient(API_KEY_USERNAME, API_KEY_PASSWORD);
client.emailMessages.createTemplated({
templateId: "wptemplate_ABc123XYZ",
to: 'Jordan Isip <jordan@usewaypoint.com>',
variables: {
"passcode": "1234510",
"expiresIn": "45 minutes"
}
});

Additional options for sending

Send a sandbox message

Learn more about sending test emails API .

await client.sandboxEmailMessages.createTemplated({
templateId: // template id example: 'wptemplate_xxxxxxxxxxxxxxxx',
to: // email address of recipient,
variables: // variables expected by the template
});

Send a message without a template

Learn more about sending emails without a template API .

await client.emailMessages.createRaw({
to: // email address of recipient,
subject: 'Hello',
bodyHtml: '<h1>Hello world</h1>'
});

Send a sandbox message without a template

Learn more about sending test emails API .

await client.sandboxEmailMessages.createRaw({
to: // email address of recipient,
subject: 'Hello',
bodyHtml: '<h1>Hello world</h1>'
});

Downloading/previewing a template

Learn more about downloading templates API .

await client.templates.previewHtml(
'wptemplate_RXL7zGTGsvkXzAP3',
{
"passcode": "1234510",
"expiresIn": "45 minutes"
}
);