Skip to main content

Send via API

Prerequisites

  1. Sign up for a Courier account
  2. Add an integration
  3. Get your API key

Step 1: Install the SDK

npm install @trycourier/courier

Step 2: Initialize the SDK

Import the Courier client and initialize it with your authorization token:
const { CourierClient } = require("@trycourier/courier");
const courier = new CourierClient({ authorizationToken: "<AUTH_TOKEN>" });

Step 3: Send a Message

Send a basic notification message:
const { requestId } = await courier.send({
  message: {
    to: {
      email: "email@example.com",
    },
    content: {
      title: "Welcome!",
      body: "Thanks for signing up, {{name}}",
    },
    data: {
      name: "Peter Parker",
    },
    routing: {
      method: "single",
      channels: ["email"],
    },
  },
});

Message Properties

The message object contains these main properties:
  • to: Identifies the recipient (email address, phone number, etc.)
  • content: The notification’s title and body
  • data: Variables to populate message templates
  • routing: Controls which channel(s) deliver the message
The API call returns a request ID:
{ "requestId": "87e7c05b-4f46-fda24e356e23" }
Monitor notification status in the logs. Now that we’ve sent a message created via the API, let’s create a reuseable template.

Send using a reuseable template

Courier’s Template Designer lets you create reuseable templates and populate it with dynamic data.

Step 1: Create a Template

Navigate to the Designer and select “New” to get the option to create a new template.
Create a new template

Create Your First Template

Step 2: Add Channels

Click ”+ Add Channel” to add email, SMS, push, or chat channels to your notification template.
Add channel interface

Add Notification Channels

Step 3: Design Content

Use content blocks to build your notification. Add text, images, buttons, and other elements that automatically adapt to each channel.
Content design interface

Design Notification Content

Step 4: Publish and Send

Click “Publish Changes” to make your notification available, then use the Send API to trigger it from your application.
const { requestId } = await courier.send({
  message: {
    to: {
      email: "email@example.com",
    },
    template: "K7BF5ANZ6JMYJ4MXGK3FFNW8PT6T",
    data: {
      markdowncontent: "This is the markdown content",
    },
    routing: {
      method: "single",
      channels: ["email"],
    },
  },
});
And that’s it! You’ve created and sent your first template with the designer.

Next Steps

Choose your path to learn more:
Pro Tip: You can mix approaches! Design your notification templates visually with the Designer, then use the generated code snippets to send them programmatically from your application.