Polyv Help Center

Help Center

Create Interactive Listener Event

Updated: 2026-05-22 10:21:24

API Description

1、创建互动监听事件
2、接口支持https协议

API URL

https://api.polyv.net/live/v4/channel/interaction-event/save

Request Method

POST

API Constraints

  1. The API supports both HTTP and HTTPS. HTTPS is recommended for security. API calls have frequency limits. See details
  2. Task list

Request Parameter Description

Parameter Required Type Description
appId true String Account appId See details on obtaining keys
timestamp true Long Current 13-digit millisecond timestamp, valid within 3 minutes
sign true String Signature, a 32-character uppercase MD5 value. The appSecret key used to generate the signature is critical for communication data security. It must never be used directly on the client side. All APIs must be called through the customer's own server to relay to the POLYV server for response data. See signature generation rules

Request Body Parameter Description

Parameter Required Type Description
channelId true Integer Channel ID
tasks true Array Task rule list See tasks field description
callbackUrl false String Callback URL
allDone true String Whether all tasks in the tasks array must be completed to consider the task done: Y or N
payload false String Payload

Callback Description (POST Request)

Parameter Type Description
roomId String Room ID
accountId String Account ID
content String User completed task list, JSON array. See content parameter description
requestId String Request ID
timestamp Long Current 13-digit millisecond timestamp
sign String Signature verification. Generation rule: polyvlog + 数据key和value组成 + polyvlog, where 数据key is sorted alphabetically by first letter. MD5 encoded, then converted to uppercase. For example, parameters {roomId:'200060', channelId:'005200060', user:{nick:'yang'}}, the signature would be: md5('polyvChatSign' + 'channelId' + '005200060' + 'roomId' + '200060' + 'user' + JSON.stringify({nick:'yang'}) + 'polyvChatSign').toLocaleUpperCase();
totalBatch Integer Total number of batches for the current task
currentBatch Integer Current batch number for the task
Content Array Object Description
Parameter Type Description
data Array Task completion details list. See data list description
taskId String Task ID
activityId String Activity ID
taskData Object Task custom data
Data List Description
Parameter Type Description
userId String User ID
Callback Response Description

The callback interface response body must meet one of the following conditions, otherwise the system will retry. After 5 consecutive failures, the callback is abandoned:

  • The value of the code field is 200
  • The value of the status field is success

Tasks Parameter Description

Parameter Required Type Description
startTime true Long Start time
endTime true Long End time
type true String Task condition (online, check-in). When type is onlineTime, there is onlineTime; when type is signCount, there is signCount; when type is speakCount, there are speakCount and speakContent, meaning reaching speakCount times with comment content being speakContent; when type is customCount, there is customCount; when type is customCount, there is eventType; type can be loginList; when type is taskEndTimeOnline, the task triggers when the task is completed and the user is online
onlineTime false Integer Online duration (in milliseconds)
signCount false Integer Check-in count
userTags false Array User tags
speakCount false Integer Comment count
speakContent false String Comment content
customCount false Integer Custom count
eventType false String Event type
payload false String Payload, within 500 characters

Example

https://api.polyv.net/live/v4/channel/interaction-event/save?appId=frlr1zazn3&sign=012332FBD8DBCFC068AFCB484A2ADECB&timestamp=1670550787318

Request body JSON parameters:

{
    "channelId": 5392252,
    "tasks": [
        {
          "type":"signCount",
          "signCount": 2,
          "startTime": 1733888246000,
          "endTime":   1733888426000
        }
    ],
    "callbackUrl" : "http://callback/write",
    "allDone": "Y"
}

Response body JSON:

{
  "code": 200,
  "status": "success",
  "requestId": "5b7d9087-c632-4607-93de-ed3da2c7a4cf",
  "data": {
    "activityId": "95564091-b835-11ef-9283-17521e995374",
    "list": [
      {
        "taskId": "95564090-b835-11ef-9283-17521e995374",
        "result": {
          "status": "success",
          "message": "",
          "code": 200,
          "data": ""
        }
      }
    ]
  },
  "message": "添加任务成功",
  "success": true
}

