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 response = await client.users.preferences.updateOrCreateTopic('topic_id', {
user_id: 'user_id',
topic: {
status: 'OPTED_IN',
has_custom_routing: true,
custom_routing: ['inbox', 'email'],
},
});
console.log(response.message);import os
from courier import Courier
client = Courier(
api_key=os.environ.get("COURIER_API_KEY"), # This is the default and can be omitted
)
response = client.users.preferences.update_or_create_topic(
topic_id="topic_id",
user_id="user_id",
topic={
"status": "OPTED_IN",
"has_custom_routing": True,
"custom_routing": ["inbox", "email"],
},
)
print(response.message)package main
import (
"context"
"fmt"
"github.com/trycourier/courier-go"
"github.com/trycourier/courier-go/option"
"github.com/trycourier/courier-go/shared"
)
func main() {
client := courier.NewClient(
option.WithAPIKey("My API Key"),
)
response, err := client.Users.Preferences.UpdateOrNewTopic(
context.TODO(),
"topic_id",
courier.UserPreferenceUpdateOrNewTopicParams{
UserID: "user_id",
Topic: courier.UserPreferenceUpdateOrNewTopicParamsTopic{
Status: shared.PreferenceStatusOptedIn,
HasCustomRouting: courier.Bool(true),
CustomRouting: []shared.ChannelClassification{shared.ChannelClassificationInbox, shared.ChannelClassificationEmail},
},
},
)
if err != nil {
panic(err.Error())
}
fmt.Printf("%+v\n", response.Message)
}
package com.courier.example;
import com.courier.client.CourierClient;
import com.courier.client.okhttp.CourierOkHttpClient;
import com.courier.models.PreferenceStatus;
import com.courier.models.users.preferences.PreferenceUpdateOrCreateTopicParams;
import com.courier.models.users.preferences.PreferenceUpdateOrCreateTopicResponse;
public final class Main {
private Main() {}
public static void main(String[] args) {
CourierClient client = CourierOkHttpClient.fromEnv();
PreferenceUpdateOrCreateTopicParams params = PreferenceUpdateOrCreateTopicParams.builder()
.userId("user_id")
.topicId("topic_id")
.topic(PreferenceUpdateOrCreateTopicParams.Topic.builder()
.status(PreferenceStatus.OPTED_IN)
.build())
.build();
PreferenceUpdateOrCreateTopicResponse response = client.users().preferences().updateOrCreateTopic(params);
}
}require "courier"
courier = Courier::Client.new(api_key: "My API Key")
response = courier.users.preferences.update_or_create_topic(
"topic_id",
user_id: "user_id",
topic: {status: :OPTED_IN}
)
puts(response)<?php
require_once dirname(__DIR__) . '/vendor/autoload.php';
use Courier\Client;
use Courier\PreferenceStatus;
use Courier\ChannelClassification;
use Courier\Core\Exceptions\APIException;
$client = new Client(apiKey: getenv('COURIER_API_KEY') ?: 'My API Key');
try {
$response = $client->users->preferences->updateOrCreateTopic(
'topic_id',
userID: 'user_id',
topic: [
'status' => PreferenceStatus::OPTED_IN,
'customRouting' => [
ChannelClassification::INBOX, ChannelClassification::EMAIL
],
'hasCustomRouting' => true,
],
tenantID: 'tenant_id',
);
var_dump($response);
} catch (APIException $e) {
echo $e->getMessage();
}using System;
using TryCourier;
using TryCourier.Models;
using TryCourier.Models.Users.Preferences;
CourierClient client = new();
PreferenceUpdateOrCreateTopicParams parameters = new()
{
UserID = "user_id",
TopicID = "topic_id",
Topic = new()
{
Status = PreferenceStatus.OptedIn,
CustomRouting =
[
ChannelClassification.Inbox, ChannelClassification.Email
],
HasCustomRouting = true,
},
};
var response = await client.Users.Preferences.UpdateOrCreateTopic(parameters);
Console.WriteLine(response);courier users:preferences update-or-create-topic \
--api-key 'My API Key' \
--user-id user_id \
--topic-id topic_id \
--topic '{status: OPTED_IN}'curl --request PUT \
--url https://api.courier.com/users/{user_id}/preferences/{topic_id} \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"topic": {
"status": "OPTED_IN",
"has_custom_routing": true,
"custom_routing": [
"inbox",
"email"
]
}
}
'{
"message": "success"
}{
"message": "Example message text",
"type": "invalid_request_error"
}User Preferences
Update or Create user preferences for a specific subscription topic
Update or Create user preferences for a specific subscription topic.
PUT
/
users
/
{user_id}
/
preferences
/
{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 response = await client.users.preferences.updateOrCreateTopic('topic_id', {
user_id: 'user_id',
topic: {
status: 'OPTED_IN',
has_custom_routing: true,
custom_routing: ['inbox', 'email'],
},
});
console.log(response.message);import os
from courier import Courier
client = Courier(
api_key=os.environ.get("COURIER_API_KEY"), # This is the default and can be omitted
)
response = client.users.preferences.update_or_create_topic(
topic_id="topic_id",
user_id="user_id",
topic={
"status": "OPTED_IN",
"has_custom_routing": True,
"custom_routing": ["inbox", "email"],
},
)
print(response.message)package main
import (
"context"
"fmt"
"github.com/trycourier/courier-go"
"github.com/trycourier/courier-go/option"
"github.com/trycourier/courier-go/shared"
)
func main() {
client := courier.NewClient(
option.WithAPIKey("My API Key"),
)
response, err := client.Users.Preferences.UpdateOrNewTopic(
context.TODO(),
"topic_id",
courier.UserPreferenceUpdateOrNewTopicParams{
UserID: "user_id",
Topic: courier.UserPreferenceUpdateOrNewTopicParamsTopic{
Status: shared.PreferenceStatusOptedIn,
HasCustomRouting: courier.Bool(true),
CustomRouting: []shared.ChannelClassification{shared.ChannelClassificationInbox, shared.ChannelClassificationEmail},
},
},
)
if err != nil {
panic(err.Error())
}
fmt.Printf("%+v\n", response.Message)
}
package com.courier.example;
import com.courier.client.CourierClient;
import com.courier.client.okhttp.CourierOkHttpClient;
import com.courier.models.PreferenceStatus;
import com.courier.models.users.preferences.PreferenceUpdateOrCreateTopicParams;
import com.courier.models.users.preferences.PreferenceUpdateOrCreateTopicResponse;
public final class Main {
private Main() {}
public static void main(String[] args) {
CourierClient client = CourierOkHttpClient.fromEnv();
PreferenceUpdateOrCreateTopicParams params = PreferenceUpdateOrCreateTopicParams.builder()
.userId("user_id")
.topicId("topic_id")
.topic(PreferenceUpdateOrCreateTopicParams.Topic.builder()
.status(PreferenceStatus.OPTED_IN)
.build())
.build();
PreferenceUpdateOrCreateTopicResponse response = client.users().preferences().updateOrCreateTopic(params);
}
}require "courier"
courier = Courier::Client.new(api_key: "My API Key")
response = courier.users.preferences.update_or_create_topic(
"topic_id",
user_id: "user_id",
topic: {status: :OPTED_IN}
)
puts(response)<?php
require_once dirname(__DIR__) . '/vendor/autoload.php';
use Courier\Client;
use Courier\PreferenceStatus;
use Courier\ChannelClassification;
use Courier\Core\Exceptions\APIException;
$client = new Client(apiKey: getenv('COURIER_API_KEY') ?: 'My API Key');
try {
$response = $client->users->preferences->updateOrCreateTopic(
'topic_id',
userID: 'user_id',
topic: [
'status' => PreferenceStatus::OPTED_IN,
'customRouting' => [
ChannelClassification::INBOX, ChannelClassification::EMAIL
],
'hasCustomRouting' => true,
],
tenantID: 'tenant_id',
);
var_dump($response);
} catch (APIException $e) {
echo $e->getMessage();
}using System;
using TryCourier;
using TryCourier.Models;
using TryCourier.Models.Users.Preferences;
CourierClient client = new();
PreferenceUpdateOrCreateTopicParams parameters = new()
{
UserID = "user_id",
TopicID = "topic_id",
Topic = new()
{
Status = PreferenceStatus.OptedIn,
CustomRouting =
[
ChannelClassification.Inbox, ChannelClassification.Email
],
HasCustomRouting = true,
},
};
var response = await client.Users.Preferences.UpdateOrCreateTopic(parameters);
Console.WriteLine(response);courier users:preferences update-or-create-topic \
--api-key 'My API Key' \
--user-id user_id \
--topic-id topic_id \
--topic '{status: OPTED_IN}'curl --request PUT \
--url https://api.courier.com/users/{user_id}/preferences/{topic_id} \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"topic": {
"status": "OPTED_IN",
"has_custom_routing": true,
"custom_routing": [
"inbox",
"email"
]
}
}
'{
"message": "success"
}{
"message": "Example message text",
"type": "invalid_request_error"
}Authorizations
Bearer authentication header of the form Bearer <token>, where <token> is your auth token.
Path Parameters
A unique identifier associated with the user whose preferences you wish to retrieve.
A unique identifier associated with a subscription topic.
Query Parameters
Update the preferences of a user for this specific tenant context.
Body
application/json
Show child attributes
Show child attributes
Response
Example:
"success"
⌘I