创建产品 - CreateProduct
功能介绍
创建产品。
授权信息
账号具备所有API的调用权限,如果使用账号下的IAM用户调用当前API,该IAM用户需具备调用API所需的权限,具体权限要求请参见权限和授权项。
URI
POST /v2/{project_id}/link/instances/{instance_id}/products
|
参数 |
是否必选 |
参数类型 |
描述 |
|---|---|---|---|
|
project_id |
是 |
String |
项目ID。兼容20.0场景默认为default。项目ID,获取方式请参见API参考的“附录 > 获取项目ID”章节。 |
|
instance_id |
是 |
String |
实例ID。兼容20.0场景默认为default。 |
请求参数
|
参数 |
是否必选 |
参数类型 |
描述 |
|---|---|---|---|
|
X-Auth-Token |
是 |
String |
用户Token。通过调用IAM服务获取用户Token接口获取(响应消息头中X-Subject-Token的值)。 |
|
参数 |
是否必选 |
参数类型 |
描述 |
|---|---|---|---|
|
app_id |
是 |
String |
应用ID。 |
|
name |
是 |
String |
产品名称,创建产品时租户内唯一,长度最大64,仅支持中文、英文字、数字、下划线和中划线。 |
|
manufacturer_id |
是 |
String |
产品供应商ID。 |
|
manufacturer_name |
是 |
String |
厂商名称。 |
|
model |
是 |
String |
产品型号,支持英文大小写,数字,下划线,中划线,空格和点(首尾空格会被忽略),长度2-50。 |
|
product_type |
是 |
Integer |
产品类型,0-普通产品(不支持子设备) 1-网关产品。 |
|
description |
否 |
String |
产品描述,长度0-200。 |
|
protocol_type |
是 |
Integer |
产品的协议类型,0-mqtt 1-CoAP 2-modbus 4-opcua 5-扩展协议。 |
|
device_type |
否 |
String |
产品的设备类型(默认Default)。 |
|
template_id |
否 |
Integer |
关联产品模板ID(使用产品模板创建产品时使用,否则为空),自动向下取整,该字段为数据库中的自增唯一标识符;通过调用查询产品模板接口:GET /v2/{project_id}/link/instances/{instance_id}/product-templates获取响应体中对应的id字段值。 |
|
version |
否 |
String |
模型版本。 |
|
data_format |
否 |
Integer |
产品的数据格式,0-JSON 1-USER_DEFINED。 |
响应参数
状态码:201
|
参数 |
参数类型 |
描述 |
|---|---|---|
|
permissions |
Array of strings |
权限。 |
|
id |
Integer |
产品ID,该字段为数据库中的自增唯一标识符;通过调用查询产品接口:GET /v2/{project_id}/link/instances/{instance_id}/products获取响应体中对应的id字段值。 |
|
product_serial |
String |
产品唯一序列(系统唯一值,用于MQS的TOPIC中标记产品)。 |
|
app_id |
String |
应用ID。 |
|
name |
String |
产品名称,创建产品时租户内唯一,长度最大64,仅支持中文、英文字母、数字、下划线和中划线。 |
|
manufacturer_id |
String |
产品供应商ID。 |
|
manufacturer_name |
String |
厂商名称。 |
|
model |
String |
产品型号。 |
|
product_type |
Integer |
产品类型,0-普通产品(不支持子设备) 1-网关产品。 |
|
description |
String |
产品描述,长度0-200。 |
|
protocol_type |
Integer |
产品的协议类型,0-mqtt 1-CoAP 2-modbus 4-opcua 5-扩展协议。 |
|
device_type |
String |
产品的设备类型(默认Default)。 |
|
version |
String |
产品版本。 |
|
created_user |
CreatedUser object |
创建时的用户。 |
|
last_updated_user |
LastUpdatedUser object |
最后更新时的用户。 |
|
authentication |
Authentication object |
鉴权 |
|
created_datetime |
Long |
创建时间,timestamp(ms),使用UTC时区。 |
|
app_name |
String |
应用名称。 |
|
data_format |
Integer |
data_format 0-JSON 1-USER_DEFINED |
|
template_id |
Integer |
关联的产品模板ID,该字段为数据库中的自增唯一标识符;通过调用查询产品模板接口:GET /v2/{project_id}/link/instances/{instance_id}/product-templates获取响应体中对应的id字段值。 |
|
template_name |
String |
关联的产品模板名称 |
|
sync_template_date |
Long |
同步产品模板时间,timestamp(ms),使用UTC时区。 |
|
参数 |
参数类型 |
描述 |
|---|---|---|
|
user_name |
String |
一型一密/一机一密的用户名。 |
|
password |
String |
一型一密/一机一密的密码,输入要求:至少1个数字,1个大写字母,1个小写字母,1个特殊字符(~!@#$%^&*()-_=+|[{}];:<>/?),长度8-32个字符。 |
状态码: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。 |
请求示例
创建一个产品,产品类型为普通产品,协议类型为MQTT,产品状态为启用。
{
"app_id" : "ef3845be-091a-4ab5-869a-9de0025e2165",
"name" : "device",
"manufacturer_id" : 10001,
"manufacturer_name" : "test",
"model" : "model1",
"product_type" : 0,
"protocol_type" : 0,
"status" : 0,
"device_type" : "Default"
}
响应示例
状态码:201
Created
{
"permissions" : [ "read", "access", "delete", "modify" ],
"id" : 120671,
"product_serial" : "Dd1bRt122894",
"app_id" : "a1503e51-46f7-4d23-8617-7cb2d28dde98",
"name" : "pro-opcua",
"manufacturer_id" : "pro-opcua",
"manufacturer_name" : "pro-opcua",
"model" : "pro-opcua",
"product_type" : 0,
"description" : "opcua product",
"protocol_type" : 4,
"device_type" : "default",
"version" : "version",
"status" : 0,
"created_datetime" : 1607481372416,
"last_updated_datetime" : 1607481372416,
"app_name" : "app-link",
"data_format" : 0,
"created_user" : {
"user_id" : "6546435432432",
"user_name" : "user1"
},
"last_updated_user" : {
"user_id" : "6546435432432",
"user_name" : "user1"
},
"authentication" : {
"user_name" : "4MjxbCl4q461",
"password" : "********"
}
}
状态码:400
Bad Request
{
"error_code" : "ROMA.00110001",
"error_msg" : "The parameter does not meet verification rules: [name:Can not be empty, manufacturer_name:Can not be empty, manufacturer_id:Can not be empty, product_type:must not be null, app_id:must not be empty, model:Can not be empty]",
"request_id" : "b728949c-dfb5-4277-b54e-7c05e1b0b598-1619663322828-cnnorth7a-P-romalink-service01"
}
状态码:404
Not Found
{
"error_code" : "ROMA.00110006",
"error_msg" : "The resource does not exist. Check whether the resource ID ff38023c-0854-4779-847d-72528e1f5da5 is correct.",
"request_id" : "72b07918-f6a2-4721-81bf-f3fd5486025e-1619663576836-cnnorth7a-P-romalink-service01"
}
状态码:500
Internal Server Error
{
"error_code" : "ROMA.00110002",
"error_msg" : "The instance does not exist. project_id: 397cd10b30544c588b2f4a56d83856c4, instance_id: f3bb386a-23ec-47aa-9943-4c60ac658611",
"request_id" : "c8c06d0a-be92-4fdf-9d10-bc20131ab158-1619593104919-cnnorth7a-P-romalink-service01"
}
状态码
|
状态码 |
描述 |
|---|---|
|
201 |
Created |
|
400 |
Bad Request |
|
404 |
Not Found |
|
500 |
Internal Server Error |
错误码
请参见错误码。