Subscribe users to a list
Subscribes the users to the list, overwriting existing subscriptions. If the list does not exist, it will be automatically created.
URL: https://api.courier.com/lists/:list_id/subscriptions
Method: PUT
Path Parameters
list_idstringrequired
A unique identifier associated with the list you wish to retrieve.
Body Parameters
recipientsarray
An array of list subscriptions
+ Show Properties
Responses
status: 204 Successfully subscribed
status: 400 Bad Request
messagestring
A message describing the error that occurred.
typestring
[invalid_request_error] The type of error that occurred.
Request Example
- cURL
- Node.js
- Ruby
- Python
- Go
- PHP
curl --request PUT \
--url https://api.courier.com/lists/example.list.id/subscriptions \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--data '
{
"recipients": [
{
"recipientId": "0460766e-8463-4905-ae98-b72c7aef41d6"
}
]
}
'
// Dependencies to install:
// $ npm install node-fetch --save
const fetch = require('node-fetch');
const options = {
method: 'PUT',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({
"recipients": [
{
"recipientId": "0460766e-8463-4905-ae98-b72c7aef41d6"
}
]
})
};
fetch('https://api.courier.com/lists/example.list.id/subscriptions', options)
.then(response => response.json())
.then(response => console.log(response))
.catch(err => console.error(err));
require 'uri'
require 'net/http'
require 'openssl'
url = URI("https://api.courier.com/lists/example.list.id/subscriptions")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Put.new(url)
request["Accept"] = 'application/json'
request["Content-Type"] = 'application/json'
request.body = "{\"recipients\":[{\"recipientId\":\"0460766e-8463-4905-ae98-b72c7aef41d6\"}]}"
response = http.request(request)
puts response.read_body
# Dependencies to install:
# $ python -m pip install requests
import requests
url = "https://api.courier.com/lists/example.list.id/subscriptions"
payload = {
"recipients": [
{
"recipientId": "0460766e-8463-4905-ae98-b72c7aef41d6"
}
]
}
headers = {
"Accept": "application/json",
"Content-Type": "application/json"
}
response = requests.request("PUT", url, json=payload, headers=headers)
print(response.text)
package main
import (
"fmt"
"strings"
"net/http"
"io/ioutil"
)
func main() {
url := "https://api.courier.com/lists/example.list.id/subscriptions"
payload := strings.NewReader("{\"recipients\":[{\"recipientId\":\"0460766e-8463-4905-ae98-b72c7aef41d6\"}]}")
req, _ := http.NewRequest("PUT", url, payload)
req.Header.Add("Accept", "application/json")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := ioutil.ReadAll(res.Body)
fmt.Println(res)
fmt.Println(string(body))
}
<?php
// Dependencies to install:
// $ composer require guzzlehttp/guzzle
require_once('vendor/autoload.php');
$client = new \GuzzleHttp\Client();
$response = $client->request('PUT', 'https://api.courier.com/lists/example.list.id/subscriptions', [
'body' => '{"recipients":[{"recipientId":"0460766e-8463-4905-ae98-b72c7aef41d6"}]}',
'headers' => [
'Accept' => 'application/json',
'Content-Type' => 'application/json',
],
]);
echo $response->getBody();
Example
Method: PUT
URL: https://api.courier.com/lists/abcdefgh12345678/subscriptions
Body:
{
"recipientId": "0460766e-8463-4905-ae98-b72c7aef41d6",
"preferences": {
"notifications": {
"abcdefgh12345678": {
"channel_preferences": [
{
"channel": "direct_message"
}
],
"rules": [
{
"type": "snooze"
}
],
"status": "OPTED_IN"
}
},
"categories": {
"cooking": {
"channel_preferences": [
{
"channel": "direct_message"
}
],
"rules": [
{
"type": "snooze"
}
],
"status": "OPTED_IN"
}
}
}
}