Skip to Content

Set topic subscriptions

Upserts explicit subscribed or unsubscribed status for one channel.

POST
/v1/topics/{id}/subscriptions

Upserts explicit subscribed or unsubscribed status for one channel. Each contact is named by ID, email, or phone. New addresses create contacts in the topic's namespace. Repeating the same status is idempotent. On email, setting subscribed never overrides a contact's explicit unsubscribe: those contacts are counted in kept, and only the recipient can resubscribe them.

Authorization

apiKey
headerx-api-key<token>

Path Parameters

id*string
Match^tpc_[0-9a-hjkmnp-tv-z]{16,24}$

Request Body

application/json
  1. body
contacts*array<||>
Items1 <= items <= 1000
channel*string
Value in"sms""whatsapp""email"
status*string
Value in"subscribed""unsubscribed"
source?|null

Response Body

TopicSetSubscriptionsResult

application/json
  1. response
updated*integer
Range0 <= value <= 9007199254740991
kept*integer

Email contacts left unsubscribed because they explicitly unsubscribed from this topic. Only the recipient can resubscribe them, through the preference page or double opt-in.

Range0 <= value <= 9007199254740991
Example Request
import { createClient } from "samva";

const samva = createClient({ apiKey: process.env.SAMVA_API_KEY! });

const result = await samva.topics.setSubscriptions({
  "id": "example",
  "contacts": [
    {
      "contactId": "example"
    }
  ],
  "channel": "sms",
  "status": "subscribed"
});
Example Response
{
  "updated": 0,
  "kept": 0
}

Related documentation