Skip to main content
POST
/
preferences
/
sections
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 workspacePreferenceGetResponse = await client.workspacePreferences.create({
  name: 'Account Notifications',
});

console.log(workspacePreferenceGetResponse.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_get_response = client.workspace_preferences.create(
name="Account Notifications",
)
print(workspace_preference_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"),
)
workspacePreferenceGetResponse, err := client.WorkspacePreferences.New(context.TODO(), courier.WorkspacePreferenceNewParams{
WorkspacePreferenceCreateRequest: courier.WorkspacePreferenceCreateRequestParam{
Name: "Account Notifications",
},
})
if err != nil {
panic(err.Error())
}
fmt.Printf("%+v\n", workspacePreferenceGetResponse.ID)
}
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);
}
}
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)
<?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();
}
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);
courier workspace-preferences create \
--api-key 'My API Key' \
--name 'Account Notifications'
curl --request POST \
--url https://api.courier.com/preferences/sections \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"name": "Account Notifications"
}
'
{
  "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"
    }
  ]
}
{
"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.

Body

application/json

Request body for creating a workspace preference.

name
string
required

Human-readable name for the workspace preference.

description
string | null

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

routing_options
enum<string>[] | null

Default channels for the workspace preference. Defaults to empty if omitted.

Available options:
direct_message,
email,
push,
sms,
webhook,
inbox
has_custom_routing
boolean | null

Whether the workspace preference defines custom routing for its topics.

Response

Created

A workspace preference in your workspace, including its topics.

id
string
required

The workspace preference id.

name
string
required

Human-readable name.

routing_options
enum<string>[]
required

Default channels for the workspace preference. May be empty.

Available options:
direct_message,
email,
push,
sms,
webhook,
inbox
has_custom_routing
boolean
required

Whether the workspace preference defines custom routing for its topics.

created
string
required

ISO-8601 timestamp of when the workspace preference was created.

topics
WorkspacePreferenceTopicGetResponse · object[]
required

The topics contained in this workspace preference.

description
string | null

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

creator
string | null

Id of the creator.

updated
string | null

ISO-8601 timestamp of the last update.

updater
string | null

Id of the last updater.