> ## 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 Topic in Section

> Creates a subscription topic inside a workspace preference. The default status sets whether users start opted in, opted out, or required.



## OpenAPI

````yaml /openapi-specs/openapi.documented.yml post /preferences/sections/{section_id}/topics
openapi: 3.0.1
info:
  title: Courier
  description: The Courier REST API for sending and managing notifications across channels.
  version: 0.0.1
servers:
  - url: https://api.courier.com
    description: Production
security: []
tags:
  - name: Send
    description: >-
      Send a message to one or more recipients — users, lists, audiences, or
      tenants — across every channel you have configured.
  - name: Templates
    description: >-
      Create, update, version, publish, and localize notification templates and
      their content.
  - name: Brands
    description: >-
      Manage the logos, colors, and layout that give the templates you send a
      consistent look.
  - name: Routing Strategies
    description: >-
      Define reusable channel routing and failover strategies, and see which
      templates use them.
  - name: Journeys
    description: >-
      Build, version, publish, invoke, and cancel multi-step notification
      workflows, along with the templates scoped to them.
  - name: Broadcasts
    description: >-
      Create a one-off send to a list or audience, author its content, then send
      it immediately or schedule it for later.
  - name: User Profiles
    description: >-
      Store the contact information Courier delivers to for each user — email,
      phone number, push tokens, and any custom data you send to.
  - name: Tenants
    description: >-
      Manage tenants — the organizations, teams, or accounts your users belong
      to — along with their users and default preferences.
  - name: Audiences
    description: >-
      Define filter-based groups whose membership Courier recalculates as user
      profiles change.
  - name: Lists
    description: >-
      Manage static groups of users that you subscribe explicitly, and send to
      them by list id or list pattern.
  - name: Providers
    description: >-
      Configure the channel providers Courier delivers through, and browse the
      provider types it supports.
  - name: Preference Topics
    description: >-
      Manage the workspace catalog of subscription topics, the sections that
      group them, and publishing the preference page.
  - name: User Preferences
    description: >-
      Read and write a single user's notification preferences, per topic and per
      channel.
  - name: Messages
    description: >-
      Look up the messages Courier has accepted, inspect their delivery history
      and rendered output, and cancel, resend, or archive them.
  - name: Device Tokens
    description: >-
      Register and manage the APNS and FCM device tokens Courier delivers push
      notifications to.
  - name: Tenant Memberships
    description: >-
      Associate a user with one or more tenants, and read or remove those
      associations.
  - name: Tenant Templates
    description: >-
      Manage the templates and template versions scoped to a single tenant,
      including the ones authored in the embedded designer.
  - name: Automations
    description: >-
      Invoke a stored automation template or an ad hoc automation defined in the
      request.
  - name: Digests
    description: >-
      Inspect what has accumulated in a digest schedule and release a digest
      ahead of its next scheduled delivery.
  - name: Translations
    description: >-
      Store and retrieve the translation strings Courier uses to render
      localized template content.
  - name: Inbox
    description: Manage the messages in a user's in-app inbox.
  - name: Track Events
    description: >-
      Record an inbound event that triggers the journeys and automations mapped
      to it.
  - name: Audit Events
    description: >-
      Read the audit trail of configuration and access changes in your
      workspace.
  - name: Authentication
    description: >-
      Issue scoped, short-lived JWTs so client-side SDKs — Inbox, Preferences,
      and the embedded designer — can call Courier as a single user. Server-side
      requests authenticate with your workspace API key instead.
