Set metadata
Set a single custom key-value pair in a specific open channel. You must provide a user ID as the owner of the entry.
Metadata is destroyed when the open channel is destroyed.
Enable the service
Before using this feature, enable open channel metadata for your App Key. See Open channel metadata overview.
If the service is not enabled, the API returns error 1009. If you exceed the rate limit while the service is disabled, the API returns HTTP 429 (error code 1008).
Request
POST: https://[Base URL](/platform-chat-api/base-url)/chatroom/entry/set.json
Rate limit: 100 metadata operations per second, shared with the batch set endpoint (/chatroom/entry/batch/set.json). If you only use this single-set endpoint, you can call it 100 times per second.
Signature: Required. See API request signature.
Request body
Content type: application/x-www-form-urlencoded
| Parameter | Type | Required | Description |
|---|---|---|---|
chatroomId | String | Yes | The open channel ID. |
userId | String | Yes | The user ID performing the operation. The user does not need to be in the open channel when using the server API. |
key | String | Yes | Metadata key. Supports letters, numbers, and +, =, -, _. Case-sensitive. Max 128 characters. Each open channel supports up to 100 key-value pairs. |
value | String | Yes | Metadata value. Max 4,096 characters. |
autoDelete | Int | No | Whether to delete this key when the owner user leaves the open channel. 1: delete. 0: keep (default). |
objectName | String | No | Message type for the metadata change notification. Typically the built-in RC:chrmKVNotiMsg, or a custom message type. When provided, a notification message is sent when the metadata changes. |
content | String | No | Content of the notification message, as a JSON string. When objectName is RC:chrmKVNotiMsg, the content must include type, key, and value fields. |
Request example
POST /chatroom/entry/set.json HTTP/1.1
Host: api.sg-light-api.com
App-Key: uwd1c0sxdlx2
Nonce: 14314
Timestamp: 1408710653491
Signature: 45beb7cc7307889a8e711219a47b7cf6a5b000e8
Content-Type: application/x-www-form-urlencoded
chatroomId=kvchatroom2&userId=Lnq9MJsPY&key=huihui&value=555&autoDelete=0&objectName=RC%3AchrmKVNotiMsg&content=%7B%22key%22%3A%22keyli%22%2C%22value%22%3A%225%22%2C%22type%22%3A%221%22%7D&extra=111111
Response
| Field | Type | Description |
|---|---|---|
code | Number | Return code. 200 indicates success. |
Response example
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
{"code":200}