Create a Notification Template scoped to a Journey
Create a notification template scoped to this journey. Defaults to DRAFT state; pass state: "PUBLISHED" to publish on create.
The content tree must contain exactly one channel block whose channel matches the channel on the request — a journey-scoped template carries a single channel. Top-level elements, or a block for a different channel, return 400. The template designer renders only the channel block matching the tab it draws, so content stored without one cannot be opened. An empty elements array is accepted.
import Courier from '@trycourier/courier';
const client = new Courier({
apiKey: process.env['COURIER_API_KEY'], // This is the default and can be omitted
});
const journeyTemplateGetResponse = await client.journeys.templates.create('x', {
channel: 'email',
notification: {
name: 'Welcome email',
tags: [],
brand: null,
subscription: null,
content: {
version: '2022-01-01',
elements: [
{
type: 'channel',
channel: 'email',
elements: [{ type: 'text', content: 'Welcome!' }],
},
],
},
},
});
console.log(journeyTemplateGetResponse.id);import os
from courier import Courier
client = Courier(
api_key=os.environ.get("COURIER_API_KEY"), # This is the default and can be omitted
)
journey_template_get_response = client.journeys.templates.create(
template_id="x",
channel="email",
notification={
"name": "Welcome email",
"tags": [],
"brand": None,
"subscription": None,
"content": {
"version": "2022-01-01",
"elements": [{
"type": "channel",
"channel": "email",
"elements": [{
"type": "text",
"content": "Welcome!",
}],
}],
},
},
)
print(journey_template_get_response.id)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"),
)
journeyTemplateGetResponse, err := client.Journeys.Templates.New(
context.TODO(),
"x",
courier.JourneyTemplateNewParams{
JourneyTemplateCreateRequest: courier.JourneyTemplateCreateRequestParam{
Channel: "email",
Notification: courier.JourneyTemplateCreateRequestNotificationParam{
Brand: courier.JourneyTemplateCreateRequestNotificationBrandParam{
ID: "id",
},
Content: courier.JourneyTemplateCreateRequestNotificationContentParam{
Elements: []shared.ElementalNodeUnionParam{{
OfElementalTextNodeWithType: &shared.ElementalTextNodeWithTypeParam{
ElementalTextNodeParam: shared.ElementalTextNodeParam{
ElementalBaseNodeParam: shared.ElementalBaseNodeParam{},
},
},
}},
Version: "2022-01-01",
},
Name: "Welcome email",
Subscription: courier.JourneyTemplateCreateRequestNotificationSubscriptionParam{
TopicID: "topic_id",
},
Tags: []string{"string"},
},
},
},
)
if err != nil {
panic(err.Error())
}
fmt.Printf("%+v\n", journeyTemplateGetResponse.ID)
}
package com.courier.example;
import com.courier.client.CourierClient;
import com.courier.client.okhttp.CourierOkHttpClient;
import com.courier.models.ElementalTextNodeWithType;
import com.courier.models.journeys.JourneyTemplateCreateRequest;
import com.courier.models.journeys.JourneyTemplateGetResponse;
import com.courier.models.journeys.templates.TemplateCreateParams;
public final class Main {
private Main() {}
public static void main(String[] args) {
CourierClient client = CourierOkHttpClient.fromEnv();
TemplateCreateParams params = TemplateCreateParams.builder()
.templateId("x")
.journeyTemplateCreateRequest(JourneyTemplateCreateRequest.builder()
.channel("email")
.notification(JourneyTemplateCreateRequest.Notification.builder()
.brand(JourneyTemplateCreateRequest.Notification.Brand.builder()
.id("id")
.build())
.content(JourneyTemplateCreateRequest.Notification.Content.builder()
.addElement(ElementalTextNodeWithType.builder().build())
.version(JourneyTemplateCreateRequest.Notification.Content.Version._2022_01_01)
.build())
.name("Welcome email")
.subscription(JourneyTemplateCreateRequest.Notification.Subscription.builder()
.topicId("topic_id")
.build())
.addTag("string")
.build())
.build())
.build();
JourneyTemplateGetResponse journeyTemplateGetResponse = client.journeys().templates().create(params);
}
}require "courier"
courier = Courier::Client.new(api_key: "My API Key")
journey_template_get_response = courier.journeys.templates.create(
"x",
channel: "email",
notification: {
brand: {id: "id"},
content: {elements: [{}], version: :"2022-01-01"},
name: "Welcome email",
subscription: {topic_id: "topic_id"},
tags: ["string"]
}
)
puts(journey_template_get_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 {
$journeyTemplateGetResponse = $client->journeys->templates->create(
'x',
channel: 'email',
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',
'align' => 'left',
'bold' => 'bold',
'color' => 'color',
'content' => 'Welcome!',
'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',
'scope' => 'default',
],
'name' => 'Welcome email',
'subscription' => ['topicID' => 'topic_id'],
'tags' => ['string'],
],
providerKey: 'x',
state: 'state',
idempotencyKey: 'order-ORD-456-user-123',
xIdempotencyExpiration: '1785312000',
);
var_dump($journeyTemplateGetResponse);
} catch (APIException $e) {
echo $e->getMessage();
}using System;
using System.Collections.Generic;
using System.Text.Json;
using TryCourier;
using TryCourier.Models;
using Templates = TryCourier.Models.Journeys.Templates;
CourierClient client = new();
Templates::TemplateCreateParams parameters = new()
{
TemplateID = "x",
Channel = "email",
Notification = new()
{
Brand = new("id"),
Content = new()
{
Elements =
[
new ElementalChannelNodeWithType()
{
Channels =
[
"string"
],
If = "if",
Loop = "loop",
Ref = "ref",
Channel = "email",
Elements =
[
new UnionMember0()
{
Channels =
[
"string"
],
If = "if",
Loop = "loop",
Ref = "ref",
Align = Align.Left,
Bold = "bold",
Color = "color",
Content = "Welcome!",
FontSize = "font_size",
Format = Format.Markdown,
Italic = "italic",
LineHeight = "line_height",
Locales = new Dictionary<string, LocalesItem>()
{
{ "foo", new("content") }
},
Strikethrough = "strikethrough",
TextStyle = TextStyle.Text,
Underline = "underline",
Type = UnionMember0IntersectionMember1Type.Text,
},
],
FontSize = "font_size",
LineHeight = "line_height",
Padding = "padding",
Raw = new Dictionary<string, JsonElement>()
{
{ "foo", JsonSerializer.SerializeToElement("bar") }
},
Type = ElementalChannelNodeWithTypeIntersectionMember1Type.Channel,
},
],
Version = Templates::Version.V2022_01_01,
Scope = Templates::Scope.Default,
},
Name = "Welcome email",
Subscription = new("topic_id"),
Tags =
[
"string"
],
},
};
var journeyTemplateGetResponse = await client.Journeys.Templates.Create(parameters);
Console.WriteLine(journeyTemplateGetResponse);courier journeys:templates create \
--api-key 'My API Key' \
--template-id x \
--channel email \
--notification "{brand: {id: id}, content: {elements: [{}], version: '2022-01-01'}, name: Welcome email, subscription: {topic_id: topic_id}, tags: [string]}"curl --request POST \
--url https://api.courier.com/journeys/{templateId}/templates \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"channel": "email",
"notification": {
"name": "Welcome email",
"tags": [],
"brand": null,
"subscription": null,
"content": {
"version": "2022-01-01",
"elements": [
{
"type": "channel",
"channel": "email",
"elements": [
{
"type": "text",
"content": "Welcome!"
}
]
}
]
}
}
}
'{
"name": "Welcome email",
"tags": [],
"brand": null,
"subscription": null,
"content": {
"scope": "default",
"version": "2022-01-01",
"elements": []
}
}Authorizations
Headers
A unique key that makes this request idempotent. If Courier receives another request with the same Idempotency-Key, it returns the stored response from the first request without performing the operation again (including the original status code and any error). Use it to safely retry POST requests after network failures without risking duplicate sends. The key is scoped to this endpoint.
Body
Response
Created notification template
A journey-scoped notification template.
import Courier from '@trycourier/courier';
const client = new Courier({
apiKey: process.env['COURIER_API_KEY'], // This is the default and can be omitted
});
const journeyTemplateGetResponse = await client.journeys.templates.create('x', {
channel: 'email',
notification: {
name: 'Welcome email',
tags: [],
brand: null,
subscription: null,
content: {
version: '2022-01-01',
elements: [
{
type: 'channel',
channel: 'email',
elements: [{ type: 'text', content: 'Welcome!' }],
},
],
},
},
});
console.log(journeyTemplateGetResponse.id);import os
from courier import Courier
client = Courier(
api_key=os.environ.get("COURIER_API_KEY"), # This is the default and can be omitted
)
journey_template_get_response = client.journeys.templates.create(
template_id="x",
channel="email",
notification={
"name": "Welcome email",
"tags": [],
"brand": None,
"subscription": None,
"content": {
"version": "2022-01-01",
"elements": [{
"type": "channel",
"channel": "email",
"elements": [{
"type": "text",
"content": "Welcome!",
}],
}],
},
},
)
print(journey_template_get_response.id)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"),
)
journeyTemplateGetResponse, err := client.Journeys.Templates.New(
context.TODO(),
"x",
courier.JourneyTemplateNewParams{
JourneyTemplateCreateRequest: courier.JourneyTemplateCreateRequestParam{
Channel: "email",
Notification: courier.JourneyTemplateCreateRequestNotificationParam{
Brand: courier.JourneyTemplateCreateRequestNotificationBrandParam{
ID: "id",
},
Content: courier.JourneyTemplateCreateRequestNotificationContentParam{
Elements: []shared.ElementalNodeUnionParam{{
OfElementalTextNodeWithType: &shared.ElementalTextNodeWithTypeParam{
ElementalTextNodeParam: shared.ElementalTextNodeParam{
ElementalBaseNodeParam: shared.ElementalBaseNodeParam{},
},
},
}},
Version: "2022-01-01",
},
Name: "Welcome email",
Subscription: courier.JourneyTemplateCreateRequestNotificationSubscriptionParam{
TopicID: "topic_id",
},
Tags: []string{"string"},
},
},
},
)
if err != nil {
panic(err.Error())
}
fmt.Printf("%+v\n", journeyTemplateGetResponse.ID)
}
package com.courier.example;
import com.courier.client.CourierClient;
import com.courier.client.okhttp.CourierOkHttpClient;
import com.courier.models.ElementalTextNodeWithType;
import com.courier.models.journeys.JourneyTemplateCreateRequest;
import com.courier.models.journeys.JourneyTemplateGetResponse;
import com.courier.models.journeys.templates.TemplateCreateParams;
public final class Main {
private Main() {}
public static void main(String[] args) {
CourierClient client = CourierOkHttpClient.fromEnv();
TemplateCreateParams params = TemplateCreateParams.builder()
.templateId("x")
.journeyTemplateCreateRequest(JourneyTemplateCreateRequest.builder()
.channel("email")
.notification(JourneyTemplateCreateRequest.Notification.builder()
.brand(JourneyTemplateCreateRequest.Notification.Brand.builder()
.id("id")
.build())
.content(JourneyTemplateCreateRequest.Notification.Content.builder()
.addElement(ElementalTextNodeWithType.builder().build())
.version(JourneyTemplateCreateRequest.Notification.Content.Version._2022_01_01)
.build())
.name("Welcome email")
.subscription(JourneyTemplateCreateRequest.Notification.Subscription.builder()
.topicId("topic_id")
.build())
.addTag("string")
.build())
.build())
.build();
JourneyTemplateGetResponse journeyTemplateGetResponse = client.journeys().templates().create(params);
}
}require "courier"
courier = Courier::Client.new(api_key: "My API Key")
journey_template_get_response = courier.journeys.templates.create(
"x",
channel: "email",
notification: {
brand: {id: "id"},
content: {elements: [{}], version: :"2022-01-01"},
name: "Welcome email",
subscription: {topic_id: "topic_id"},
tags: ["string"]
}
)
puts(journey_template_get_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 {
$journeyTemplateGetResponse = $client->journeys->templates->create(
'x',
channel: 'email',
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',
'align' => 'left',
'bold' => 'bold',
'color' => 'color',
'content' => 'Welcome!',
'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',
'scope' => 'default',
],
'name' => 'Welcome email',
'subscription' => ['topicID' => 'topic_id'],
'tags' => ['string'],
],
providerKey: 'x',
state: 'state',
idempotencyKey: 'order-ORD-456-user-123',
xIdempotencyExpiration: '1785312000',
);
var_dump($journeyTemplateGetResponse);
} catch (APIException $e) {
echo $e->getMessage();
}using System;
using System.Collections.Generic;
using System.Text.Json;
using TryCourier;
using TryCourier.Models;
using Templates = TryCourier.Models.Journeys.Templates;
CourierClient client = new();
Templates::TemplateCreateParams parameters = new()
{
TemplateID = "x",
Channel = "email",
Notification = new()
{
Brand = new("id"),
Content = new()
{
Elements =
[
new ElementalChannelNodeWithType()
{
Channels =
[
"string"
],
If = "if",
Loop = "loop",
Ref = "ref",
Channel = "email",
Elements =
[
new UnionMember0()
{
Channels =
[
"string"
],
If = "if",
Loop = "loop",
Ref = "ref",
Align = Align.Left,
Bold = "bold",
Color = "color",
Content = "Welcome!",
FontSize = "font_size",
Format = Format.Markdown,
Italic = "italic",
LineHeight = "line_height",
Locales = new Dictionary<string, LocalesItem>()
{
{ "foo", new("content") }
},
Strikethrough = "strikethrough",
TextStyle = TextStyle.Text,
Underline = "underline",
Type = UnionMember0IntersectionMember1Type.Text,
},
],
FontSize = "font_size",
LineHeight = "line_height",
Padding = "padding",
Raw = new Dictionary<string, JsonElement>()
{
{ "foo", JsonSerializer.SerializeToElement("bar") }
},
Type = ElementalChannelNodeWithTypeIntersectionMember1Type.Channel,
},
],
Version = Templates::Version.V2022_01_01,
Scope = Templates::Scope.Default,
},
Name = "Welcome email",
Subscription = new("topic_id"),
Tags =
[
"string"
],
},
};
var journeyTemplateGetResponse = await client.Journeys.Templates.Create(parameters);
Console.WriteLine(journeyTemplateGetResponse);courier journeys:templates create \
--api-key 'My API Key' \
--template-id x \
--channel email \
--notification "{brand: {id: id}, content: {elements: [{}], version: '2022-01-01'}, name: Welcome email, subscription: {topic_id: topic_id}, tags: [string]}"curl --request POST \
--url https://api.courier.com/journeys/{templateId}/templates \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"channel": "email",
"notification": {
"name": "Welcome email",
"tags": [],
"brand": null,
"subscription": null,
"content": {
"version": "2022-01-01",
"elements": [
{
"type": "channel",
"channel": "email",
"elements": [
{
"type": "text",
"content": "Welcome!"
}
]
}
]
}
}
}
'{
"name": "Welcome email",
"tags": [],
"brand": null,
"subscription": null,
"content": {
"scope": "default",
"version": "2022-01-01",
"elements": []
}
}