Skip to main content
POST
/
notifications
JavaScript
import Courier from '@trycourier/courier';

const client = new Courier({
  apiKey: process.env['COURIER_API_KEY'], // This is the default and can be omitted
});

const notificationTemplateResponse = await client.notifications.create({
  notification: {
    name: 'Welcome Email',
    tags: ['onboarding', 'welcome'],
    brand: { id: 'bnd_01kx4mrd0pfzw8wt7pn7p2fzag' },
    subscription: { topic_id: 'pt_01kx4h2jdafq8bk9a26x0kvd1t' },
    routing: { strategy_id: 'rs_01kx4h2jdafq8bk9amzvy6hbv0' },
    content: { version: '2022-01-01', elements: [{ type: 'channel' }] },
  },
  state: 'DRAFT',
});

console.log(notificationTemplateResponse);
import os
from courier import Courier

client = Courier(
api_key=os.environ.get("COURIER_API_KEY"), # This is the default and can be omitted
)
notification_template_response = client.notifications.create(
notification={
"name": "Welcome Email",
"tags": ["onboarding", "welcome"],
"brand": {
"id": "bnd_01kx4mrd0pfzw8wt7pn7p2fzag"
},
"subscription": {
"topic_id": "pt_01kx4h2jdafq8bk9a26x0kvd1t"
},
"routing": {
"strategy_id": "rs_01kx4h2jdafq8bk9amzvy6hbv0"
},
"content": {
"version": "2022-01-01",
"elements": [{
"type": "channel"
}],
},
},
state="DRAFT",
)
print(notification_template_response)
package main

import (
"context"
"fmt"

"github.com/trycourier/courier-go"
"github.com/trycourier/courier-go/option"
"github.com/trycourier/courier-go/shared"
)

func main() {
client := courier.NewClient(
option.WithAPIKey("My API Key"),
)
notificationTemplateResponse, err := client.Notifications.New(context.TODO(), courier.NotificationNewParams{
NotificationTemplateCreateRequest: courier.NotificationTemplateCreateRequestParam{
Notification: courier.NotificationTemplatePayloadParam{
Brand: courier.NotificationTemplatePayloadBrandParam{
ID: "bnd_01kx4mrd0pfzw8wt7pn7p2fzag",
},
Content: shared.ElementalContentParam{
Elements: []shared.ElementalNodeUnionParam{{
OfElementalTextNodeWithType: &shared.ElementalTextNodeWithTypeParam{
ElementalBaseNodeParam: shared.ElementalBaseNodeParam{},
},
}},
Version: "2022-01-01",
},
Name: "Welcome Email",
Routing: courier.NotificationTemplatePayloadRoutingParam{
StrategyID: "rs_01kx4h2jdafq8bk9amzvy6hbv0",
},
Subscription: courier.NotificationTemplatePayloadSubscriptionParam{
TopicID: "pt_01kx4h2jdafq8bk9a26x0kvd1t",
},
Tags: []string{"onboarding", "welcome"},
},
},
})
if err != nil {
panic(err.Error())
}
fmt.Printf("%+v\n", notificationTemplateResponse)
}
package com.courier.example;

import com.courier.client.CourierClient;
import com.courier.client.okhttp.CourierOkHttpClient;
import com.courier.models.ElementalContent;
import com.courier.models.ElementalTextNodeWithType;
import com.courier.models.notifications.NotificationTemplateCreateRequest;
import com.courier.models.notifications.NotificationTemplatePayload;
import com.courier.models.notifications.NotificationTemplateResponse;

public final class Main {
private Main() {}

public static void main(String[] args) {
CourierClient client = CourierOkHttpClient.fromEnv();

NotificationTemplateCreateRequest params = NotificationTemplateCreateRequest.builder()
.notification(NotificationTemplatePayload.builder()
.brand(NotificationTemplatePayload.Brand.builder()
.id("bnd_01kx4mrd0pfzw8wt7pn7p2fzag")
.build())
.content(ElementalContent.builder()
.addElement(ElementalTextNodeWithType.builder().build())
.version("2022-01-01")
.build())
.name("Welcome Email")
.routing(NotificationTemplatePayload.Routing.builder()
.strategyId("rs_01kx4h2jdafq8bk9amzvy6hbv0")
.build())
.subscription(NotificationTemplatePayload.Subscription.builder()
.topicId("pt_01kx4h2jdafq8bk9a26x0kvd1t")
.build())
.addTag("onboarding")
.addTag("welcome")
.build())
.build();
NotificationTemplateResponse notificationTemplateResponse = client.notifications().create(params);
}
}
require "courier"

courier = Courier::Client.new(api_key: "My API Key")

notification_template_response = courier.notifications.create(
notification: {
brand: {id: "bnd_01kx4mrd0pfzw8wt7pn7p2fzag"},
content: {elements: [{}], version: "2022-01-01"},
name: "Welcome Email",
routing: {strategy_id: "rs_01kx4h2jdafq8bk9amzvy6hbv0"},
subscription: {topic_id: "pt_01kx4h2jdafq8bk9a26x0kvd1t"},
tags: ["onboarding", "welcome"]
}
)

puts(notification_template_response)
<?php

require_once dirname(__DIR__) . '/vendor/autoload.php';

use Courier\Client;
use Courier\Core\Exceptions\APIException;

