> ## Documentation Index
> Fetch the complete documentation index at: https://www.courier.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Create Notification Template

> Create a notification template. Requires all fields in the notification object. Templates are created in draft state by default.



## OpenAPI

````yaml /openapi-specs/openapi.documented.yml post /notifications
openapi: 3.0.1
info:
  title: Courier
  description: The Courier REST API.
  version: 0.0.1
servers:
  - url: https://api.courier.com
    description: Production
security: []
paths:
  /notifications:
    post:
      tags:
        - Notification Templates
      summary: Create Notification Template
      description: >-
        Create a notification template. Requires all fields in the notification
        object. Templates are created in draft state by default.
      operationId: notifications_create
      parameters: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/NotificationTemplateCreateRequest'
            examples:
              DraftWithAllFields:
                summary: Create a draft template with all fields populated
                value:
                  notification:
                    name: Welcome Email
                    tags:
                      - onboarding
                      - welcome
                    brand:
                      id: brand_abc
                    subscription:
                      topic_id: marketing
                    routing:
                      strategy_id: rs_123
                    content:
                      version: '2022-01-01'
                      elements:
                        - type: channel
                          channel: email
                          elements:
                            - type: meta
                              title: Welcome!
                            - type: text
                              content: Hello {{data.name}}.
                  state: DRAFT
              MinimalDraft:
                summary: Create a minimal draft template
                value:
                  notification:
                    name: Bare Minimum
                    tags: []
                    brand: null
                    subscription: null
                    routing: null
                    content:
                      version: '2022-01-01'
                      elements: []
              AutoPublish:
                summary: Create and immediately publish
                value:
                  notification:
                    name: Auto-Published Template
                    tags:
                      - alerts
                    brand: null
                    subscription: null
                    routing: null
                    content:
                      version: '2022-01-01'
                      elements:
                        - type: channel
                          channel: email
                          elements:
                            - type: meta
                              title: Alert
                            - type: text
                              content: You have a new alert.
                  state: PUBLISHED
      responses:
        '201':
          description: Created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/NotificationTemplateResponse'
              examples:
                DraftCreated:
                  value:
                    id: nt_01abc123
                    name: Welcome Email
                    tags:
                      - onboarding
                      - welcome
                    brand:
                      id: brand_abc
                    subscription:
                      topic_id: marketing
                    routing:
                      strategy_id: rs_123
                    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
        '400':
          description: Bad Request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/BadRequest'
              examples:
                ValidationError:
                  value:
                    type: invalid_request_error
                    message: >-
                      notification.name: Required; notification.content:
                      Required
                RoutingStrategyNotFound:
                  value:
                    type: invalid_request_error
                    message: Routing strategy rs_nonexistent not found
      security:
        - BearerAuth: []
      x-codeSamples:
        - lang: JavaScript
          source: >-
            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: 'brand_abc' },
                subscription: { topic_id: 'marketing' },
                routing: { strategy_id: 'rs_123' },
                content: { version: '2022-01-01', elements: [{ type: 'channel' }] },
              },
              state: 'DRAFT',
            });


            console.log(notificationTemplateResponse);
        - lang: Python
          source: |-
            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": "brand_abc"
                    },
                    "subscription": {
                        "topic_id": "marketing"
                    },
                    "routing": {
                        "strategy_id": "rs_123"
                    },
                    "content": {
                        "version": "2022-01-01",
                        "elements": [{
                            "type": "channel"
                        }],
                    },
                },
                state="DRAFT",
            )
            print(notification_template_response)
        - lang: Go
          source: "package main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\n\t\"github.com/trycourier/courier-go\"\n\t\"github.com/trycourier/courier-go/option\"\n\t\"github.com/trycourier/courier-go/shared\"\n)\n\nfunc main() {\n\tclient := courier.NewClient(\n\t\toption.WithAPIKey(\"My API Key\"),\n\t)\n\tnotificationTemplateResponse, err := client.Notifications.New(context.TODO(), courier.NotificationNewParams{\n\t\tNotificationTemplateCreateRequest: courier.NotificationTemplateCreateRequestParam{\n\t\t\tNotification: courier.NotificationTemplatePayloadParam{\n\t\t\t\tBrand: courier.NotificationTemplatePayloadBrandParam{\n\t\t\t\t\tID: \"brand_abc\",\n\t\t\t\t},\n\t\t\t\tContent: shared.ElementalContentParam{\n\t\t\t\t\tElements: []shared.ElementalNodeUnionParam{{\n\t\t\t\t\t\tOfElementalTextNodeWithType: &shared.ElementalTextNodeWithTypeParam{\n\t\t\t\t\t\t\tElementalBaseNodeParam: shared.ElementalBaseNodeParam{},\n\t\t\t\t\t\t},\n\t\t\t\t\t}},\n\t\t\t\t\tVersion: \"2022-01-01\",\n\t\t\t\t},\n\t\t\t\tName: \"Welcome Email\",\n\t\t\t\tRouting: courier.NotificationTemplatePayloadRoutingParam{\n\t\t\t\t\tStrategyID: \"rs_123\",\n\t\t\t\t},\n\t\t\t\tSubscription: courier.NotificationTemplatePayloadSubscriptionParam{\n\t\t\t\t\tTopicID: \"marketing\",\n\t\t\t\t},\n\t\t\t\tTags: []string{\"onboarding\", \"welcome\"},\n\t\t\t},\n\t\t},\n\t})\n\tif err != nil {\n\t\tpanic(err.Error())\n\t}\n\tfmt.Printf(\"%+v\\n\", notificationTemplateResponse)\n}\n"
        - lang: Java
          source: >-
            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("brand_abc")
                                .build())
                            .content(ElementalContent.builder()
                                .addElement(ElementalTextNodeWithType.builder().build())
                                .version("2022-01-01")
                                .build())
                            .name("Welcome Email")
                            .routing(NotificationTemplatePayload.Routing.builder()
                                .strategyId("rs_123")
                                .build())
                            .subscription(NotificationTemplatePayload.Subscription.builder()
                                .topicId("marketing")
                                .build())
                            .addTag("onboarding")
                            .addTag("welcome")
                            .build())
                        .build();
                    NotificationTemplateResponse notificationTemplateResponse = client.notifications().create(params);
                }
            }
        - lang: Ruby
          source: |-
            require "courier"

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

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

            puts(notification_template_response)
        - lang: PHP
          source: >-
            <?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' => 'brand_abc'],
                  'content' => [
                    'elements' => [['type' => 'channel']], 'version' => '2022-01-01'
                  ],
                  'name' => 'Welcome Email',
                  'routing' => ['strategyID' => 'rs_123'],
                  'subscription' => ['topicID' => 'marketing'],
                  'tags' => ['onboarding', 'welcome'],
                ],
                state: 'DRAFT',
              );

              var_dump($notificationTemplateResponse);
            } catch (APIException $e) {
              echo $e->getMessage();
            }
        - lang: C#
          source: >-
            using System;

            using Courier;

            using Courier.Models;

            using Courier.Models.Notifications;


            CourierClient client = new();


            NotificationCreateParams parameters = new()

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


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


            Console.WriteLine(notificationTemplateResponse);
        - lang: CLI
          source: |-
            courier notifications create \
              --api-key 'My API Key' \
              --notification "{brand: {id: brand_abc}, content: {elements: [{}], version: '2022-01-01'}, name: Welcome Email, routing: {strategy_id: rs_123}, subscription: {topic_id: marketing}, tags: [onboarding, welcome]}"
