创建订阅 - CreateNotification
功能介绍
该接口用于创建指定实例下对应的应用下的设备操作,订阅到指定的Topic。
调试
您可以在API Explorer中调试该接口,支持自动认证鉴权。API Explorer可以自动生成SDK代码示例,并提供SDK代码示例调试功能。
授权信息
账号具备所有API的调用权限,如果使用账号下的IAM用户调用当前API,该IAM用户需具备调用API所需的权限,具体权限要求请参见权限和授权项。
URI
POST /v2/{project_id}/link/instances/{instance_id}/notifications
| 参数 | 是否必选 | 参数类型 | 描述 |
|---|---|---|---|
| project_id | 是 | String | 项目ID,获取方式请参见API参考的“附录 > 获取项目ID”章节。 |
| instance_id | 是 | String | 实例ID。 |
请求参数
| 参数 | 是否必选 | 参数类型 | 描述 |
|---|---|---|---|
| X-Auth-Token | 是 | String | 用户Token。通过调用IAM服务获取用户Token接口获取(响应消息头中X-Subject-Token的值)。 |
| 参数 | 是否必选 | 参数类型 | 描述 |
|---|---|---|---|
| app_id | 否 | String | 通知归属的应用ID。只有创建应用级订阅时传入。app_id、product_serial都不传入时创建实例级订阅。 |
| product_serial | 否 | String | 通知归属的产品标识。只有创建产品级订阅时传入,此时忽略app_id。app_id、product_serial都不传入时创建实例级订阅。 |
| type | 是 | Integer | 通知类型,0-设备上线通知,1-设备下线通知,2-设备添加通知,3-设备删除通知,4-设备变更通知,5-未认证设备通知。 |
| topic | 是 | String | 通知发送的主题名,该主题需要在MQS存在。 |
| status | 是 | Integer | 启停状态,0-启用,1-停用。 |
响应参数
状态码:200
| 参数 | 参数类型 | 描述 |
|---|---|---|
| notification_id | Integer | 订阅ID。 |
| type | Integer | 订阅类型,0:设备上线通知类型,1:设备下线通知类型,2:设备添加通知类型, 3:设备删除通知类型,4:设备变更通知类型。 |
| status | Integer | 订阅管理状态,0:启用,1:停用。 |
| topic | String | 订阅的Topic名称。 |
| instance_id | String | 实例ID。 |
| app_id | String | 应用ID。 |
| product_serial | String | 通知归属的产品标识。 |
状态码:400
| 参数 | 参数类型 | 描述 |
|---|---|---|
| error_code | String | 系统错误码,针对4xx和5xx类HTTP错误码的详细错误码。 |
| error_msg | String | 错误描述。 |
| request_id | String | 消息ID。 |
状态码:404
| 参数 | 参数类型 | 描述 |
|---|---|---|
| error_code | String | 系统错误码,针对4xx和5xx类HTTP错误码的详细错误码。 |
| error_msg | String | 错误描述。 |
| request_id | String | 消息ID。 |
状态码:500
| 参数 | 参数类型 | 描述 |
|---|---|---|
| error_code | String | 系统错误码,针对4xx和5xx类HTTP错误码的详细错误码。 |
| error_msg | String | 错误描述。 |
| request_id | String | 消息ID。 |
请求示例
订阅指定集成应用下设备的上线通知,并把消息发送到MQS的指定Topic。
{
"app_id" : "ef3845be-091a-4ab5-869a-9de0025e2165",
"type" : 0,
"topic" : "online",
"status" : 0
} 响应示例
状态码:200
Created
{
"notification_id" : 100,
"type" : 0,
"status" : 0,
"topic" : "string",
"instance_id" : "string",
"app_id" : "string"
} 状态码:404
Not Found
{
"error_code" : "ROMA.00110006",
"error_msg" : "The resource does not exist. Check whether the resource ID 1 is correct.",
"request_id" : "624c8be1-39b6-47b7-941d-c159aced368a-1619602544650-cnnorth7a-P-romalink-service01"
} 状态码
| 状态码 | 描述 |
|---|---|
| 200 | Created |
| 400 | Bad Request |
| 404 | Not Found |
| 500 | Internal Server Error |
错误码
请参见错误码。