
# 产品添加通知
#### 功能介绍
应用服务器在调用物联网平台的[创建规则触发条件 - CreateRoutingRule](https://support.huaweicloud.com/api-iothub/iot_06_v5_01307.html)（Resource:product，Event:create）、[创建规则动作 - CreateRuleAction](https://support.huaweicloud.com/api-iothub/iot_06_v5_01302.html)、[修改规则触发条件 - UpdateRoutingRule](https://support.huaweicloud.com/api-iothub/iot_06_v5_01309.html)接口配置并激活规则后，当物联网平台中的产品添加时，物联网平台会向应用服务器推送通知消息。
#### URI
POST /由应用服务器创建产品添加通知规则的转发目标决定
#### 请求参数
表1请求Body参数 
| 参数            | 是否必选 | 参数类型                                                                                                                          | 描述                                                                                                         |
|:---|:---|:---|:---|
| resource      | 是    | String                                                                                                                        | **参数说明**：订阅的资源名称，取值为product。                                                                               |
| event         | 是    | String                                                                                                                        | **参数说明**：订阅的资源事件，取值为create。                                                                                |
| event_time    | 是    | String                                                                                                                        | **参数说明**：资源事件生成时间,格式：yyyyMMdd'T'HHmmss'Z' UTC字符串，如：20151212T121212Z。若需要显示本地时区，您需要自己进行时间转换。                 |
| event_time_ms | 否    | String                                                                                                                        | **参数说明**：资源事件生成时间,格式：yyyy-MM-dd'T'HH:mm:ss.SSS'Z' UTC字符串，如：2015-12-12T12:12:12.000Z。若需要显示本地时区，您需要自己进行时间转换。 |
| request_id    | 否    | String                                                                                                                        | **参数说明**：消息ID，由设备侧指定或平台生成，用于跟踪业务流程。                                                                        |
| notify_data   | 是    | [ProductUpdateNotifyData] object | **参数说明**：推送消息。                                                                                             |
   
 表2ProductUpdateNotifyData 
| 参数   | 是否必选 | 参数类型                                                                                          | 描述               |
|:---|:---|:---|:---|
| body | 是    | [Product] object | **参数说明**：推送消息内容。 |
   
 表3Product 
| 参数                   | 是否必选 | 参数类型                                                                                                                        | 描述                                                                |
|:---|:---|:---|:---|
| app_id               | 否    | String                                                                                                                      | **参数说明**：资源空间ID。                                                  |
| app_name             | 否    | String                                                                                                                      | **参数说明**：资源空间名称。                                                  |
| product_id           | 否    | String                                                                                                                      | **参数说明**：产品ID，用于唯一标识一个产品，在物联网平台创建产品后由平台分配获得。                      |
| name                 | 否    | String                                                                                                                      | **参数说明**：产品名称。                                                    |
| device_type          | 否    | String                                                                                                                      | **参数说明**：设备类型。                                                    |
| protocol_type        | 否    | String                                                                                                                      | **参数说明**：设备使用的协议类型。取值范围：MQTT，CoAP，HTTP，HTTPS，Modbus，ONVIF。        |
| data_format          | 否    | String                                                                                                                      | **参数说明**：设备上报数据的格式，取值范围：json，binary。                              |
| manufacturer_name    | 否    | String                                                                                                                      | **参数说明**：厂商名称。                                                    |
| industry             | 否    | String                                                                                                                      | **参数说明**：设备所属行业。                                                  |
| description          | 否    | String                                                                                                                      | **参数说明**：产品的描述信息。                                                 |
| service_capabilities | 否    | Array of [ServiceCapability] objects | **参数说明**：设备的服务能力列表。                                               |
| create_time          | 否    | String                                                                                                                      | **参数说明**：在物联网平台创建产品的时间，格式：yyyyMMdd'T'HHmmss'Z'，如20151212T121212Z。 |
   
 表4ServiceCapability 
| 参数           | 是否必选 | 参数类型                                                                                                                    | 描述                                                                                                                                                                                                     |
|:---|:---|:---|:---|
| service_id   | 是    | String                                                                                                                  | **参数说明**：设备的服务ID。                                                                                                                                                                                      |
| service_type | 是    | String                                                                                                                  | **参数说明**：设备的服务类型。                                                                                                                                                                                      |
| properties   | 否    | Array of [ServiceProperty] objects | **参数说明**：设备服务支持的属性列表。                                                                                                                                                                                  |
| commands     | 否    | Array of [ServiceCommand] objects   | **参数说明**：设备服务支持的命令列表。                                                                                                                                                                                  |
| events       | 否    | Array of [ServiceEvent] objects       | **参数说明**：设备服务支持的事件列表。                                                                                                                                                                                  |
| description  | 否    | String                                                                                                                  | **参数说明**：设备服务的描述信息。                                                                                                                                                                                    |
| option       | 否    | String                                                                                                                  | **参数说明**：指定设备服务是否必选。Master（主服务）, Mandatory（必选服务）, Optional（可选服务），目前本字段为非功能性字段，仅起到标识作用。默认为Optional（可选服务）。 缺省值：**Optional** |
   
 表5ServiceProperty 
| 参数            | 是否必选 | 参数类型             | 描述                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
|:---|:---|:---|:---|
| property_name | 是    | String           | **参数说明**：设备属性名称。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| required      | 否    | Boolean          | **参数说明**：设备属性是否必选。默认为false。 缺省值：**false**                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| data_type     | 是    | String           | **参数说明**：参数的数据类型。 **取值范围**： int : 整数类型。 long: 长整型。 decimal：小数类型。 string：字符串类型。 DateTime：日期类型。 jsonObject：json对象类型。 enum：枚举类型。 boolean：布尔类型。 string list: 字符串数组类型。                                                                                                                                                        |
| enum_list     | 否    | Array of strings | **参数说明**：设备属性的枚举值列表。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| min           | 否    | String           | **参数说明**：设备属性的最小值。 最小长度：**1** 最大长度：**16**                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| max           | 否    | String           | **参数说明**：设备属性的最大值。 最小长度：**1** 最大长度：**16**                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| max_length    | 否    | Integer          | **参数说明**：设备属性的最大长度。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| step          | 否    | Double           | **参数说明**：设备属性的步长。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| unit          | 否    | String           | **参数说明**：设备属性的单位。 最大长度：**16**                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| method        | 是    | String           | **参数说明**：设备属性的访问模式。取值范围：RWE，RW，RE，WE，E，W，R。 - R：属性值可读   - W：属性值可写   - E：属性值可订阅，即属性值变化时上报事件。    |
| description   | 否    | String           | **参数说明**：设备属性的描述。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| default_value | 否    | Object           | **参数说明**：设备属性的默认值。如果设置了默认值，使用该产品创建设备时，会将该属性的默认值写入到该设备的设备影子预期数据中，待设备上线时将该属性默认值下发给设备。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
   
 表6ServiceCommand 
| 参数           | 是否必选 | 参数类型                                                                                                                                  | 描述                  |
|:---|:---|:---|:---|
| command_name | 是    | String                                                                                                                                | **参数说明**：设备命令名称。    |
| paras        | 否    | Array of [ServiceCommandPara] objects         | **参数说明**：设备命令的参数列表。 |
| responses    | 否    | Array of [ServiceCommandResponse] objects | **参数说明**：设备命令的响应列表。 |
   
 表7ServiceCommandResponse 
| 参数            | 是否必选 | 参数类型                                                                                                                          | 描述                    |
|:---|:---|:---|:---|
| paras         | 否    | Array of [ServiceCommandPara] objects | **参数说明**：设备命令响应的参数列表。 |
| response_name | 是    | String                                                                                                                        | **参数说明**：设备命令响应名称。    |
   
 表8ServiceEvent 
| 参数         | 是否必选 | 参数类型                                                                                                                          | 描述                  |
|:---|:---|:---|:---|
| event_type | 是    | String                                                                                                                        | **参数说明**：设备事件类型。    |
| paras      | 否    | Array of [ServiceCommandPara] objects | **参数说明**：设备事件的参数列表。 |
   
 表9ServiceCommandPara 
| 参数          | 是否必选 | 参数类型             | 描述                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
|:---|:---|:---|:---|
| para_name   | 是    | String           | **参数说明**：参数的名称。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| required    | 否    | Boolean          | **参数说明**：参数是否必选。默认为false。 缺省值：**false**                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| data_type   | 是    | String           | **参数说明**：参数的数据类型。 **取值范围**： int : 整数类型。 long: 长整型。 decimal：小数类型。 string：字符串类型。 DateTime：日期类型。 jsonObject：json对象类型。 enum：枚举类型。 boolean：布尔类型。 string list: 字符串数组类型。 |
| enum_list   | 否    | Array of strings | **参数说明**：参数的枚举值列表。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| min         | 否    | String           | **参数说明**：参数的最小值。 最小长度：**1** 最大长度：**16**                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| max         | 否    | String           | **参数说明**：参数的最大值。 最小长度：**1** 最大长度：**16**                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| max_length  | 否    | Integer          | **参数说明**：参数的最大长度。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| step        | 否    | Double           | **参数说明**：参数的步长。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| unit        | 否    | String           | **参数说明**：参数的单位。 最大长度：**16**                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
| description | 否    | String           | **参数说明**：参数的描述。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
   
#### 响应参数
**状态码：200**
OK
无
#### 请求示例
产品添加通知示例：
```
产品添加通知
{
  "resource" : "product",
  "event" : "create",
  "event_time" : "20151212T121212Z",
  "event_time_ms" : "2015-12-12T12:12:12.000Z",
  "request_id" : "3fe58d5e-8697-4849-a165-7db128f7e776",
  "notify_data" : {
    "body" : {
      "app_name" : "testAPP01",
      "protocol_type" : "CoAP",
      "data_format" : "binary",
      "service_capabilities" : [ {
        "service_type" : "temperature",
        "service_id" : "temperature",
        "description" : "temperature",
        "properties" : [ {
          "unit" : "centigrade",
          "min" : "1",
          "method" : "R",
          "max" : "100",
          "data_type" : "decimal",
          "description" : "force",
          "step" : 0.1,
          "default_value" : {
            "color" : "red",
            "size" : 1
          },
          "enum_list" : [ "string" ],
          "required" : true,
          "property_name" : "temperature",
          "max_length" : 100
        } ],
        "commands" : [ {
          "command_name" : "reboot",
          "responses" : [ {
            "response_name" : "ACK",
            "paras" : [ {
              "unit" : "km/h",
              "min" : "1",
              "max" : "100",
              "para_name" : "force",
              "data_type" : "string",
              "description" : "force",
              "step" : 0.1,
              "enum_list" : [ "string" ],
              "required" : false,
              "max_length" : 100
            } ]
          } ],
          "paras" : [ {
            "unit" : "km/h",
            "min" : "1",
            "max" : "100",
            "para_name" : "force",
            "data_type" : "string",
            "description" : "force",
            "step" : 0.1,
            "enum_list" : [ "string" ],
            "required" : false,
            "max_length" : 100
          } ]
        } ],
        "events" : [ {
          "event_type" : "reboot",
          "paras" : [ {
            "unit" : "km/h",
            "min" : "1",
            "max" : "100",
            "para_name" : "force",
            "data_type" : "string",
            "description" : "force",
            "step" : 0.1,
            "enum_list" : [ "string" ],
            "required" : false,
            "max_length" : 100
          } ]
        } ],
        "option" : "Mandatory"
      } ],
      "create_time" : "20190303T081011Z",
      "product_id" : "5ba24f5ebbe8f56f5a14f605",
      "name" : "Thermometer",
      "description" : "this is a thermometer",
      "device_type" : "Thermometer",
      "industry" : "smartCity",
      "manufacturer_name" : "ABC",
      "app_id" : "jeQDJQZltU8iKgFFoW060F5SGZka"
    }
  }
}
```
#### 响应示例
无
#### 状态码
| 状态码 | 描述 |
|:---|:---|
| 200 | OK |
   
#### 错误码
请参见[错误码](https://support.huaweicloud.com/api-iothub/ErrorCode.html)。
