> ## 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 Workspace Preference

> Creates a workspace preference and returns its generated id. Add subscription topics to it afterwards with the topics endpoint.



## OpenAPI

````yaml /openapi-specs/openapi.documented.yml post /preferences/sections
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:
    post:
      tags:
        - Workspace Preferences
      summary: Create Workspace Preference
      description: >-
        Creates a workspace preference and returns its generated id. Add
        subscription topics to it afterwards with the topics endpoint.
      operationId: workspacePreferences_create
      parameters: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/WorkspacePreferenceCreateRequest'
            examples:
              Minimal:
                value:
                  name: Account Notifications
              Full:
                value:
                  name: Account Notifications
                  routing_options:
                    - email
                    - push
                  has_custom_routing: true
      responses:
        '201':
          description: Created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/WorkspacePreferenceGetResponse'
              examples:
                Example:
                  value:
                    id: ps_01kx4h2jdafq8bk9b6w3knrezh
                    name: Account Notifications
                    routing_options:
                      - direct_message
                    has_custom_routing: true
                    created: '2024-01-15T10:30:00.000Z'
                    creator: user_123
                    updated: '2024-01-15T10:30:00.000Z'
                    updater: user_123
                    topics:
                      - 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
      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 workspacePreferenceGetResponse = await
            client.workspacePreferences.create({
              name: 'Account Notifications',
            });


            console.log(workspacePreferenceGetResponse.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_get_response =
            client.workspace_preferences.create(
                name="Account Notifications",
            )

            print(workspace_preference_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\tworkspacePreferenceGetResponse, err := client.WorkspacePreferences.New(context.TODO(), courier.WorkspacePreferenceNewParams{\n\t\tWorkspacePreferenceCreateRequest: courier.WorkspacePreferenceCreateRequestParam{\n\t\t\tName: \"Account Notifications\",\n\t\t},\n\t})\n\tif err != nil {\n\t\tpanic(err.Error())\n\t}\n\tfmt.Printf(\"%+v\\n\", workspacePreferenceGetResponse.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.WorkspacePreferenceCreateRequest;

            import
            com.courier.models.workspacepreferences.WorkspacePreferenceGetResponse;


            public final class Main {
                private Main() {}

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

                    WorkspacePreferenceCreateRequest params = WorkspacePreferenceCreateRequest.builder()
                        .name("Account Notifications")
                        .build();
                    WorkspacePreferenceGetResponse workspacePreferenceGetResponse = client.workspacePreferences().create(params);
                }
            }
        - lang: Ruby
          source: >-
            require "courier"


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


            workspace_preference_get_response =
            courier.workspace_preferences.create(name: "Account Notifications")


            puts(workspace_preference_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 {
              $workspacePreferenceGetResponse = $client->workspacePreferences->create(
                name: 'Account Notifications',
                description: 'description',
                hasCustomRouting: true,
                routingOptions: [ChannelClassification::DIRECT_MESSAGE],
              );

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

            using TryCourier;

            using TryCourier.Models.WorkspacePreferences;


            CourierClient client = new();


            WorkspacePreferenceCreateParams parameters = new()

            {
                Name = "Account Notifications"
            };


            var workspacePreferenceGetResponse = await
            client.WorkspacePreferences.Create(parameters);


            Console.WriteLine(workspacePreferenceGetResponse);
        - lang: CLI
          source: |-
            courier workspace-preferences create \
              --api-key 'My API Key' \
              --name 'Account Notifications'
components:
  schemas:
    WorkspacePreferenceCreateRequest:
      title: WorkspacePreferenceCreateRequest
      type: object
      description: Request body for creating a workspace preference.
      properties:
        name:
          type: string
          description: Human-readable name for the workspace preference.
        description:
          type: string
          nullable: true
          description: >-
            Optional description shown under the section on the hosted
            preferences page.
        routing_options:
          type: array
          items:
            $ref: '#/components/schemas/ChannelClassification'
          nullable: true
          description: >-
            Default channels for the workspace preference. Defaults to empty if
            omitted.
        has_custom_routing:
          type: boolean
          nullable: true
          description: >-
            Whether the workspace preference defines custom routing for its
            topics.
      required:
        - name
    WorkspacePreferenceGetResponse:
      title: WorkspacePreferenceGetResponse
      type: object
      description: A workspace preference in your workspace, including its topics.
      properties:
        id:
          type: string
          description: The workspace preference id.
        name:
          type: string
          description: Human-readable name.
        description:
          type: string
          nullable: true
          description: >-
            Optional description shown under the section on the hosted
            preferences page.
        routing_options:
          type: array
          items:
            $ref: '#/components/schemas/ChannelClassification'
          description: Default channels for the workspace preference. May be empty.
        has_custom_routing:
          type: boolean
          description: >-
            Whether the workspace preference defines custom routing for its
            topics.
        created:
          type: string
          description: ISO-8601 timestamp of when the workspace preference was created.
        creator:
          type: string
          nullable: true
          description: Id of the creator.
        updated:
          type: string
          nullable: true
          description: ISO-8601 timestamp of the last update.
        updater:
          type: string
          nullable: true
          description: Id of the last updater.
        topics:
          type: array
          items:
            $ref: '#/components/schemas/WorkspacePreferenceTopicGetResponse'
          description: The topics contained in this workspace preference.
      required:
        - id
        - name
        - routing_options
        - has_custom_routing
        - created
        - topics
    BadRequest:
      title: BadRequest
      type: object
      properties:
        type:
          type: string
          enum:
            - invalid_request_error
      required:
        - type
      allOf:
        - $ref: '#/components/schemas/BaseError'
    ChannelClassification:
      title: ChannelClassification
      type: string
      enum:
        - direct_message
        - email
        - push
        - sms
        - webhook
        - inbox
    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
    BaseError:
      title: BaseError
      type: object
      properties:
        message:
          type: string
          description: A message describing the error that occurred.
      required:
        - message
    SubscriptionTopicStatus:
      title: SubscriptionTopicStatus
      type: string
      enum:
        - OPTED_OUT
        - OPTED_IN
        - REQUIRED
    AllowedPreference:
      title: AllowedPreference
      type: string
      description: A preference control a recipient may customize for a topic.
      enum:
        - snooze
        - channel_preferences
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer

````