@trycourier/courier
A node.js module for communicating with the Courier REST API.
Installation (via npm)
npm install @trycourier/courier
Usage
import { CourierClient } from "@trycourier/courier";
const courier = CourierClient({ authorizationToken: "<AUTH_TOKEN>" });
const { messageId } = await courier.send({
eventId: "<EVENT_ID>",
recipientId: "<RECIPIENT_ID>",
profile: {
email: "example@example.com",
phone_number: "555-228-3890"
},
data: {}
});
Environment Variables
courier-node
supports credential storage in environment variables. If no authorizationToken
is provided when instantiating the Courier client (e.g., const courier = CourierClient();
), the value in the COURIER_AUTH_TOKEN
env var will be used.
If you need to use a base url other than the default https://api.trycourier.app, you can set it using the COURIER_BASE_URL
env var.
Advanced Usage
import { CourierClient } from "@trycourier/courier";
const courier = CourierClient({ authorizationToken: "<AUTH_TOKEN>" });
async function run() {
const { messageId } = await courier.send({
eventId: "<EVENT_ID>",
recipientId: "<RECIPIENT_ID>",
profile: {},
data: {},
preferences: {},
override: {}
});
console.log(messageId);
const messageStatus = await courier.getMessage(messageId);
console.log(messageStatus);
const { status: replaceStatus } = await courier.replaceProfile({
recipientId: "<RECIPIENT_ID>",
profile: {
email: "example@example.com"
}
});
console.log(replaceStatus);
const { status: mergeStatus } = await courier.mergeProfile({
recipientId: "<RECIPIENT_ID>",
profile: {
sms: "555-555-5555"
}
});
console.log(mergeStatus);
const { profile } = await courier.getProfile({
recipientId: "<RECIPIENT_ID>"
});
console.log(profile);
}
run();
License
MIT License
Author
Courier (support@trycourier.com)