components:
  schemas:
    NotificationTemplateCreateRequest:
      title: NotificationTemplateCreateRequest
      type: object
      description: Request body for creating a notification template.
      properties:
        notification:
          $ref: '#/components/schemas/NotificationTemplatePayload'
        state:
          type: string
          description: >-
            Template state after creation. Case-insensitive input, normalized to
            uppercase in the response. Defaults to "DRAFT".
          enum:
            - DRAFT
            - PUBLISHED
          default: DRAFT
      required:
        - notification
    NotificationTemplateResponse:
      title: NotificationTemplateResponse
      description: >-
        Response for GET /notifications/{id}, POST /notifications, and PUT
        /notifications/{id}. Returns all template fields at the top level.
      allOf:
        - $ref: '#/components/schemas/NotificationTemplatePayload'
        - type: object
          properties:
            id:
              type: string
              description: The template ID.
            state:
              type: string
              description: The template state. Always uppercase.
              enum:
                - DRAFT
                - PUBLISHED
            created:
              type: integer
              format: int64
              description: Epoch milliseconds when the template was created.
            creator:
              type: string
              description: User ID of the creator.
            updated:
              type: integer
              format: int64
              description: Epoch milliseconds of last update.
            updater:
              type: string
              description: User ID of the last updater.
          required:
            - id
            - state
            - created
            - creator
    BadRequest:
      title: BadRequest
      type: object
      properties:
        type:
          type: string
          enum:
            - invalid_request_error
      required:
        - type
      allOf:
        - $ref: '#/components/schemas/BaseError'
    NotificationTemplatePayload:
      title: NotificationTemplatePayload
      type: object
      description: >-
        Core template fields used in POST and PUT request bodies (nested under a
        `notification` key) and returned at the top level in responses.
      properties:
        name:
          type: string
          description: Display name for the template.
        tags:
          type: array
          items:
            type: string
          description: Tags for categorization. Send empty array for none.
        brand:
          nullable: true
          type: object
          description: Brand reference, or null for no brand.
          properties:
            id:
              type: string
          required:
            - id
        subscription:
          nullable: true
          type: object
          description: Subscription topic reference, or null for none.
          properties:
            topic_id:
              type: string
          required:
            - topic_id
        routing:
          nullable: true
          type: object
          description: Routing strategy reference, or null for none.
          properties:
            strategy_id:
              type: string
          required:
            - strategy_id
        content:
          $ref: '#/components/schemas/ElementalContent'
          description: Elemental content definition.
      required:
        - name
        - tags
        - brand
        - subscription
        - routing
        - content
    BaseError:
      title: BaseError
      type: object
      properties:
        message:
          type: string
          description: A message describing the error that occurred.
      required:
        - message
    ElementalContent:
      title: ElementalContent
      type: object
      properties:
        version:
          type: string
          description: For example, "2022-01-01"
        elements:
          type: array
          items:
            $ref: '#/components/schemas/ElementalNode'
      required:
        - version
        - elements
    ElementalNode:
      title: ElementalNode
      oneOf:
        - type: object
          allOf:
            - type: object
              properties:
                type:
                  type: string
                  enum:
                    - text
            - $ref: '#/components/schemas/ElementalTextNode'
          required:
            - type
        - type: object
          allOf:
            - type: object
              properties:
                type:
                  type: string
                  enum:
                    - meta
            - $ref: '#/components/schemas/ElementalMetaNode'
          required:
            - type
        - type: object
          allOf:
            - type: object
              properties:
                type:
                  type: string
                  enum:
                    - channel
            - $ref: '#/components/schemas/ElementalChannelNode'
          required:
            - type
            - channel
        - type: object
          allOf:
            - type: object
              properties:
                type:
                  type: string
                  enum:
                    - image
            - $ref: '#/components/schemas/ElementalImageNode'
          required:
            - type
        - type: object
          allOf:
            - type: object
              properties:
                type:
                  type: string
                  enum:
                    - action
            - $ref: '#/components/schemas/ElementalActionNode'
          required:
            - type
        - type: object
          allOf:
            - type: object
              properties:
                type:
                  type: string
                  enum:
                    - divider
            - $ref: '#/components/schemas/ElementalDividerNode'
          required:
            - type
        - type: object
          allOf:
            - type: object
              properties:
                type:
                  type: string
                  enum:
                    - quote
            - $ref: '#/components/schemas/ElementalQuoteNode'
          required:
            - type
        - type: object
          allOf:
            - type: object
              properties:
                type:
                  type: string
                  enum:
                    - html
            - $ref: '#/components/schemas/ElementalHtmlNode'
          required:
            - type
    ElementalTextNode:
      title: ElementalTextNode
      type: object
      description: Represents a body of text to be rendered inside of the notification.
      properties:
        content:
          type: string
          description: |-
            The text content displayed in the notification. Either this
            field must be specified, or the elements field
        align:
          $ref: '#/components/schemas/TextAlign'
          description: Text alignment.
        text_style:
          $ref: '#/components/schemas/TextStyle'
          nullable: true
          description: Allows the text to be rendered as a heading level.
        color:
          type: string
          nullable: true
          description: Specifies the color of text. Can be any valid css color value
        bold:
          type: string
          nullable: true
          description: Apply bold to the text
        italic:
          type: string
          nullable: true
          description: Apply italics to the text
        strikethrough:
          type: string
          nullable: true
          description: Apply a strike through the text
        underline:
          type: string
          nullable: true
          description: Apply an underline to the text
        locales:
          $ref: '#/components/schemas/Locales'
          nullable: true
          description: >-
            Region specific content. See [locales
            docs](https://www.courier.com/docs/platform/content/elemental/locales/)
            for more details.
        format:
          type: string
          enum:
            - markdown
          nullable: true
      required:
        - content
        - align
      allOf:
        - $ref: '#/components/schemas/ElementalBaseNode'
    ElementalMetaNode:
      title: ElementalMetaNode
      type: object
      description: >-
        The meta element contains information describing the notification that
        may 

        be used by a particular channel or provider. One important field is the
        title 

        field which will be used as the title for channels that support it.
      properties:
        title:
          type: string
          nullable: true
          description: >-
            The title to be displayed by supported channels. For example, the
            email subject.
      allOf:
        - $ref: '#/components/schemas/ElementalBaseNode'
    ElementalChannelNode:
      title: ElementalChannelNode
      type: object
      description: >-
        The channel element allows a notification to be customized based on
        which channel it is sent through. 

        For example, you may want to display a detailed message when the
        notification is sent through email, 

        and a more concise message in a push notification. Channel elements are
        only valid as top-level 

        elements; you cannot nest channel elements. If there is a channel
        element specified at the top-level 

        of the document, all sibling elements must be channel elements.

        Note: As an alternative, most elements support a `channel` property.
        Which allows you to selectively 

        display an individual element on a per channel basis. See the 

        [control flow
        docs](https://www.courier.com/docs/platform/content/elemental/control-flow/)
        for more details.
      properties:
        channel:
          type: string
          example: email
          description: >-
            The channel the contents of this element should be applied to. Can
            be `email`,

            `push`, `direct_message`, `sms` or a provider such as slack
        raw:
          type: object
          additionalProperties: true
          nullable: true
          description: >-
            Raw data to apply to the channel. If `elements` has not been
            specified, `raw` is required.
      allOf:
        - $ref: '#/components/schemas/ElementalBaseNode'
    ElementalImageNode:
      title: ElementalImageNode
      type: object
      description: Used to embed an image into the notification.
      properties:
        src:
          type: string
          description: The source of the image.
        href:
          type: string
          nullable: true
          description: A URL to link to when the image is clicked.
        align:
          $ref: '#/components/schemas/IAlignment'
          nullable: true
          description: The alignment of the image.
        altText:
          type: string
          nullable: true
          description: Alternate text for the image.
        width:
          type: string
          nullable: true
          description: CSS width properties to apply to the image. For example, 50px
      required:
        - src
      allOf:
        - $ref: '#/components/schemas/ElementalBaseNode'
    ElementalActionNode:
      title: ElementalActionNode
      type: object
      description: Allows the user to execute an action. Can be a button or a link.
      properties:
        content:
          type: string
          description: The text content of the action shown to the user.
        href:
          type: string
          description: The target URL of the action.
        action_id:
          type: string
          nullable: true
          description: A unique id used to identify the action when it is executed.
        align:
          nullable: true
          description: The alignment of the action button. Defaults to "center".
          allOf:
            - $ref: '#/components/schemas/IAlignment'
        background_color:
          type: string
          nullable: true
          description: The background color of the action button.
        style:
          nullable: true
          description: Defaults to `button`.
          allOf:
            - $ref: '#/components/schemas/IActionButtonStyle'
        locales:
          description: >-
            Region specific content. See [locales
            docs](https://www.courier.com/docs/platform/content/elemental/locales/)
            for more details.
          allOf:
            - $ref: '#/components/schemas/Locales'
      required:
        - content
        - href
        - locales
      allOf:
        - $ref: '#/components/schemas/ElementalBaseNode'
    ElementalDividerNode:
      title: ElementalDividerNode
      type: object
      description: Renders a dividing line between elements.
      properties:
        color:
          type: string
          nullable: true
          description: The CSS color to render the line with. For example, `#fff`
      allOf:
        - $ref: '#/components/schemas/ElementalBaseNode'
    ElementalQuoteNode:
      title: ElementalQuoteNode
      type: object
      description: Renders a quote block.
      properties:
        content:
          type: string
          description: The text value of the quote.
        align:
          $ref: '#/components/schemas/IAlignment'
          nullable: true
          description: Alignment of the quote.
        borderColor:
          type: string
          nullable: true
          description: CSS border color property. For example, `#fff`
        text_style:
          $ref: '#/components/schemas/TextStyle'
        locales:
          $ref: '#/components/schemas/Locales'
          description: >-
            Region specific content. See [locales
            docs](https://www.courier.com/docs/platform/content/elemental/locales/)
            for more details.
      required:
        - content
        - text_style
        - locales
      allOf:
        - $ref: '#/components/schemas/ElementalBaseNode'
    ElementalHtmlNode:
      title: ElementalHtmlNode
      type: object
      description: >-
        Raw HTML string inside an Elemental document. When rendering a message,
        this node is turned into output only for the email channel; for other
        channels it produces no blocks.
      properties:
        content:
          type: string
          description: Raw HTML string to render inside the notification.
        locales:
          $ref: '#/components/schemas/Locales'
          nullable: true
          description: >-
            Region-specific `content` overrides. See [locales
            docs](https://www.courier.com/docs/platform/content/elemental/locales/)
            for more details.
      required:
        - content
      allOf:
        - $ref: '#/components/schemas/ElementalBaseNode'
    TextAlign:
      title: TextAlign
      type: string
      enum:
        - left
        - center
        - right
    TextStyle:
      title: TextStyle
      type: string
      enum:
        - text
        - h1
        - h2
        - subtext
    Locales:
      title: Locales
      type: object
      additionalProperties:
        $ref: '#/components/schemas/Locale'
      nullable: true
    ElementalBaseNode:
      title: ElementalBaseNode
      type: object
      properties:
        channels:
          type: array
          items:
            type: string
          nullable: true
        ref:
          type: string
          nullable: true
        if:
          type: string
          nullable: true
        loop:
          type: string
          nullable: true
    IAlignment:
      title: IAlignment
      type: string
      enum:
        - center
        - left
        - right
        - full
    IActionButtonStyle:
      title: IActionButtonStyle
      type: string
      enum:
        - button
        - link
    Locale:
      title: Locale
      type: object
      properties:
        content:
          type: string
      required:
        - content
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer

````