Response Parameter Description

Parameter Type Description
code Integer Response status code, 200 for success, non-200 for failure
status String Response result, determined by business, success returns success, failure returns error
success Boolean Response result, determined by business, success returns true, failure returns false
data Object Contains taskId
error Object Error information when status code is non-200 See Error field description
requestId String Request ID, a unique UUID generated for each request, only for debugging and troubleshooting, should not be tied to business logic

Error Parameter Description

Parameter Type Description
code Integer Error code, used to determine the specific error cause
desc String Error description, corresponding to error.code

Java Request Example

For quick integration of the base code, please download the relevant dependency source code. Click here to download the source code. After downloading, add it to your own source code project. The HttpUtil.java and LiveSignUtil.java in the test cases are included in the download file.

It is strongly recommended to use the Live Java SDK for API integration. The Live Java SDK provides unified encapsulation and optimization for API call logic, exception handling, data signing, and HTTP request thread pools.

private final Logger log = LoggerFactory.getLogger(getClass());
/**
 * 新建监听事件
 * @throws IOException
 * @throws NoSuchAlgorithmException
 */
@Test
public void createTest() throws IOException, NoSuchAlgorithmException {
    //公共参数,填写自己的实际参数
    String appId = super.appId;
    String appSecret = super.appSecret;
    String timestamp = String.valueOf(System.currentTimeMillis());
        
    String url = "https://api.polyv.net/live/v4/channel/interaction-event/save";
    //业务参数
    Integer channelId = 5004544;
    String activityName = "demoData";
    Integer taskRule = 1;
    Long startTime = 1722035312584;
    Long endTime = 1722036312584;
    List<Task> tasks = new ArrayList();
    
    //http 调用逻辑
    Map<String, String> requestMap = new HashMap<>();
    requestMap.put("appId", appId);
    requestMap.put("timestamp", timestamp);
        
    Map<String, Object> jsonMap = new HashMap<>();
    jsonMap.put("channelId", channelId);
    jsonMap.put("tasks", tasks);
    jsonMap.put("callbackUrl", "http://callback/write");
    jsonMap.put("allDone", "Y");
    
    requestMap.put("sign", LiveSignUtil.getSign(requestMap, appSecret));
    
    url = HttpUtil.appendUrl(url, requestMap);
    String response = HttpUtil.postJsonBody(url, JSON.toJSONString(jsonMap), null);
    
    log.info("测试新建监听事件:{}", response);
    //do somethings
    
}

Response Example

For global system error descriptions, see Global Error Description

Success Example

{
  "code": 200,
  "status": "success",
  "requestId": "5b7d9087-c632-4607-93de-ed3da2c7a4cf",
  "data": {
    "activityId": "95564091-b835-11ef-9283-17521e995374",
    "list": [
      {
        "taskId": "95564090-b835-11ef-9283-17521e995374",
        "result": {
          "status": "success",
          "message": "",
          "code": 200,
          "data": ""
        }
      }
    ]
  },
  "message": "添加任务成功",
  "success": true
}

Error Example

{
    "code": 400,
    "status": "error",
    "requestId": "d310b70bc329403f87f77f9203d50f89.128.16360831552223589",
    "error": {
        "code": 20001,
        "desc": "application not found."
    },
    "success": false
}
{
    "code": 200,
    "status": "success",
    "requestId": "29fc71ae-110f-43f2-87f0-4d60a6c743ff",
    "data": {
        "list": [
            {
                "taskId": "2368e870-b835-11ef-9283-17521e995374",
                "result": {
                    "status": "error",
                    "message": "time is too long",
                    "code": 505,
                    "data": {}
                }
            }
        ],
        "activityId": "2368e871-b835-11ef-9283-17521e995374"
    },
    "message": "添加任务成功",
    "success": true
}
联系客服,在线咨询