> ## 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.

# Replace Topic in Section

> Replace a topic within a workspace preference. Full document replacement; missing optional fields are cleared. Same 404 rules as GET.



## OpenAPI

````yaml /openapi-specs/openapi.documented.yml put /preferences/sections/{section_id}/topics/{topic_id}
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: []
paths:
  /preferences/sections/{section_id}/topics/{topic_id}:
    put:
      tags:
        - Workspace Preferences
      summary: Replace Topic in Section
      description: >-
        Replace a topic within a workspace preference. Full document
        replacement; missing optional fields are cleared. Same 404 rules as GET.
      operationId: workspacePreferences_topics_replace
      parameters:
        - name: section_id
          in: path
          description: Id of the workspace preference.
          required: true
          schema:
            type: string
        - name: topic_id
          in: path
          description: Id of the subscription preference topic.
          required: true
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/WorkspacePreferenceTopicReplaceRequest'
      responses:
        '200':
          description: ''
          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:
                Example:
                  value:
                    message: Example message text
                    type: invalid_request_error
      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.replace(
              'topic_id',
              {
                section_id: 'section_id',
                default_status: 'OPTED_OUT',
                name: 'name',
              },
            );


            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.replace(
                topic_id="topic_id",
                section_id="section_id",
                default_status="OPTED_OUT",
                name="name",
            )

            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.Replace(\n\t\tcontext.TODO(),\n\t\t\"topic_id\",\n\t\tcourier.WorkspacePreferenceTopicReplaceParams{\n\t\t\tSectionID: \"section_id\",\n\t\t\tWorkspacePreferenceTopicReplaceRequest: courier.WorkspacePreferenceTopicReplaceRequestParam{\n\t\t\t\tDefaultStatus: courier.WorkspacePreferenceTopicReplaceRequestDefaultStatusOptedOut,\n\t\t\t\tName:          \"name\",\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.WorkspacePreferenceTopicGetResponse;

            import
            com.courier.models.workspacepreferences.WorkspacePreferenceTopicReplaceRequest;

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


            public final class Main {
                private Main() {}

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

                    TopicReplaceParams params = TopicReplaceParams.builder()
                        .sectionId("section_id")
                        .topicId("topic_id")
                        .workspacePreferenceTopicReplaceRequest(WorkspacePreferenceTopicReplaceRequest.builder()
                            .defaultStatus(WorkspacePreferenceTopicReplaceRequest.DefaultStatus.OPTED_OUT)
                            .name("name")
                            .build())
                        .build();
                    WorkspacePreferenceTopicGetResponse workspacePreferenceTopicGetResponse = client.workspacePreferences().topics().replace(params);
                }
            }
        - lang: Ruby
          source: >-
            require "courier"


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


            workspace_preference_topic_get_response =
            courier.workspace_preferences.topics.replace(
              "topic_id",
              section_id: "section_id",
              default_status: :OPTED_OUT,
              name: "name"
            )


            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
                ->replace(
                'topic_id',
                sectionID: 'section_id',
                defaultStatus: 'OPTED_OUT',
                name: 'name',
                allowedPreferences: ['snooze'],
                description: 'description',
                includeUnsubscribeHeader: true,
                routingOptions: [ChannelClassification::DIRECT_MESSAGE],
                topicData: ['foo' => 'bar'],
              );

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

            using TryCourier;

            using TryCourier.Models.WorkspacePreferences.Topics;


            CourierClient client = new();


            TopicReplaceParams parameters = new()

            {
                SectionID = "section_id",
                TopicID = "topic_id",
                DefaultStatus = TopicReplaceParamsDefaultStatus.OptedOut,
                Name = "name",
            };


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


            Console.WriteLine(workspacePreferenceTopicGetResponse);
        - lang: CLI
          source: |-
            courier workspace-preferences:topics replace \
              --api-key 'My API Key' \
              --section-id section_id \
              --topic-id topic_id \
              --default-status OPTED_OUT \
              --name name
components:
  schemas:
    WorkspacePreferenceTopicReplaceRequest:
      title: WorkspacePreferenceTopicReplaceRequest
      type: object
      description: >-
        Request body for replacing a preference topic. Full document
        replacement; missing optional fields are cleared.
      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. Omit to clear.
        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. Omit to clear.
        allowed_preferences:
          type: array
          items:
            $ref: '#/components/schemas/AllowedPreference'
          nullable: true
          description: Preference controls a recipient may customize. Omit to clear.
        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. Omit to clear.
      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

````