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.

Install the npm package

npm install @usewaypoint/client --save

Setup

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 a message with a template.

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 sandbox test requests.

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 a message without a template.

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 sandbox requests.

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