User Preferences
Replace user Preferences in bulk
Replaces a user’s entire set of preference overrides. Any topic you leave out is reset to its default, so send the full set rather than a subset.
PUT
/
users
/
{user_id}
/
preferences
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.bulkReplace('user_id', {
topics: [
{
topic_id: 'pt_01kx4h2jdafq8bk996nn92357r',
status: 'OPTED_IN',
has_custom_routing: true,
custom_routing: ['inbox', 'email'],
},
],
});
console.log(response.deleted);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.bulk_replace(
user_id="user_id",
topics=[{
"topic_id": "pt_01kx4h2jdafq8bk996nn92357r",
"status": "OPTED_IN",
"has_custom_routing": True,
"custom_routing": ["inbox", "email"],
}],
)
print(response.deleted)package main
import (
"context"
"fmt"
"github.com/trycourier/courier-go/v4"
"github.com/trycourier/courier-go/v4/option"
"github.com/trycourier/courier-go/v4/shared"
)
func main() {
client := courier.NewClient(
option.WithAPIKey("My API Key"),
)
response, err := client.Users.Preferences.BulkReplace(
context.TODO(),
"user_id",
courier.UserPreferenceBulkReplaceParams{
Topics: []courier.UserPreferenceBulkReplaceParamsTopic{{
TopicID: "pt_01kx4h2jdafq8bk996nn92357r",
Status: "OPTED_IN",
HasCustomRouting: courier.Bool(true),
CustomRouting: []shared.ChannelClassification{shared.ChannelClassificationInbox, shared.ChannelClassificationEmail},
}},
},
)
if err != nil {
panic(err.Error())
}
fmt.Printf("%+v\n", response.Deleted)
}
package com.courier.example;
import com.courier.client.CourierClient;
import com.courier.client.okhttp.CourierOkHttpClient;
import com.courier.models.users.preferences.PreferenceBulkReplaceParams;
import com.courier.models.users.preferences.PreferenceBulkReplaceResponse;
public final class Main {
private Main() {}
public static void main(String[] args) {
CourierClient client = CourierOkHttpClient.fromEnv();
PreferenceBulkReplaceParams params = PreferenceBulkReplaceParams.builder()
.userId("user_id")
.addTopic(PreferenceBulkReplaceParams.Topic.builder()
.status(PreferenceBulkReplaceParams.Topic.Status.OPTED_IN)
.topicId("pt_01kx4h2jdafq8bk996nn92357r")
.build())
.build();
PreferenceBulkReplaceResponse response = client.users().preferences().bulkReplace(params);
}
}require "courier"
courier = Courier::Client.new(api_key: "My API Key")
response = courier.users.preferences.bulk_replace(
"user_id",
topics: [{status: :OPTED_IN, topic_id: "pt_01kx4h2jdafq8bk996nn92357r"}]
)
puts(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 {
$response = $client->users->preferences->bulkReplace(
'user_id',
topics: [
[
'status' => 'OPTED_IN',
'topicID' => 'pt_01kx4h2jdafq8bk996nn92357r',
'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();
PreferenceBulkReplaceParams parameters = new()
{
UserID = "user_id",
Topics =
[
new()
{
Status = Status.OptedIn,
TopicID = "pt_01kx4h2jdafq8bk996nn92357r",
CustomRouting =
[
ChannelClassification.Inbox, ChannelClassification.Email
],
HasCustomRouting = true,
},
],
};
var response = await client.Users.Preferences.BulkReplace(parameters);
Console.WriteLine(response);courier users:preferences bulk-replace \
--api-key 'My API Key' \
--user-id user_id \
--topic '{status: OPTED_IN, topic_id: pt_01kx4h2jdafq8bk996nn92357r}'curl --request PUT \
--url https://api.courier.com/users/{user_id}/preferences \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"topics": [
{
"topic_id": "pt_01kx4h2jdafq8bk996nn92357r",
"status": "OPTED_IN",
"has_custom_routing": true,
"custom_routing": [
"inbox",
"email"
]
}
]
}
'{
"items": [
{
"topic_id": "pt_01kx4h2jdafq8bk996nn92357r",
"status": "OPTED_IN",
"has_custom_routing": true,
"custom_routing": [
"inbox",
"email"
]
}
],
"deleted": [
"pt_01kx4h2jdafq8bk99eyt3dx43x"
]
}Authorizations
Path Parameters
Query Parameters
Body
application/json
Response
The replacement was applied. items contains the complete resulting set of topic overrides for the user, and deleted lists the ids of the overrides that were reset to their topic default.
⌘I
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.bulkReplace('user_id', {
topics: [
{
topic_id: 'pt_01kx4h2jdafq8bk996nn92357r',
status: 'OPTED_IN',
has_custom_routing: true,
custom_routing: ['inbox', 'email'],
},
],
});
console.log(response.deleted);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.bulk_replace(
user_id="user_id",
topics=[{
"topic_id": "pt_01kx4h2jdafq8bk996nn92357r",
"status": "OPTED_IN",
"has_custom_routing": True,
"custom_routing": ["inbox", "email"],
}],
)
print(response.deleted)package main
import (
"context"
"fmt"
"github.com/trycourier/courier-go/v4"
"github.com/trycourier/courier-go/v4/option"
"github.com/trycourier/courier-go/v4/shared"
)
func main() {
client := courier.NewClient(
option.WithAPIKey("My API Key"),
)
response, err := client.Users.Preferences.BulkReplace(
context.TODO(),
"user_id",
courier.UserPreferenceBulkReplaceParams{
Topics: []courier.UserPreferenceBulkReplaceParamsTopic{{
TopicID: "pt_01kx4h2jdafq8bk996nn92357r",
Status: "OPTED_IN",
HasCustomRouting: courier.Bool(true),
CustomRouting: []shared.ChannelClassification{shared.ChannelClassificationInbox, shared.ChannelClassificationEmail},
}},
},
)
if err != nil {
panic(err.Error())
}
fmt.Printf("%+v\n", response.Deleted)
}
package com.courier.example;
import com.courier.client.CourierClient;
import com.courier.client.okhttp.CourierOkHttpClient;
import com.courier.models.users.preferences.PreferenceBulkReplaceParams;
import com.courier.models.users.preferences.PreferenceBulkReplaceResponse;
public final class Main {
private Main() {}
public static void main(String[] args) {
CourierClient client = CourierOkHttpClient.fromEnv();
PreferenceBulkReplaceParams params = PreferenceBulkReplaceParams.builder()
.userId("user_id")
.addTopic(PreferenceBulkReplaceParams.Topic.builder()
.status(PreferenceBulkReplaceParams.Topic.Status.OPTED_IN)
.topicId("pt_01kx4h2jdafq8bk996nn92357r")
.build())
.build();
PreferenceBulkReplaceResponse response = client.users().preferences().bulkReplace(params);
}
}require "courier"
courier = Courier::Client.new(api_key: "My API Key")
response = courier.users.preferences.bulk_replace(
"user_id",
topics: [{status: :OPTED_IN, topic_id: "pt_01kx4h2jdafq8bk996nn92357r"}]
)
puts(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 {
$response = $client->users->preferences->bulkReplace(
'user_id',
topics: [
[
'status' => 'OPTED_IN',
'topicID' => 'pt_01kx4h2jdafq8bk996nn92357r',
'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();
PreferenceBulkReplaceParams parameters = new()
{
UserID = "user_id",
Topics =
[
new()
{
Status = Status.OptedIn,
TopicID = "pt_01kx4h2jdafq8bk996nn92357r",
CustomRouting =
[
ChannelClassification.Inbox, ChannelClassification.Email
],
HasCustomRouting = true,
},
],
};
var response = await client.Users.Preferences.BulkReplace(parameters);
Console.WriteLine(response);courier users:preferences bulk-replace \
--api-key 'My API Key' \
--user-id user_id \
--topic '{status: OPTED_IN, topic_id: pt_01kx4h2jdafq8bk996nn92357r}'curl --request PUT \
--url https://api.courier.com/users/{user_id}/preferences \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"topics": [
{
"topic_id": "pt_01kx4h2jdafq8bk996nn92357r",
"status": "OPTED_IN",
"has_custom_routing": true,
"custom_routing": [
"inbox",
"email"
]
}
]
}
'{
"items": [
{
"topic_id": "pt_01kx4h2jdafq8bk996nn92357r",
"status": "OPTED_IN",
"has_custom_routing": true,
"custom_routing": [
"inbox",
"email"
]
}
],
"deleted": [
"pt_01kx4h2jdafq8bk99eyt3dx43x"
]
}