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.profiles.lists.subscribe('user_id', {
lists: [{ listId: 'listId' }],
});
console.log(response.status);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.profiles.lists.subscribe(
user_id="user_id",
lists=[{
"list_id": "listId"
}],
)
print(response.status)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"),
)
response, err := client.Profiles.Lists.Subscribe(
context.TODO(),
"user_id",
courier.ProfileListSubscribeParams{
Lists: []courier.SubscribeToListsRequestItemParam{{
ListID: "listId",
}},
},
)
if err != nil {
panic(err.Error())
}
fmt.Printf("%+v\n", response.Status)
}
package com.courier.example;
import com.courier.client.CourierClient;
import com.courier.client.okhttp.CourierOkHttpClient;
import com.courier.models.profiles.SubscribeToListsRequestItem;
import com.courier.models.profiles.lists.ListSubscribeParams;
import com.courier.models.profiles.lists.ListSubscribeResponse;
public final class Main {
private Main() {}
public static void main(String[] args) {
CourierClient client = CourierOkHttpClient.fromEnv();
ListSubscribeParams params = ListSubscribeParams.builder()
.userId("user_id")
.addList(SubscribeToListsRequestItem.builder()
.listId("listId")
.build())
.build();
ListSubscribeResponse response = client.profiles().lists().subscribe(params);
}
}require "courier"
courier = Courier::Client.new(api_key: "My API Key")
response = courier.profiles.lists.subscribe("user_id", lists: [{listId: "listId"}])
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->profiles->lists->subscribe(
'user_id',
lists: [
[
'listID' => 'listId',
'preferences' => [
'categories' => [
'foo' => [
'status' => PreferenceStatus::OPTED_IN,
'channelPreferences' => [
['channel' => ChannelClassification::DIRECT_MESSAGE]
],
'rules' => [['until' => 'until', 'start' => 'start']],
],
],
'notifications' => [
'foo' => [
'status' => PreferenceStatus::OPTED_IN,
'channelPreferences' => [
['channel' => ChannelClassification::DIRECT_MESSAGE]
],
'rules' => [['until' => 'until', 'start' => 'start']],
],
],
],
],
],
idempotencyKey: 'order-ORD-456-user-123',
xIdempotencyExpiration: '1785312000',
);
var_dump($response);
} catch (APIException $e) {
echo $e->getMessage();
}using System;
using System.Collections.Generic;
using TryCourier;
using TryCourier.Models;
using TryCourier.Models.Profiles.Lists;
CourierClient client = new();
ListSubscribeParams parameters = new()
{
UserID = "user_id",
Lists =
[
new()
{
ListID = "listId",
Preferences = new()
{
Categories = new Dictionary<string, NotificationPreferenceDetails>(
)
{
{ "foo", new()
{
Status = PreferenceStatus.OptedIn,
ChannelPreferences =
[
new(ChannelClassification.DirectMessage)
],
Rules =
[
new()
{
Until = "until",
Start = "start",
},
],
} },
},
Notifications = new Dictionary<string, NotificationPreferenceDetails>(
)
{
{ "foo", new()
{
Status = PreferenceStatus.OptedIn,
ChannelPreferences =
[
new(ChannelClassification.DirectMessage)
],
Rules =
[
new()
{
Until = "until",
Start = "start",
},
],
} },
},
},
},
],
};
var response = await client.Profiles.Lists.Subscribe(parameters);
Console.WriteLine(response);courier profiles:lists subscribe \
--api-key 'My API Key' \
--user-id user_id \
--list '{listId: listId}'curl --request POST \
--url https://api.courier.com/profiles/{user_id}/lists \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"lists": [
{
"listId": "<string>",
"preferences": {
"categories": {},
"notifications": {}
}
}
]
}
'{
"status": "SUCCESS"
}{
"message": "Example message text",
"type": "invalid_request_error"
}Subscribe to one or more lists
Subscribes a user to one or more lists, creating any list that does not yet exist. Optional preferences apply to each subscription.
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.profiles.lists.subscribe('user_id', {
lists: [{ listId: 'listId' }],
});
console.log(response.status);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.profiles.lists.subscribe(
user_id="user_id",
lists=[{
"list_id": "listId"
}],
)
print(response.status)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"),
)
response, err := client.Profiles.Lists.Subscribe(
context.TODO(),
"user_id",
courier.ProfileListSubscribeParams{
Lists: []courier.SubscribeToListsRequestItemParam{{
ListID: "listId",
}},
},
)
if err != nil {
panic(err.Error())
}
fmt.Printf("%+v\n", response.Status)
}
package com.courier.example;
import com.courier.client.CourierClient;
import com.courier.client.okhttp.CourierOkHttpClient;
import com.courier.models.profiles.SubscribeToListsRequestItem;
import com.courier.models.profiles.lists.ListSubscribeParams;
import com.courier.models.profiles.lists.ListSubscribeResponse;
public final class Main {
private Main() {}
public static void main(String[] args) {
CourierClient client = CourierOkHttpClient.fromEnv();
ListSubscribeParams params = ListSubscribeParams.builder()
.userId("user_id")
.addList(SubscribeToListsRequestItem.builder()
.listId("listId")
.build())
.build();
ListSubscribeResponse response = client.profiles().lists().subscribe(params);
}
}require "courier"
courier = Courier::Client.new(api_key: "My API Key")
response = courier.profiles.lists.subscribe("user_id", lists: [{listId: "listId"}])
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->profiles->lists->subscribe(
'user_id',
lists: [
[
'listID' => 'listId',
'preferences' => [
'categories' => [
'foo' => [
'status' => PreferenceStatus::OPTED_IN,
'channelPreferences' => [
['channel' => ChannelClassification::DIRECT_MESSAGE]
],
'rules' => [['until' => 'until', 'start' => 'start']],
],
],
'notifications' => [
'foo' => [
'status' => PreferenceStatus::OPTED_IN,
'channelPreferences' => [
['channel' => ChannelClassification::DIRECT_MESSAGE]
],
'rules' => [['until' => 'until', 'start' => 'start']],
],
],
],
],
],
idempotencyKey: 'order-ORD-456-user-123',
xIdempotencyExpiration: '1785312000',
);
var_dump($response);
} catch (APIException $e) {
echo $e->getMessage();
}using System;
using System.Collections.Generic;
using TryCourier;
using TryCourier.Models;
using TryCourier.Models.Profiles.Lists;
CourierClient client = new();
ListSubscribeParams parameters = new()
{
UserID = "user_id",
Lists =
[
new()
{
ListID = "listId",
Preferences = new()
{
Categories = new Dictionary<string, NotificationPreferenceDetails>(
)
{
{ "foo", new()
{
Status = PreferenceStatus.OptedIn,
ChannelPreferences =
[
new(ChannelClassification.DirectMessage)
],
Rules =
[
new()
{
Until = "until",
Start = "start",
},
],
} },
},
Notifications = new Dictionary<string, NotificationPreferenceDetails>(
)
{
{ "foo", new()
{
Status = PreferenceStatus.OptedIn,
ChannelPreferences =
[
new(ChannelClassification.DirectMessage)
],
Rules =
[
new()
{
Until = "until",
Start = "start",
},
],
} },
},
},
},
],
};
var response = await client.Profiles.Lists.Subscribe(parameters);
Console.WriteLine(response);courier profiles:lists subscribe \
--api-key 'My API Key' \
--user-id user_id \
--list '{listId: listId}'curl --request POST \
--url https://api.courier.com/profiles/{user_id}/lists \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"lists": [
{
"listId": "<string>",
"preferences": {
"categories": {},
"notifications": {}
}
}
]
}
'{
"status": "SUCCESS"
}{
"message": "Example message text",
"type": "invalid_request_error"
}Authorizations
Bearer authentication header of the form Bearer <token>, where <token> is your auth token.
Headers
A unique key that makes this request idempotent. If Courier receives another request with the same Idempotency-Key, it returns the stored response from the first request without performing the operation again (including the original status code and any error). Use it to safely retry POST requests after network failures without risking duplicate sends. The key is scoped to this endpoint.
How long the idempotency key remains valid, as a Unix epoch timestamp in seconds or an ISO 8601 date string. Only applies when Idempotency-Key is provided. If omitted, the key is retained for 25 hours; the maximum is 1 year.
Path Parameters
A unique identifier representing the user associated with the requested user profile.
Body
Show child attributes
Show child attributes
Response
SUCCESS