paths:
  /preferences/sections/{section_id}/topics:
    post:
      tags:
        - Preference Topics
      summary: Create Topic in Section
      description: >-
        Creates a subscription topic inside a workspace preference. The default
        status sets whether users start opted in, opted out, or required.
      operationId: workspacePreferences_topics_create
      parameters:
        - $ref: '#/components/parameters/IdempotencyKey'
        - $ref: '#/components/parameters/IdempotencyExpiration'
        - name: section_id
          in: path
          description: Id of the workspace preference to create the topic in.
          required: true
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/WorkspacePreferenceTopicCreateRequest'
            examples:
              Minimal:
                value:
                  name: Marketing
                  default_status: OPTED_OUT
              Full:
                value:
                  name: Product Updates
                  default_status: OPTED_IN
                  routing_options:
                    - email
                    - push
                  allowed_preferences:
                    - channel_preferences
                    - snooze
                  include_unsubscribe_header: true
      responses:
        '201':
          description: Created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/WorkspacePreferenceTopicGetResponse'
              examples:
                Example:
                  value:
                    id: pt_01kx4h2jdafq8bk99mj9q2gsa2
                    name: Product Updates
                    default_status: OPTED_OUT
                    routing_options:
                      - direct_message
                    allowed_preferences:
                      - snooze
                    include_unsubscribe_header: true
                    topic_data: {}
                    created: '2024-01-15T10:30:00.000Z'
                    creator: user_123
                    updated: '2024-01-15T10:30:00.000Z'
                    updater: user_123
        '400':
          description: Bad Request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/BadRequest'
              examples:
                Example:
                  value:
                    message: Example message text
                    type: invalid_request_error
        '404':
          description: Not Found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/NotFound'
              examples:
                WorkspacePreferenceNotFound:
                  value:
                    type: invalid_request_error
                    message: Workspace preference 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 workspacePreferenceTopicGetResponse = await
            client.workspacePreferences.topics.create(
              'section_id',
              { default_status: 'OPTED_OUT', name: 'Marketing' },
            );


            console.log(workspacePreferenceTopicGetResponse.id);
        - 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
            )

            workspace_preference_topic_get_response =
            client.workspace_preferences.topics.create(
                section_id="section_id",
                default_status="OPTED_OUT",
                name="Marketing",
            )

            print(workspace_preference_topic_get_response.id)
        - 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)\n\nfunc main() {\n\tclient := courier.NewClient(\n\t\toption.WithAPIKey(\"My API Key\"),\n\t)\n\tworkspacePreferenceTopicGetResponse, err := client.WorkspacePreferences.Topics.New(\n\t\tcontext.TODO(),\n\t\t\"section_id\",\n\t\tcourier.WorkspacePreferenceTopicNewParams{\n\t\t\tWorkspacePreferenceTopicCreateRequest: courier.WorkspacePreferenceTopicCreateRequestParam{\n\t\t\t\tDefaultStatus: courier.WorkspacePreferenceTopicCreateRequestDefaultStatusOptedOut,\n\t\t\t\tName:          \"Marketing\",\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\", workspacePreferenceTopicGetResponse.ID)\n}\n"
        - lang: Java
          source: >-
            package com.courier.example;


            import com.courier.client.CourierClient;

            import com.courier.client.okhttp.CourierOkHttpClient;

            import
            com.courier.models.workspacepreferences.WorkspacePreferenceTopicCreateRequest;

            import
            com.courier.models.workspacepreferences.WorkspacePreferenceTopicGetResponse;

            import
            com.courier.models.workspacepreferences.topics.TopicCreateParams;


            public final class Main {
                private Main() {}

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

                    TopicCreateParams params = TopicCreateParams.builder()
                        .sectionId("section_id")
                        .workspacePreferenceTopicCreateRequest(WorkspacePreferenceTopicCreateRequest.builder()
                            .defaultStatus(WorkspacePreferenceTopicCreateRequest.DefaultStatus.OPTED_OUT)
                            .name("Marketing")
                            .build())
                        .build();
                    WorkspacePreferenceTopicGetResponse workspacePreferenceTopicGetResponse = client.workspacePreferences().topics().create(params);
                }
            }
        - lang: Ruby
          source: >-
            require "courier"


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


            workspace_preference_topic_get_response =
            courier.workspace_preferences.topics.create("section_id",
            default_status: :OPTED_OUT, name: "Marketing")


            puts(workspace_preference_topic_get_response)
        - lang: PHP
          source: >-
            <?php


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


            use Courier\Client;

            use Courier\ChannelClassification;

            use Courier\Core\Exceptions\APIException;


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


            try {
              $workspacePreferenceTopicGetResponse = $client
                ->workspacePreferences
                ->topics
                ->create(
                'section_id',
                defaultStatus: 'OPTED_OUT',
                name: 'Marketing',
                allowedPreferences: ['snooze'],
                description: 'description',
                includeUnsubscribeHeader: true,
                routingOptions: [ChannelClassification::DIRECT_MESSAGE],
                topicData: ['foo' => 'bar'],
                idempotencyKey: 'order-ORD-456-user-123',
                xIdempotencyExpiration: '1785312000',
              );

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

            using TryCourier;

            using TryCourier.Models.WorkspacePreferences.Topics;


            CourierClient client = new();


            TopicCreateParams parameters = new()

            {
                SectionID = "section_id",
                DefaultStatus = DefaultStatus.OptedOut,
                Name = "Marketing",
            };


            var workspacePreferenceTopicGetResponse = await
            client.WorkspacePreferences.Topics.Create(parameters);


            Console.WriteLine(workspacePreferenceTopicGetResponse);
        - lang: CLI
          source: |-
            courier workspace-preferences:topics create \
              --api-key 'My API Key' \
              --section-id section_id \
              --default-status OPTED_OUT \
              --name Marketing
components:
  parameters:
    IdempotencyKey:
      name: Idempotency-Key
      in: header
      required: false
      description: >-
        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.
      schema:
        type: string
      example: order-ORD-456-user-123
    IdempotencyExpiration:
      name: x-idempotency-expiration
      in: header
      required: false
      description: >-
        How long the idempotency key remains valid, as a Unix epoch timestamp in
        seconds or an ISO 8601 date string. Only applies when `Idempotency-Key`
        is provided. If omitted, the key is retained for 25 hours; the maximum
        is 1 year.
      schema:
        type: string
      example: '1785312000'
  schemas:
    WorkspacePreferenceTopicCreateRequest:
      title: WorkspacePreferenceTopicCreateRequest
      type: object
      description: Request body for creating a preference topic.
      properties:
        name:
          type: string
          description: Human-readable name for the preference topic.
        description:
          type: string
          nullable: true
          description: >-
            Optional description shown under the topic on the hosted preferences
            page.
        default_status:
          $ref: '#/components/schemas/SubscriptionTopicStatus'
          description: >-
            The default subscription status applied when a recipient has not set
            their own.
        routing_options:
          type: array
          items:
            $ref: '#/components/schemas/ChannelClassification'
          nullable: true
          description: >-
            Default channels delivered for this topic. Defaults to empty if
            omitted.
        allowed_preferences:
          type: array
          items:
            $ref: '#/components/schemas/AllowedPreference'
          nullable: true
          description: >-
            Preference controls a recipient may customize for this topic.
            Defaults to empty if omitted.
        include_unsubscribe_header:
          type: boolean
          nullable: true
          description: >-
            Whether to include a list-unsubscribe header on emails for this
            topic.
        topic_data:
          type: object
          additionalProperties: true
          nullable: true
          description: Arbitrary metadata associated with the topic.
      required:
        - name
        - default_status
    WorkspacePreferenceTopicGetResponse:
      title: WorkspacePreferenceTopicGetResponse
      type: object
      description: A subscription preference topic in your workspace.
      properties:
        id:
          type: string
          description: The preference topic id.
        name:
          type: string
          description: Human-readable name.
        description:
          type: string
          nullable: true
          description: >-
            Optional description shown under the topic on the hosted preferences
            page.
        default_status:
          $ref: '#/components/schemas/SubscriptionTopicStatus'
          description: >-
            The default subscription status applied when a recipient has not set
            their own.
        routing_options:
          type: array
          items:
            $ref: '#/components/schemas/ChannelClassification'
          description: Default channels delivered for this topic. May be empty.
        allowed_preferences:
          type: array
          items:
            $ref: '#/components/schemas/AllowedPreference'
          description: Preference controls a recipient may customize. May be empty.
        include_unsubscribe_header:
          type: boolean
          description: >-
            Whether a list-unsubscribe header is included on emails for this
            topic.
        topic_data:
          type: object
          additionalProperties: true
          description: Arbitrary metadata associated with the topic.
        created:
          type: string
          description: ISO-8601 timestamp of when the topic was created.
        creator:
          type: string
          nullable: true
          description: Id of the creator.
        updated:
          type: string
          description: ISO-8601 timestamp of the last update.
        updater:
          type: string
          nullable: true
          description: Id of the last updater.
      required:
        - id
        - name
        - default_status
        - routing_options
        - allowed_preferences
        - include_unsubscribe_header
        - topic_data
        - created
        - updated
    BadRequest:
      title: BadRequest
      type: object
      properties:
        type:
          type: string
          enum:
            - invalid_request_error
      required:
        - type
      allOf:
        - $ref: '#/components/schemas/BaseError'
    NotFound:
      title: NotFound
      type: object
      properties:
        type:
          type: string
          enum:
            - invalid_request_error
      required:
        - type
      allOf:
        - $ref: '#/components/schemas/BaseError'
    SubscriptionTopicStatus:
      title: SubscriptionTopicStatus
      type: string
      enum:
        - OPTED_OUT
        - OPTED_IN
        - REQUIRED
    ChannelClassification:
      title: ChannelClassification
      type: string
      enum:
        - direct_message
        - email
        - push
        - sms
        - webhook
        - inbox
    AllowedPreference:
      title: AllowedPreference
      type: string
      description: A preference control a recipient may customize for a topic.
      enum:
        - snooze
        - channel_preferences
    BaseError:
      title: BaseError
      type: object
      properties:
        message:
          type: string
          description: A message describing the error that occurred.
      required:
        - message
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer

````