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.replace('id', {
notification: {
name: 'Updated Name',
tags: ['updated'],
brand: null,
subscription: null,
routing: null,
content: {
version: '2022-01-01',
elements: [
{
type: 'channel',
channel: 'email',
elements: [
{ type: 'meta', title: 'Updated' },
{ type: 'text', content: 'Updated content.' },
],
},
],
},
},
state: 'PUBLISHED',
});
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.replace(
id="id",
notification={
"name": "Updated Name",
"tags": ["updated"],
"brand": None,
"subscription": None,
"routing": None,
"content": {
"version": "2022-01-01",
"elements": [{
"type": "channel",
"channel": "email",
"elements": [{
"type": "meta",
"title": "Updated",
}, {
"type": "text",
"content": "Updated content.",
}],
}],
},
},
state="PUBLISHED",
)
print(notification_template_response)package main
import (
"context"
"fmt"
"github.com/trycourier/courier-go/v4"
"github.com/trycourier/courier-go/v4/option"
"github.com/trycourier/courier-go/v4/shared"
)
func main() {
client := courier.NewClient(
option.WithAPIKey("My API Key"),
)
notificationTemplateResponse, err := client.Notifications.Replace(
context.TODO(),
"id",
courier.NotificationReplaceParams{
NotificationTemplateUpdateRequest: courier.NotificationTemplateUpdateRequestParam{
Notification: courier.NotificationTemplateWritePayloadParam{
NotificationTemplatePayloadParam: courier.NotificationTemplatePayloadParam{
Brand: courier.NotificationTemplatePayloadBrandParam{
ID: "id",
},
Content: shared.ElementalContentParam{
Elements: []shared.ElementalNodeUnionParam{{
OfElementalTextNodeWithType: &shared.ElementalTextNodeWithTypeParam{
ElementalTextNodeParam: shared.ElementalTextNodeParam{
ElementalBaseNodeParam: shared.ElementalBaseNodeParam{},
},
},
}},
Version: "2022-01-01",
},
Name: "Updated Name",
Routing: courier.NotificationTemplatePayloadRoutingParam{
StrategyID: "strategy_id",
},
Subscription: courier.NotificationTemplatePayloadSubscriptionParam{
TopicID: "topic_id",
},
Tags: []string{"updated"},
},
},
},
},
)
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.NotificationReplaceParams;
import com.courier.models.notifications.NotificationTemplatePayload;
import com.courier.models.notifications.NotificationTemplateResponse;
import com.courier.models.notifications.NotificationTemplateUpdateRequest;
import com.courier.models.notifications.NotificationTemplateWritePayload;
public final class Main {
private Main() {}
public static void main(String[] args) {
CourierClient client = CourierOkHttpClient.fromEnv();
NotificationReplaceParams params = NotificationReplaceParams.builder()
.id("id")
.notificationTemplateUpdateRequest(NotificationTemplateUpdateRequest.builder()
.notification(NotificationTemplateWritePayload.builder()
.brand(NotificationTemplatePayload.Brand.builder()
.id("id")
.build())
.content(ElementalContent.builder()
.addElement(ElementalTextNodeWithType.builder().build())
.version("2022-01-01")
.build())
.name("Updated Name")
.routing(NotificationTemplatePayload.Routing.builder()
.strategyId("strategy_id")
.build())
.subscription(NotificationTemplatePayload.Subscription.builder()
.topicId("topic_id")
.build())
.addTag("updated")
.build())
.build())
.build();
NotificationTemplateResponse notificationTemplateResponse = client.notifications().replace(params);
}
}require "courier"
courier = Courier::Client.new(api_key: "My API Key")
notification_template_response = courier.notifications.replace(
"id",
notification: {
brand: {id: "id"},
content: {elements: [{}], version: "2022-01-01"},
name: "Updated Name",
routing: {strategy_id: "strategy_id"},
subscription: {topic_id: "topic_id"},
tags: ["updated"]
}
)
puts(notification_template_response)<?php
require_once dirname(__DIR__) . '/vendor/autoload.php';
use Courier\Client;
use Courier\TextStyle;
use Courier\Core\Exceptions\APIException;
$client = new Client(apiKey: getenv('COURIER_API_KEY') ?: 'My API Key');
try {
$notificationTemplateResponse = $client->notifications->replace(
'id',
notification: [
'brand' => ['id' => 'id'],
'content' => [
'elements' => [
[
'channels' => ['string'],
'if' => 'if',
'loop' => 'loop',
'ref' => 'ref',
'channel' => 'email',
'elements' => [
[
'channels' => ['string'],
'if' => 'if',
'loop' => 'loop',
'ref' => 'ref',
'title' => 'Updated',
'type' => 'meta',
],
[
'channels' => ['string'],
'if' => 'if',
'loop' => 'loop',
'ref' => 'ref',
'align' => 'left',
'bold' => 'bold',
'color' => 'color',
'content' => 'Updated content.',
'fontSize' => 'font_size',
'format' => 'markdown',
'italic' => 'italic',
'lineHeight' => 'line_height',
'locales' => ['foo' => ['content' => 'content']],
'strikethrough' => 'strikethrough',
'textStyle' => TextStyle::TEXT,
'underline' => 'underline',
'type' => 'text',
],
],
'fontSize' => 'font_size',
'lineHeight' => 'line_height',
'padding' => 'padding',
'raw' => ['foo' => 'bar'],
'type' => 'channel',
],
],
'version' => '2022-01-01',
],
'name' => 'Updated Name',
'routing' => ['strategyID' => 'strategy_id'],
'subscription' => ['topicID' => 'topic_id'],
'tags' => ['updated'],
'email' => [
'bcc' => ['string'],
'cc' => ['string'],
'from' => 'from',
'replyTo' => 'reply_to',
],
'alias' => 'alias',
],
state: 'PUBLISHED',
);
var_dump($notificationTemplateResponse);
} catch (APIException $e) {
echo $e->getMessage();
}using System;
using System.Collections.Generic;
using System.Text.Json;
using TryCourier;
using Models = TryCourier.Models;
using TryCourier.Models.Notifications;
CourierClient client = new();
NotificationReplaceParams parameters = new()
{
ID = "id",
Notification = new()
{
Brand = new("id"),
Content = new()
{
Elements =
[
new Models::ElementalChannelNodeWithType()
{
Channels =
[
"string"
],
If = "if",
Loop = "loop",
Ref = "ref",
Channel = "email",
Elements =
[
new Models::UnionMember1()
{
Channels =
[
"string"
],
If = "if",
Loop = "loop",
Ref = "ref",
Title = "Updated",
Type = Models::UnionMember1IntersectionMember1Type.Meta,
},
new Models::UnionMember0()
{
Channels =
[
"string"
],
If = "if",
Loop = "loop",
Ref = "ref",
Align = Models::Align.Left,
Bold = "bold",
Color = "color",
Content = "Updated content.",
FontSize = "font_size",
Format = Models::Format.Markdown,
Italic = "italic",
LineHeight = "line_height",
Locales = new Dictionary<string, Models::LocalesItem>(
)
{
{ "foo", new("content") }
},
Strikethrough = "strikethrough",
TextStyle = Models::TextStyle.Text,
Underline = "underline",
Type = Models::UnionMember0IntersectionMember1Type.Text,
},
],
FontSize = "font_size",
LineHeight = "line_height",
Padding = "padding",
Raw = new Dictionary<string, JsonElement>()
{
{ "foo", JsonSerializer.SerializeToElement("bar") }
},
Type = Models::ElementalChannelNodeWithTypeIntersectionMember1Type.Channel,
},
],
Version = "2022-01-01",
},
Name = "Updated Name",
Routing = new("strategy_id"),
Subscription = new("topic_id"),
Tags =
[
"updated"
],
Email = new()
{
Bcc =
[
"string"
],
Cc =
[
"string"
],
From = "from",
ReplyTo = "reply_to",
},
Alias = "alias",
},
};
var notificationTemplateResponse = await client.Notifications.Replace(parameters);
Console.WriteLine(notificationTemplateResponse);courier notifications replace \
--api-key 'My API Key' \
--id id \
--notification "{brand: {id: id}, content: {elements: [{}], version: '2022-01-01'}, name: Updated Name, routing: {strategy_id: strategy_id}, subscription: {topic_id: topic_id}, tags: [updated]}"curl --request PUT \
--url https://api.courier.com/notifications/{id} \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"notification": {
"name": "Updated Name",
"tags": [
"updated"
],
"brand": null,
"subscription": null,
"routing": null,
"content": {
"version": "2022-01-01",
"elements": [
{
"type": "channel",
"channel": "email",
"elements": [
{
"type": "meta",
"title": "Updated"
},
{
"type": "text",
"content": "Updated content."
}
]
}
]
}
},
"state": "PUBLISHED"
}
'{
"id": "nt_01kx4h2jdafq8bk9aftxak4b40",
"name": "Updated Name",
"tags": [
"updated"
],
"brand": null,
"subscription": null,
"routing": null,
"content": {
"version": "2022-01-01",
"elements": [
{
"type": "channel",
"channel": "email",
"elements": [
{
"type": "meta",
"title": "Updated"
},
{
"type": "text",
"content": "Updated content."
}
]
}
]
},
"state": "PUBLISHED",
"created": 1710000000000,
"creator": "user_abc",
"updated": 1710000001000,
"updater": "user_def"
}Replace Notification Template
Replaces a notification template in full, so send every field rather than only the ones you want changed. Publish separately to make it live.
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.replace('id', {
notification: {
name: 'Updated Name',
tags: ['updated'],
brand: null,
subscription: null,
routing: null,
content: {
version: '2022-01-01',
elements: [
{
type: 'channel',
channel: 'email',
elements: [
{ type: 'meta', title: 'Updated' },
{ type: 'text', content: 'Updated content.' },
],
},
],
},
},
state: 'PUBLISHED',
});
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.replace(
id="id",
notification={
"name": "Updated Name",
"tags": ["updated"],
"brand": None,
"subscription": None,
"routing": None,
"content": {
"version": "2022-01-01",
"elements": [{
"type": "channel",
"channel": "email",
"elements": [{
"type": "meta",
"title": "Updated",
}, {
"type": "text",
"content": "Updated content.",
}],
}],
},
},
state="PUBLISHED",
)
print(notification_template_response)package main
import (
"context"
"fmt"
"github.com/trycourier/courier-go/v4"
"github.com/trycourier/courier-go/v4/option"
"github.com/trycourier/courier-go/v4/shared"
)
func main() {
client := courier.NewClient(
option.WithAPIKey("My API Key"),
)
notificationTemplateResponse, err := client.Notifications.Replace(
context.TODO(),
"id",
courier.NotificationReplaceParams{
NotificationTemplateUpdateRequest: courier.NotificationTemplateUpdateRequestParam{
Notification: courier.NotificationTemplateWritePayloadParam{
NotificationTemplatePayloadParam: courier.NotificationTemplatePayloadParam{
Brand: courier.NotificationTemplatePayloadBrandParam{
ID: "id",
},
Content: shared.ElementalContentParam{
Elements: []shared.ElementalNodeUnionParam{{
OfElementalTextNodeWithType: &shared.ElementalTextNodeWithTypeParam{
ElementalTextNodeParam: shared.ElementalTextNodeParam{
ElementalBaseNodeParam: shared.ElementalBaseNodeParam{},
},
},
}},
Version: "2022-01-01",
},
Name: "Updated Name",
Routing: courier.NotificationTemplatePayloadRoutingParam{
StrategyID: "strategy_id",
},
Subscription: courier.NotificationTemplatePayloadSubscriptionParam{
TopicID: "topic_id",
},
Tags: []string{"updated"},
},
},
},
},
)
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.NotificationReplaceParams;
import com.courier.models.notifications.NotificationTemplatePayload;
import com.courier.models.notifications.NotificationTemplateResponse;
import com.courier.models.notifications.NotificationTemplateUpdateRequest;
import com.courier.models.notifications.NotificationTemplateWritePayload;
public final class Main {
private Main() {}
public static void main(String[] args) {
CourierClient client = CourierOkHttpClient.fromEnv();
NotificationReplaceParams params = NotificationReplaceParams.builder()
.id("id")
.notificationTemplateUpdateRequest(NotificationTemplateUpdateRequest.builder()
.notification(NotificationTemplateWritePayload.builder()
.brand(NotificationTemplatePayload.Brand.builder()
.id("id")
.build())
.content(ElementalContent.builder()
.addElement(ElementalTextNodeWithType.builder().build())
.version("2022-01-01")
.build())
.name("Updated Name")
.routing(NotificationTemplatePayload.Routing.builder()
.strategyId("strategy_id")
.build())
.subscription(NotificationTemplatePayload.Subscription.builder()
.topicId("topic_id")
.build())
.addTag("updated")
.build())
.build())
.build();
NotificationTemplateResponse notificationTemplateResponse = client.notifications().replace(params);
}
}require "courier"
courier = Courier::Client.new(api_key: "My API Key")
notification_template_response = courier.notifications.replace(
"id",
notification: {
brand: {id: "id"},
content: {elements: [{}], version: "2022-01-01"},
name: "Updated Name",
routing: {strategy_id: "strategy_id"},
subscription: {topic_id: "topic_id"},
tags: ["updated"]
}
)
puts(notification_template_response)<?php
require_once dirname(__DIR__) . '/vendor/autoload.php';
use Courier\Client;
use Courier\TextStyle;
use Courier\Core\Exceptions\APIException;
$client = new Client(apiKey: getenv('COURIER_API_KEY') ?: 'My API Key');
try {
$notificationTemplateResponse = $client->notifications->replace(
'id',
notification: [
'brand' => ['id' => 'id'],
'content' => [
'elements' => [
[
'channels' => ['string'],
'if' => 'if',
'loop' => 'loop',
'ref' => 'ref',
'channel' => 'email',
'elements' => [
[
'channels' => ['string'],
'if' => 'if',
'loop' => 'loop',
'ref' => 'ref',
'title' => 'Updated',
'type' => 'meta',
],
[
'channels' => ['string'],
'if' => 'if',
'loop' => 'loop',
'ref' => 'ref',
'align' => 'left',
'bold' => 'bold',
'color' => 'color',
'content' => 'Updated content.',
'fontSize' => 'font_size',
'format' => 'markdown',
'italic' => 'italic',
'lineHeight' => 'line_height',
'locales' => ['foo' => ['content' => 'content']],
'strikethrough' => 'strikethrough',
'textStyle' => TextStyle::TEXT,
'underline' => 'underline',
'type' => 'text',
],
],
'fontSize' => 'font_size',
'lineHeight' => 'line_height',
'padding' => 'padding',
'raw' => ['foo' => 'bar'],
'type' => 'channel',
],
],
'version' => '2022-01-01',
],
'name' => 'Updated Name',
'routing' => ['strategyID' => 'strategy_id'],
'subscription' => ['topicID' => 'topic_id'],
'tags' => ['updated'],
'email' => [
'bcc' => ['string'],
'cc' => ['string'],
'from' => 'from',
'replyTo' => 'reply_to',
],
'alias' => 'alias',
],
state: 'PUBLISHED',
);
var_dump($notificationTemplateResponse);
} catch (APIException $e) {
echo $e->getMessage();
}using System;
using System.Collections.Generic;
using System.Text.Json;
using TryCourier;
using Models = TryCourier.Models;
using TryCourier.Models.Notifications;
CourierClient client = new();
NotificationReplaceParams parameters = new()
{
ID = "id",
Notification = new()
{
Brand = new("id"),
Content = new()
{
Elements =
[
new Models::ElementalChannelNodeWithType()
{
Channels =
[
"string"
],
If = "if",
Loop = "loop",
Ref = "ref",
Channel = "email",
Elements =
[
new Models::UnionMember1()
{
Channels =
[
"string"
],
If = "if",
Loop = "loop",
Ref = "ref",
Title = "Updated",
Type = Models::UnionMember1IntersectionMember1Type.Meta,
},
new Models::UnionMember0()
{
Channels =
[
"string"
],
If = "if",
Loop = "loop",
Ref = "ref",
Align = Models::Align.Left,
Bold = "bold",
Color = "color",
Content = "Updated content.",
FontSize = "font_size",
Format = Models::Format.Markdown,
Italic = "italic",
LineHeight = "line_height",
Locales = new Dictionary<string, Models::LocalesItem>(
)
{
{ "foo", new("content") }
},
Strikethrough = "strikethrough",
TextStyle = Models::TextStyle.Text,
Underline = "underline",
Type = Models::UnionMember0IntersectionMember1Type.Text,
},
],
FontSize = "font_size",
LineHeight = "line_height",
Padding = "padding",
Raw = new Dictionary<string, JsonElement>()
{
{ "foo", JsonSerializer.SerializeToElement("bar") }
},
Type = Models::ElementalChannelNodeWithTypeIntersectionMember1Type.Channel,
},
],
Version = "2022-01-01",
},
Name = "Updated Name",
Routing = new("strategy_id"),
Subscription = new("topic_id"),
Tags =
[
"updated"
],
Email = new()
{
Bcc =
[
"string"
],
Cc =
[
"string"
],
From = "from",
ReplyTo = "reply_to",
},
Alias = "alias",
},
};
var notificationTemplateResponse = await client.Notifications.Replace(parameters);
Console.WriteLine(notificationTemplateResponse);courier notifications replace \
--api-key 'My API Key' \
--id id \
--notification "{brand: {id: id}, content: {elements: [{}], version: '2022-01-01'}, name: Updated Name, routing: {strategy_id: strategy_id}, subscription: {topic_id: topic_id}, tags: [updated]}"curl --request PUT \
--url https://api.courier.com/notifications/{id} \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"notification": {
"name": "Updated Name",
"tags": [
"updated"
],
"brand": null,
"subscription": null,
"routing": null,
"content": {
"version": "2022-01-01",
"elements": [
{
"type": "channel",
"channel": "email",
"elements": [
{
"type": "meta",
"title": "Updated"
},
{
"type": "text",
"content": "Updated content."
}
]
}
]
}
},
"state": "PUBLISHED"
}
'{
"id": "nt_01kx4h2jdafq8bk9aftxak4b40",
"name": "Updated Name",
"tags": [
"updated"
],
"brand": null,
"subscription": null,
"routing": null,
"content": {
"version": "2022-01-01",
"elements": [
{
"type": "channel",
"channel": "email",
"elements": [
{
"type": "meta",
"title": "Updated"
},
{
"type": "text",
"content": "Updated content."
}
]
}
]
},
"state": "PUBLISHED",
"created": 1710000000000,
"creator": "user_abc",
"updated": 1710000001000,
"updater": "user_def"
}Authorizations
Bearer authentication header of the form Bearer <token>, where <token> is your auth token.
Path Parameters
Template ID (nt_ prefix).
Body
Request body for replacing a notification template. All fields are required, since PUT is a full replacement, except alias, whose omission leaves the existing aliases in place. Unlike NotificationTemplateCreateRequest, notification.content is not required to place its elements inside a channel block: the requirement applies to creation only, so templates already stored without one stay editable.
Template fields accepted in POST and PUT request bodies, nested under a notification key.
Show child attributes
Show child attributes
Template state after update. Case-insensitive input, normalized to uppercase in the response. Defaults to "DRAFT".
DRAFT, PUBLISHED Response
Response for GET /notifications/{id}, POST /notifications, and PUT /notifications/{id}. Returns all template fields at the top level.
Display name for the template.
Tags for categorization. Send empty array for none.
Brand reference, or null for no brand.
Show child attributes
Show child attributes
Subscription topic reference, or null for none.
Show child attributes
Show child attributes
Routing strategy reference, or null for none.
Show child attributes
Show child attributes
Elemental content definition.
Show child attributes
Show child attributes
The template ID.
The template state. Always uppercase.
DRAFT, PUBLISHED Epoch milliseconds when the template was created.
User ID of the creator.
Email header fields for the template's email channel: the From, Reply-to, CC and BCC values set in the Studio email channel settings. Each value may use template variables, such as {{data.cc}}, which are resolved at send time.
Reads omit email when no header is set, and omit each unset field.
Writes treat it as optional, with three meanings. Omit it to keep the stored headers. Send null to clear all four. Send an object to replace all four: a field the object leaves out is cleared. Other email channel settings, such as the subject, are kept either way. Headers only apply while content has an email channel; with no email channel they are not stored.
Show child attributes
Show child attributes
A template's send-time alias as returned by a read, omitted entirely when it has none. Usually a single string; an array for a template that resolves from several aliases, which writes through this API can no longer produce — only templates predating that restriction, or aliases attached outside this API, hold more than one.
Epoch milliseconds of last update.
User ID of the last updater.