REST ClientPubSub

create_token

View as MarkdownOpen in Claude

Create a PubSub authentication token.

Request

ttlintegerRequired1-43200
The maximum time, in minutes, for which the access token will be valid. Between 1 and 43,200 (30 days).
channelsobjectRequired
Each channel with `write` and `read` objects with boolean as values. Max of 500 channels inside main `channels`. Either `read`, `write`, or both are required inside each channel and default to false. Each channel name can be up to 250 characters. Must be valid JSON.
member_idstringOptional<=250 characters
The unique identifier of the member. Up to 250 characters. If not specified, a random UUID will be generated.
stateobjectOptional
An arbitrary JSON object available to store stateful application information in. Must be valid JSON and have a maximum size of 2,000 characters.

Response

tokenstringRequired
A PubSub Token to be used to authenticate clients to the PubSub Service.

Response Example

Response
1{
2 "token": "eyJ0eXAiOiJWUlQiLCJhbGciOiJIUzUxMiJ9.eyJpYXQiOjE2MjIxMjAxMjMsI...wMCwicnNlIjo5MDB9-BqG-DqC5LhpsdMWEFjhVkTBpQ"
3}

Example

1from signalwire.rest import RestClient
2
3client = RestClient(
4 project="your-project-id",
5 token="your-api-token",
6 host="your-space.signalwire.com",
7)
8
9token = client.pubsub.create_token(
10 channels=["notifications", "updates"],
11 member_id="user-123",
12 ttl=3600,
13)
14print("PubSub token:", token.get("token"))