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

> Replace a routing strategy. Full document replacement; the caller must send the complete desired state. Missing optional fields are cleared.



## OpenAPI

````yaml /openapi-specs/openapi.documented.yml put /routing-strategies/{id}
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/{id}:
    put:
      tags:
        - Routing Strategies
      summary: Replace Routing Strategy
      description: >-
        Replace a routing strategy. Full document replacement; the caller must
        send the complete desired state. Missing optional fields are cleared.
      operationId: routingStrategies_replace
      parameters:
        - name: id
          in: path
          description: Routing strategy ID (rs_ prefix).
          required: true
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/RoutingStrategyReplaceRequest'
            examples:
              FullReplace:
                summary: Replace all fields
                value:
                  name: Email via SendGrid v2
                  description: Updated routing with SES primary
                  tags:
                    - production
                    - email
                    - v2
                  routing:
                    method: single
                    channels:
                      - email
                  channels:
                    email:
                      providers:
                        - ses
                        - sendgrid
                  providers:
                    ses:
                      override: {}
      responses:
        '200':
          description: ''
          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'
        '404':
          description: Not Found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/NotFound'
              examples:
                StrategyNotFound:
                  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 routingStrategyGetResponse = await
            client.routingStrategies.replace('id', {
              name: 'Email via SendGrid v2',
              routing: { method: 'single', channels: ['email'] },
              channels: { email: { providers: ['ses', 'sendgrid'] } },
              description: 'Updated routing with SES primary',
              providers: { ses: { override: {} } },
              tags: ['production', 'email', 'v2'],
            });


            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.replace(
                id="id",
                name="Email via SendGrid v2",
                routing={
                    "method": "single",
                    "channels": ["email"],
                },
                channels={
                    "email": {
                        "providers": ["ses", "sendgrid"]
                    }
                },
                description="Updated routing with SES primary",
                providers={
                    "ses": {
                        "override": {}
                    }
                },
                tags=["production", "email", "v2"],
            )
            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.Replace(\n\t\tcontext.TODO(),\n\t\t\"id\",\n\t\tcourier.RoutingStrategyReplaceParams{\n\t\t\tRoutingStrategyReplaceRequest: courier.RoutingStrategyReplaceRequestParam{\n\t\t\t\tName: \"Email via SendGrid v2\",\n\t\t\t\tRouting: shared.MessageRoutingParam{\n\t\t\t\t\tChannels: []shared.MessageRoutingChannelUnionParam{{\n\t\t\t\t\t\tOfString: courier.String(\"email\"),\n\t\t\t\t\t}},\n\t\t\t\t\tMethod: shared.MessageRoutingMethodSingle,\n\t\t\t\t},\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.RoutingStrategyGetResponse;

            import
            com.courier.models.routingstrategies.RoutingStrategyReplaceParams;

            import
            com.courier.models.routingstrategies.RoutingStrategyReplaceRequest;


            public final class Main {
                private Main() {}

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

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

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

            routing_strategy_get_response = courier.routing_strategies.replace(
              "id",
              name: "Email via SendGrid v2",
              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->replace(
                'id',
                name: 'Email via SendGrid v2',
                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' => ['ses', 'sendgrid'],
                    'routingMethod' => 'all',
                    'timeouts' => ['channel' => 0, 'provider' => 0],
                  ],
                ],
                description: 'Updated routing with SES primary',
                providers: [
                  'ses' => [
                    'if' => 'if',
                    'metadata' => [
                      'utm' => [
                        'campaign' => 'campaign',
                        'content' => 'content',
                        'medium' => 'medium',
                        'source' => 'source',
                        'term' => 'term',
                      ],
                    ],
                    'override' => [],
                    'timeouts' => 0,
                  ],
                ],
                tags: ['production', 'email', 'v2'],
              );

              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();


            RoutingStrategyReplaceParams parameters = new()

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


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


            Console.WriteLine(routingStrategyGetResponse);
        - lang: CLI
          source: |-
            courier routing-strategies replace \
              --api-key 'My API Key' \
              --id id \
              --name 'Email via SendGrid v2' \
              --routing '{channels: [email], method: single}'
components:
  schemas:
    RoutingStrategyReplaceRequest:
      title: RoutingStrategyReplaceRequest
      type: object
      description: >-
        Request body for replacing a routing strategy. Full document
        replacement; missing optional fields are cleared.
      properties:
        name:
          type: string
          description: Human-readable name for the routing strategy.
        description:
          type: string
          nullable: true
          description: Optional description. Omit or null to clear.
        tags:
          type: array
          items:
            type: string
          nullable: true
          description: Optional tags. Omit or null to clear.
        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. Omit to clear.
        providers:
          $ref: '#/components/schemas/MessageProviders'
          nullable: true
          description: Per-provider delivery configuration. Omit to clear.
      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'
    NotFound:
      title: NotFound
      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

````