Skip to main content
PUT
/
preferences
/
sections
/
{section_id}
/
topics
/
{topic_id}
JavaScript
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);
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)
package main

import (
"context"
"fmt"

"github.com/trycourier/courier-go"
"github.com/trycourier/courier-go/option"
)

func main() {
client := courier.NewClient(
option.WithAPIKey("My API Key"),
)
workspacePreferenceTopicGetResponse, err := client.WorkspacePreferences.Topics.Replace(
context.TODO(),
"topic_id",
courier.WorkspacePreferenceTopicReplaceParams{
SectionID: "section_id",
WorkspacePreferenceTopicReplaceRequest: courier.WorkspacePreferenceTopicReplaceRequestParam{
DefaultStatus: courier.WorkspacePreferenceTopicReplaceRequestDefaultStatusOptedOut,
Name: "name",
},
},
)
if err != nil {
panic(err.Error())
}
fmt.Printf("%+v\n", workspacePreferenceTopicGetResponse.ID)
}
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);
}
}
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)
<?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();
}
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);
courier workspace-preferences:topics replace \
--api-key 'My API Key' \
--section-id section_id \
--topic-id topic_id \
--default-status OPTED_OUT \
--name name
curl --request PUT \
--url https://api.courier.com/preferences/sections/{section_id}/topics/{topic_id} \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"name": "<string>",
"description": "<string>",
"routing_options": [],
"allowed_preferences": [],
"include_unsubscribe_header": true,
"topic_data": {}
}
'
{
  "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"
}
{
"message": "Example message text",
"type": "invalid_request_error"
}
{
"message": "Example message text",
"type": "invalid_request_error"
}

Authorizations

Authorization
string
header
required

Bearer authentication header of the form Bearer <token>, where <token> is your auth token.

Path Parameters

section_id
string
required

Id of the workspace preference.

topic_id
string
required

Id of the subscription preference topic.

Body

application/json

Request body for replacing a preference topic. Full document replacement; missing optional fields are cleared.

name
string
required

Human-readable name for the preference topic.

default_status
enum<string>
required

The default subscription status applied when a recipient has not set their own.

Available options:
OPTED_OUT,
OPTED_IN,
REQUIRED
description
string | null

Optional description shown under the topic on the hosted preferences page. Omit to clear.

routing_options
enum<string>[] | null

Default channels delivered for this topic. Omit to clear.

Available options:
direct_message,
email,
push,
sms,
webhook,
inbox
allowed_preferences
enum<string>[] | null

Preference controls a recipient may customize. Omit to clear.

A preference control a recipient may customize for a topic.

Available options:
snooze,
channel_preferences
include_unsubscribe_header
boolean | null

Whether to include a list-unsubscribe header on emails for this topic.

topic_data
object | null

Arbitrary metadata associated with the topic. Omit to clear.

Response

A subscription preference topic in your workspace.

id
string
required

The preference topic id.

name
string
required

Human-readable name.

default_status
enum<string>
required

The default subscription status applied when a recipient has not set their own.

Available options:
OPTED_OUT,
OPTED_IN,
REQUIRED
routing_options
enum<string>[]
required

Default channels delivered for this topic. May be empty.

Available options:
direct_message,
email,
push,
sms,
webhook,
inbox
allowed_preferences
enum<string>[]
required

Preference controls a recipient may customize. May be empty.

A preference control a recipient may customize for a topic.

Available options:
snooze,
channel_preferences
include_unsubscribe_header
boolean
required

Whether a list-unsubscribe header is included on emails for this topic.

topic_data
object
required

Arbitrary metadata associated with the topic.

created
string
required

ISO-8601 timestamp of when the topic was created.

updated
string
required

ISO-8601 timestamp of the last update.

description
string | null

Optional description shown under the topic on the hosted preferences page.

creator
string | null

Id of the creator.

updater
string | null

Id of the last updater.