> ## 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 Routing Strategy

> Create a routing strategy. Requires a name and routing configuration at minimum. Channels and providers default to empty if omitted.



## OpenAPI

````yaml /openapi-specs/openapi.documented.yml post /routing-strategies
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:
  /routing-strategies:
    post:
      tags:
        - Routing Strategies
      summary: Create Routing Strategy
      description: >-
        Create a routing strategy. Requires a name and routing configuration at
        minimum. Channels and providers default to empty if omitted.
      operationId: routingStrategies_create
      parameters: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/RoutingStrategyCreateRequest'
            examples:
              FullExample:
                summary: Create a routing strategy with all fields
                value:
                  name: Email via SendGrid
                  description: Routes email through sendgrid with SES failover
                  tags:
                    - production
                    - email
                  routing:
                    method: single
                    channels:
                      - email
                  channels:
                    email:
                      providers:
                        - sendgrid
                        - ses
                  providers:
                    sendgrid:
                      override: {}
              Minimal:
                summary: Create a minimal routing strategy
                value:
                  name: Simple Email
                  routing:
                    method: single
                    channels:
                      - email
      responses:
        '201':
          description: Created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/RoutingStrategyGetResponse'
        '400':
          description: Bad Request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/BadRequest'
              examples:
                ValidationError:
                  value:
                    type: invalid_request_error
                    message: 'name: Required; routing: Required'
      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 routingStrategyGetResponse = await
            client.routingStrategies.create({
              name: 'Email via SendGrid',
              routing: { method: 'single', channels: ['email'] },
              channels: { email: { providers: ['sendgrid', 'ses'] } },
              description: 'Routes email through sendgrid with SES failover',
              providers: { sendgrid: { override: {} } },
              tags: ['production', 'email'],
            });


            console.log(routingStrategyGetResponse.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
            )
            routing_strategy_get_response = client.routing_strategies.create(
                name="Email via SendGrid",
                routing={
                    "method": "single",
                    "channels": ["email"],
                },
                channels={
                    "email": {
                        "providers": ["sendgrid", "ses"]
                    }
                },
                description="Routes email through sendgrid with SES failover",
                providers={
                    "sendgrid": {
                        "override": {}
                    }
                },
                tags=["production", "email"],
            )
            print(routing_strategy_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\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\troutingStrategyGetResponse, err := client.RoutingStrategies.New(context.TODO(), courier.RoutingStrategyNewParams{\n\t\tRoutingStrategyCreateRequest: courier.RoutingStrategyCreateRequestParam{\n\t\t\tName: \"Email via SendGrid\",\n\t\t\tRouting: shared.MessageRoutingParam{\n\t\t\t\tChannels: []shared.MessageRoutingChannelUnionParam{{\n\t\t\t\t\tOfString: courier.String(\"email\"),\n\t\t\t\t}},\n\t\t\t\tMethod: shared.MessageRoutingMethodSingle,\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\", routingStrategyGetResponse.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.MessageRouting;

            import
            com.courier.models.routingstrategies.RoutingStrategyCreateRequest;

            import
            com.courier.models.routingstrategies.RoutingStrategyGetResponse;


            public final class Main {
                private Main() {}

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

                    RoutingStrategyCreateRequest params = RoutingStrategyCreateRequest.builder()
                        .name("Email via SendGrid")
                        .routing(MessageRouting.builder()
                            .addChannel("email")
                            .method(MessageRouting.Method.SINGLE)
                            .build())
                        .build();
                    RoutingStrategyGetResponse routingStrategyGetResponse = client.routingStrategies().create(params);
                }
            }
        - lang: Ruby
          source: |-
            require "courier"

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

            routing_strategy_get_response = courier.routing_strategies.create(
              name: "Email via SendGrid",
              routing: {channels: ["email"], method: :single}
            )

            puts(routing_strategy_get_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 {
              $routingStrategyGetResponse = $client->routingStrategies->create(
                name: 'Email via SendGrid',
                routing: ['channels' => ['email'], 'method' => 'single'],
                channels: [
                  'email' => [
                    'brandID' => 'brand_id',
                    'if' => 'if',
                    'metadata' => [
                      'utm' => [
                        'campaign' => 'campaign',
                        'content' => 'content',
                        'medium' => 'medium',
                        'source' => 'source',
                        'term' => 'term',
                      ],
                    ],
                    'override' => ['foo' => 'bar'],
                    'providers' => ['sendgrid', 'ses'],
                    'routingMethod' => 'all',
                    'timeouts' => ['channel' => 0, 'provider' => 0],
                  ],
                ],
                description: 'Routes email through sendgrid with SES failover',
                providers: [
                  'sendgrid' => [
                    'if' => 'if',
                    'metadata' => [
                      'utm' => [
                        'campaign' => 'campaign',
                        'content' => 'content',
                        'medium' => 'medium',
                        'source' => 'source',
                        'term' => 'term',
                      ],
                    ],
                    'override' => [],
                    'timeouts' => 0,
                  ],
                ],
                tags: ['production', 'email'],
              );

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

            using Courier;

            using Courier.Models;

            using Courier.Models.RoutingStrategies;


            CourierClient client = new();


            RoutingStrategyCreateParams parameters = new()

            {
                Name = "Email via SendGrid",
                Routing = new()
                {
                    Channels =
                    [
                        "email"
                    ],
                    Method = Method.Single,
                },
            };


            var routingStrategyGetResponse = await
            client.RoutingStrategies.Create(parameters);


            Console.WriteLine(routingStrategyGetResponse);
        - lang: CLI
          source: |-
            courier routing-strategies create \
              --api-key 'My API Key' \
              --name 'Email via SendGrid' \
              --routing '{channels: [email], method: single}'
components:
  schemas:
    RoutingStrategyCreateRequest:
      title: RoutingStrategyCreateRequest
      type: object
      description: Request body for creating a routing strategy.
      properties:
        name:
          type: string
          description: Human-readable name for the routing strategy.
        description:
          type: string
          nullable: true
          description: Optional description of the routing strategy.
        tags:
          type: array
          items:
            type: string
          nullable: true
          description: Optional tags for categorization.
        routing:
          $ref: '#/components/schemas/MessageRouting'
          description: Routing tree defining channel selection method and order.
        channels:
          $ref: '#/components/schemas/MessageChannels'
          nullable: true
          description: Per-channel delivery configuration. Defaults to empty if omitted.
        providers:
          $ref: '#/components/schemas/MessageProviders'
          nullable: true
          description: Per-provider delivery configuration. Defaults to empty if omitted.
      required:
        - name
        - routing
    RoutingStrategyGetResponse:
      title: RoutingStrategyGetResponse
      type: object
      description: Full routing strategy entity returned by GET.
      properties:
        id:
          type: string
          description: The routing strategy ID (rs_ prefix).
        name:
          type: string
          description: Human-readable name.
        description:
          type: string
          nullable: true
          description: Description of the routing strategy.
        tags:
          type: array
          items:
            type: string
          nullable: true
          description: Tags for categorization.
        routing:
          $ref: '#/components/schemas/MessageRouting'
          description: Routing tree defining channel selection method and order.
        channels:
          $ref: '#/components/schemas/MessageChannels'
          description: Per-channel delivery configuration. May be empty.
        providers:
          $ref: '#/components/schemas/MessageProviders'
          description: Per-provider delivery configuration. May be empty.
        created:
          type: integer
          format: int64
          description: Epoch milliseconds when the strategy was created.
        creator:
          type: string
          description: User ID of the creator.
        updated:
          type: integer
          format: int64
          nullable: true
          description: Epoch milliseconds of last update.
        updater:
          type: string
          nullable: true
          description: User ID of the last updater.
      required:
        - id
        - name
        - routing
        - channels
        - providers
        - created
        - creator
    BadRequest:
      title: BadRequest
      type: object
      properties:
        type:
          type: string
          enum:
            - invalid_request_error
      required:
        - type
      allOf:
        - $ref: '#/components/schemas/BaseError'
    MessageRouting:
      title: MessageRouting
      type: object
      properties:
        method:
          $ref: '#/components/schemas/MessageRoutingMethod'
        channels:
          type: array
          items:
            $ref: '#/components/schemas/MessageRoutingChannel'
      required:
        - method
        - channels
    MessageChannels:
      title: MessageChannels
      type: object
      additionalProperties:
        $ref: '#/components/schemas/Channel'
    MessageProviders:
      title: MessageProviders
      type: object
      additionalProperties:
        $ref: '#/components/schemas/MessageProvidersType'
    BaseError:
      title: BaseError
      type: object
      properties:
        message:
          type: string
          description: A message describing the error that occurred.
      required:
        - message
    MessageRoutingMethod:
      title: MessageRoutingMethod
      type: string
      enum:
        - all
        - single
    MessageRoutingChannel:
      title: MessageRoutingChannel
      oneOf:
        - type: string
        - $ref: '#/components/schemas/MessageRouting'
    Channel:
      title: Channel
      type: object
      properties:
        brand_id:
          type: string
          nullable: true
          description: Brand id used for rendering.
        providers:
          type: array
          items:
            type: string
          nullable: true
          description: Providers enabled for this channel.
        routing_method:
          $ref: '#/components/schemas/RoutingMethod'
          nullable: true
          description: Defaults to `single`.
        if:
          type: string
          nullable: true
          description: JS conditional with access to data/profile.
        timeouts:
          $ref: '#/components/schemas/Timeouts'
          nullable: true
        override:
          type: object
          additionalProperties: true
          nullable: true
          description: Channel specific overrides.
        metadata:
          $ref: '#/components/schemas/ChannelMetadata'
          nullable: true
    MessageProvidersType:
      title: MessageProvidersType
      type: object
      properties:
        override:
          type: object
          additionalProperties: true
          nullable: true
          description: Provider-specific overrides.
        if:
          type: string
          nullable: true
          description: JS conditional with access to data/profile.
        timeouts:
          type: integer
          nullable: true
        metadata:
          $ref: '#/components/schemas/Metadata'
          nullable: true
    RoutingMethod:
      title: RoutingMethod
      type: string
      enum:
        - all
        - single
    Timeouts:
      title: Timeouts
      type: object
      properties:
        provider:
          type: integer
          nullable: true
        channel:
          type: integer
          nullable: true
    ChannelMetadata:
      title: ChannelMetadata
      type: object
      properties:
        utm:
          $ref: '#/components/schemas/UTM'
          nullable: true
    Metadata:
      title: Metadata
      type: object
      properties:
        utm:
          $ref: '#/components/schemas/UTM'
          nullable: true
    UTM:
      title: UTM
      type: object
      properties:
        source:
          type: string
          nullable: true
        medium:
          type: string
          nullable: true
        campaign:
          type: string
          nullable: true
        term:
          type: string
          nullable: true
        content:
          type: string
          nullable: true
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer

````