$client = new Client(apiKey: getenv('COURIER_API_KEY') ?: 'My API Key');

try {
$notificationTemplateResponse = $client->notifications->create(
notification: [
'brand' => ['id' => 'bnd_01kx4mrd0pfzw8wt7pn7p2fzag'],
'content' => [
'elements' => [['type' => 'channel']], 'version' => '2022-01-01'
],
'name' => 'Welcome Email',
'routing' => ['strategyID' => 'rs_01kx4h2jdafq8bk9amzvy6hbv0'],
'subscription' => ['topicID' => 'pt_01kx4h2jdafq8bk9a26x0kvd1t'],
'tags' => ['onboarding', 'welcome'],
],
state: 'DRAFT',
);

var_dump($notificationTemplateResponse);
} catch (APIException $e) {
echo $e->getMessage();
}
using System;
using TryCourier;
using TryCourier.Models;
using TryCourier.Models.Notifications;

CourierClient client = new();

NotificationCreateParams parameters = new()
{
Notification = new()
{
Brand = new("bnd_01kx4mrd0pfzw8wt7pn7p2fzag"),
Content = new()
{
Elements =
[
new ElementalChannelNodeWithType()
{
Type = ElementalChannelNodeWithTypeIntersectionMember1Type.Channel,
},
],
Version = "2022-01-01",
},
Name = "Welcome Email",
Routing = new("rs_01kx4h2jdafq8bk9amzvy6hbv0"),
Subscription = new("pt_01kx4h2jdafq8bk9a26x0kvd1t"),
Tags =
[
"onboarding", "welcome"
],
},
};

var notificationTemplateResponse = await client.Notifications.Create(parameters);

Console.WriteLine(notificationTemplateResponse);
courier notifications create \
--api-key 'My API Key' \
--notification "{brand: {id: bnd_01kx4mrd0pfzw8wt7pn7p2fzag}, content: {elements: [{}], version: '2022-01-01'}, name: Welcome Email, routing: {strategy_id: rs_01kx4h2jdafq8bk9amzvy6hbv0}, subscription: {topic_id: pt_01kx4h2jdafq8bk9a26x0kvd1t}, tags: [onboarding, welcome]}"
curl --request POST \
--url https://api.courier.com/notifications \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"notification": {
"name": "Welcome Email",
"tags": [
"onboarding",
"welcome"
],
"brand": {
"id": "bnd_01kx4mrd0pfzw8wt7pn7p2fzag"
},
"subscription": {
"topic_id": "pt_01kx4h2jdafq8bk9a26x0kvd1t"
},
"routing": {
"strategy_id": "rs_01kx4h2jdafq8bk9amzvy6hbv0"
},
"content": {
"version": "2022-01-01",
"elements": [
{
"type": "channel",
"channel": "email",
"elements": [
{
"type": "meta",
"title": "Welcome!"
},
{
"type": "text",
"content": "Hello {{data.name}}."
}
]
}
]
}
},
"state": "DRAFT"
}
'
{
  "id": "nt_01kx4h2jdafq8bk9aftxak4b40",
  "name": "Welcome Email",
  "tags": [
    "onboarding",
    "welcome"
  ],
  "brand": {
    "id": "bnd_01kx4mrd0pfzw8wt7pn7p2fzag"
  },
  "subscription": {
    "topic_id": "pt_01kx4h2jdafq8bk9a26x0kvd1t"
  },
  "routing": {
    "strategy_id": "rs_01kx4h2jdafq8bk9amzvy6hbv0"
  },
  "content": {
    "version": "2022-01-01",
    "elements": [
      {
        "type": "channel",
        "channel": "email",
        "elements": [
          {
            "type": "meta",
            "title": "Welcome!"
          },
          {
            "type": "text",
            "content": "Hello {{data.name}}."
          }
        ]
      }
    ]
  },
  "state": "DRAFT",
  "created": 1710000000000,
  "creator": "user_abc",
  "updated": 1710000000000,
  "updater": "user_abc"
}

Authorizations

Authorization
string
header
required

Bearer authentication header of the form Bearer <token>, where <token> is your auth token.

Body

application/json

Request body for creating a notification template.

notification
NotificationTemplatePayload · object
required

Core template fields used in POST and PUT request bodies (nested under a notification key) and returned at the top level in responses.

state
enum<string>
default:DRAFT

Template state after creation. Case-insensitive input, normalized to uppercase in the response. Defaults to "DRAFT".

Available options:
DRAFT,
PUBLISHED

Response

Created

Response for GET /notifications/{id}, POST /notifications, and PUT /notifications/{id}. Returns all template fields at the top level.

name
string
required

Display name for the template.

tags
string[]
required

Tags for categorization. Send empty array for none.

brand
object | null
required

Brand reference, or null for no brand.

subscription
object | null
required

Subscription topic reference, or null for none.

routing
object | null
required

Routing strategy reference, or null for none.

content
ElementalContent · object
required

Elemental content definition.

id
string
required

The template ID.

state
enum<string>
required

The template state. Always uppercase.

Available options:
DRAFT,
PUBLISHED
created
integer<int64>
required

Epoch milliseconds when the template was created.

creator
string
required

User ID of the creator.

updated
integer<int64>

Epoch milliseconds of last update.

updater
string

User ID of the last updater.