Updated on 2024-12-02 GMT+08:00

Modify a Product

Function

This API is used by an application to modify details of a product model that has been imported to the IoT platform, including the services, properties, and commands in the product model. This API is used to modify the product but not to modify or install a codec. If the service definition in the product is modified and the corresponding codec exists on the platform, modify and reinstall the codec.

Debugging

You can debug this API through automatic authentication in API Explorer or use the SDK sample code generated by API Explorer.

URI

PUT /v5/iot/{project_id}/products/{product_id}

Table 1 Path Parameters

Parameter

Mandatory

Type

Description

project_id

Yes

String

Parameter description: project ID. For details about how to obtain the project ID, see Obtaining a Project ID.

product_id

Yes

String

Parameter description: product ID, which uniquely identifies a product. It is allocated by the platform after the product is created on the platform.

Value: The value can contain a maximum of 36 characters. Only letters, digits, underscores (_), and hyphens (-) are allowed.

Request Parameters

Table 2 Request header parameters

Parameter

Mandatory

Type

Description

X-Auth-Token

No

String

Parameter description: user token. You can obtain the token by calling the IAM API Obtaining a User Token Through Password Authentication. X-Subject-Token in the response header returned by the API is the desired user token. For details about how to obtain the token, see Token Authentication.

Instance-Id

No

String

Parameter description: instance ID. Unique identifier of each instance in the physical multi-tenant scenario. Mandatory for professional editions and recommended in other cases. Log in to the IoTDA console and choose Overview in the navigation pane to view the instance ID. For details, see Viewing Instance Details.

Table 3 Request body parameters

Parameter

Mandatory

Type

Description

app_id

No

String

Parameter description: resource space ID. This parameter is optional. If you have multiple resource spaces, you can use this parameter to specify the resource space that the product to be modified belongs to. If this parameter is not specified, the product in the default resource space will be modified. If there is no product in the default resource space, the earliest created product will be modified. If you have multiple resource spaces and do not want to specify this parameter, contact Huawei technical engineers to combine your resource spaces.

Value: The value can contain a maximum of 36 characters. Only letters, digits, underscores (_), and hyphens (-) are allowed.

name

No

String

Parameter description: product name.

Value: The value can contain a maximum of 64 characters. Only letters, digits, and special characters (_?'#().,&%@!-) are allowed.

device_type

No

String

Parameter description: device type.

Value: The value can contain a maximum of 32 characters. Only letters, digits, and special characters (_?'#().,&%@!-) are allowed.

protocol_type

No

String

Parameter description: protocol used by the device. Do not change other protocol types to CoAP.

Options: MQTT, CoAP, HTTP, HTTPS, Modbus, ONVIF, OPC-UA, OPC-DA, TCP, ""UDP**, and Other.

data_format

No

String

Parameter description: format of the data reported by the device.

Options:

  • json: JSON format

  • binary: binary code stream format

service_capabilities

No

Array of ServiceCapability objects

Parameter description: list of service capabilities of the device.

manufacturer_name

No

String

Parameter description: manufacturer name.

Value: The value can contain a maximum of 32 characters. Only letters, digits, and special characters (_?'#().,&%@!-) are allowed.

industry

No

String

Parameter description: industry to which the device belongs.

Value: The value can contain a maximum of 64 characters. Only letters, digits, and special characters (_?'#().,&%@!-) are allowed.

description

No

String

Parameter description: product description.

Value: The value can contain a maximum of 128 characters. Only letters, digits, spaces, and special characters (_?'#().,;&%@!-:$![]~/) are allowed.

Table 4 ServiceCapability

Parameter

Mandatory

Type

Description

service_id

Yes

String

Parameter description: service ID of the device. The value must be unique in a product.

Value: The value can contain a maximum of 64 characters. Only letters, digits, and special characters (_?'#().,&%@!-$) are allowed.

service_type

Yes

String

Parameter description: service type of the device.

Value: The value can contain a maximum of 64 characters. Only letters, digits, and special characters (_?'#().,&%@!-$) are allowed.

properties

No

Array of ServiceProperty objects

Parameter description: list of properties supported by the device service.

Value: The array length cannot exceed 500.

commands

No

Array of ServiceCommand objects

Parameter description: list of commands supported by the device service.

Value: The array length cannot exceed 500.

events

No

Array of ServiceEvent objects

Parameter description: list of events supported by the device service. Currently, event customization is not supported. You do not need to define this field when creating or modifying a product.

Value: The array length cannot exceed 500.

description

No

String

Parameter description: device service description.

Value: The value can contain a maximum of 128 characters. Only letters, digits, spaces, and special characters (_?'#().,;&%@!-:$![]~/) are allowed.

option

No

String

Parameter description: whether the device service is mandatory. Currently, this field is not a functional field and is used only for identification.

Options:

  • Master: master service

  • Mandatory: mandatory service

  • Optional: optional service

    The default value is Optional.

Table 5 ServiceProperty

Parameter

Mandatory

Type

Description

property_name

Yes

String

Parameter description: device property name. The value must be unique in the device service. If device property names are used as keys in the device shadow JSON file, the names cannot contain periods (.), dollar signs ($), and the null character (hexadecimal ASCII code 00). A device shadow file that contains these special characters cannot be updated.

Value: The value can contain a maximum of 64 characters. Only letters, digits, and special characters (_?'#().,&%@!-) are allowed.

data_type

Yes

String

Parameter description: data type of the device property.

Options: int, long, decimal, string, DateTime, jsonObject, enum, boolean, and string list.

required

No

Boolean

Parameter description: whether the device property is mandatory. The default value is false.

enum_list

No

Array of strings

Parameter description: list of enumerated values of the device property.

min

No

String

Parameter description: minimum value of the device property.

Value length: 1–16 characters

max

No

String

Parameter description: maximum value of the device property.

Value length: 1–16 characters

max_length

No

Integer

Parameter description: maximum length of the device property.

step

No

Double

Parameter description: step of the device property.

unit

No

String

Parameter description: unit of the device property.

Value length: a maximum of 16 characters

method

Yes

String

Parameter description: access mode of the device property.

Options: RWE, RW, RE, WE, E, W, and R.

  • R: The property value can be read.

  • W: The property value can be written.

  • E: The property value can be subscribed to, that is, an event is reported when the property value changes.

description

No

String

Parameter description: device property description.

Value: The value can contain a maximum of 128 characters. Only letters, digits, spaces, and special characters (_?'#().,;&%@!-:$![]~/) are allowed.

default_value

No

Object

Parameter description: default value of the device property. If the default value is set, it will be written to the desired data of the device shadow when the product is used to create a device. When the device goes online, the default value will be delivered to the device.

Table 6 ServiceCommand

Parameter

Mandatory

Type

Description

command_name

Yes

String

Parameter description: device command name. The value must be unique in the device service.

Value: The value can contain a maximum of 64 characters. Only letters, digits, and special characters (_?'#().,&%@!-) are allowed.

paras

No

Array of ServiceCommandPara objects

Parameter description: list of device command parameters.

responses

No

Array of ServiceCommandResponse objects

Parameter description: list of response parameters of the device command.

Table 7 ServiceCommandResponse

Parameter

Mandatory

Type

Description

response_name

Yes

String

Parameter description: name of the device command response.

Value: The value can contain a maximum of 128 characters. Only letters, digits, and special characters (_?'#().,&%@!-) are allowed.

paras

No

Array of ServiceCommandPara objects

Parameter description: list of response parameters of the device command.

Table 8 ServiceEvent

Parameter

Mandatory

Type

Description

event_type

Yes

String

Parameter description: device event type. The value must be unique in the device service.

Value: The value can contain a maximum of 32 characters. Only letters, digits, and special characters (_?'#().,&%@!-) are allowed.

paras

No

Array of ServiceCommandPara objects

Parameter description: list of device event parameters.

Table 9 ServiceCommandPara

Parameter

Mandatory

Type

Description

para_name

Yes

String

Parameter description: parameter name.

Value: The value can contain a maximum of 32 characters. Only letters, digits, and special characters (_?'#().,&%@!-) are allowed.

data_type

Yes

String

Parameter description: data type of the parameter.

Options: int, long, decimal, string, DateTime, jsonObject, enum, boolean, and string list.

required

No

Boolean

Parameter description: whether the parameter is mandatory. The default value is false.

enum_list

No

Array of strings

Parameter description: list of enumerated values of the parameter.

min

No

String

Parameter description: minimum value of the parameter.

Value length: 1–16 characters

max

No

String

Parameter description: maximum value of the parameter.

Value length: 1–16 characters

max_length

No

Integer

Parameter description: maximum length of the parameter.

step

No

Double

Parameter description: step of the parameter.

unit

No

String

Parameter description: unit of the parameter.

Value length: a maximum of 16 characters

description

No

String

Parameter description: parameter description.

Value: The value can contain a maximum of 128 characters. Only letters, digits, spaces, and special characters (_?'#().,;&%@!-:$![]~/) are allowed.

Response Parameters

Status code: 200

Table 10 Response body parameters

Parameter

Type

Description

app_id

String

Resource space ID.

app_name

String

Resource space name.

product_id

String

Product ID, which uniquely identifies a product. It is allocated by the platform after the product is created on the platform.

name

String

Product name.

device_type

String

Device type.

protocol_type

String

Protocol used by a device. Options: MQTT, CoAP, HTTP, HTTPS, Modbus, ONVIF, OPC-UA, OPC-DA, TCP, ""UDP**, and Other.

data_format

String

Format of the data reported by the device. Options: json and binary.

manufacturer_name

String

Manufacturer name.

industry

String

Industry to which the device belongs.

description

String

Product description.

service_capabilities

Array of ServiceCapability objects

List of service capabilities of the device.

create_time

String

Time when a product was created on the platform. The format is yyyyMMdd'T'HHmmss'Z', for example, 20151212T121212Z.

Table 11 ServiceCapability

Parameter

Type

Description

service_id

String

Parameter description: service ID of the device. The value must be unique in a product.

Value: The value can contain a maximum of 64 characters. Only letters, digits, and special characters (_?'#().,&%@!-$) are allowed.

service_type

String

Parameter description: service type of the device.

Value: The value can contain a maximum of 64 characters. Only letters, digits, and special characters (_?'#().,&%@!-$) are allowed.

properties

Array of ServiceProperty objects

Parameter description: list of properties supported by the device service.

Value: The array length cannot exceed 500.

commands

Array of ServiceCommand objects

Parameter description: list of commands supported by the device service.

Value: The array length cannot exceed 500.

events

Array of ServiceEvent objects

Parameter description: list of events supported by the device service. Currently, event customization is not supported. You do not need to define this field when creating or modifying a product.

Value: The array length cannot exceed 500.

description

String

Parameter description: device service description.

Value: The value can contain a maximum of 128 characters. Only letters, digits, spaces, and special characters (_?'#().,;&%@!-:$![]~/) are allowed.

option

String

Parameter description: whether the device service is mandatory. Currently, this field is not a functional field and is used only for identification.

Options:

  • Master: master service

  • Mandatory: mandatory service

  • Optional: optional service

    The default value is Optional.

Table 12 ServiceProperty

Parameter

Type

Description

property_name

String

Parameter description: device property name. The value must be unique in the device service. If device property names are used as keys in the device shadow JSON file, the names cannot contain periods (.), dollar signs ($), and the null character (hexadecimal ASCII code 00). A device shadow file that contains these special characters cannot be updated.

Value: The value can contain a maximum of 64 characters. Only letters, digits, and special characters (_?'#().,&%@!-) are allowed.

data_type

String

Parameter description: data type of the device property.

Options: int, long, decimal, string, DateTime, jsonObject, enum, boolean, and string list.

required

Boolean

Parameter description: whether the device property is mandatory. The default value is false.

enum_list

Array of strings

Parameter description: list of enumerated values of the device property.

min

String

Parameter description: minimum value of the device property.

Value length: 1–16 characters

max

String

Parameter description: maximum value of the device property.

Value length: 1–16 characters

max_length

Integer

Parameter description: maximum length of the device property.

step

Double

Parameter description: step of the device property.

unit

String

Parameter description: unit of the device property.

Value length: a maximum of 16 characters

method

String

Parameter description: access mode of the device property.

Options: RWE, RW, RE, WE, E, W, and R.

  • R: The property value can be read.

  • W: The property value can be written.

  • E: The property value can be subscribed to, that is, an event is reported when the property value changes.

description

String

Parameter description: device property description.

Value: The value can contain a maximum of 128 characters. Only letters, digits, spaces, and special characters (_?'#().,;&%@!-:$![]~/) are allowed.

default_value

Object

Parameter description: default value of the device property. If the default value is set, it will be written to the desired data of the device shadow when the product is used to create a device. When the device goes online, the default value will be delivered to the device.

Table 13 ServiceCommand

Parameter

Type

Description

command_name

String

Parameter description: device command name. The value must be unique in the device service.

Value: The value can contain a maximum of 64 characters. Only letters, digits, and special characters (_?'#().,&%@!-) are allowed.

paras

Array of ServiceCommandPara objects

Parameter description: list of device command parameters.

responses

Array of ServiceCommandResponse objects

Parameter description: list of response parameters of the device command.

Table 14 ServiceCommandResponse

Parameter

Type

Description

response_name

String

Parameter description: name of the device command response.

Value: The value can contain a maximum of 128 characters. Only letters, digits, and special characters (_?'#().,&%@!-) are allowed.

paras

Array of ServiceCommandPara objects

Parameter description: list of response parameters of the device command.

Table 15 ServiceEvent

Parameter

Type

Description

event_type

String

Parameter description: device event type. The value must be unique in the device service.

Value: The value can contain a maximum of 32 characters. Only letters, digits, and special characters (_?'#().,&%@!-) are allowed.

paras

Array of ServiceCommandPara objects

Parameter description: list of device event parameters.

Table 16 ServiceCommandPara

Parameter

Type

Description

para_name

String

Parameter description: parameter name.

Value: The value can contain a maximum of 32 characters. Only letters, digits, and special characters (_?'#().,&%@!-) are allowed.

data_type

String

Parameter description: data type of the parameter.

Options: int, long, decimal, string, DateTime, jsonObject, enum, boolean, and string list.

required

Boolean

Parameter description: whether the parameter is mandatory. The default value is false.

enum_list

Array of strings

Parameter description: list of enumerated values of the parameter.

min

String

Parameter description: minimum value of the parameter.

Value length: 1–16 characters

max

String

Parameter description: maximum value of the parameter.

Value length: 1–16 characters

max_length

Integer

Parameter description: maximum length of the parameter.

step

Double

Parameter description: step of the parameter.

unit

String

Parameter description: unit of the parameter.

Value length: a maximum of 16 characters

description

String

Parameter description: parameter description.

Value: The value can contain a maximum of 128 characters. Only letters, digits, spaces, and special characters (_?'#().,;&%@!-:$![]~/) are allowed.

Example Requests

Changes the product name to Thermometer and service to temperature.

PUT https://{endpoint}/v5/iot/{project_id}/products/{product_id}

{
  "app_id" : "jeQDJQZltU8iKgFFoW060F5SGZka",
  "name" : "Thermometer.",
  "device_type" : "Thermometer",
  "protocol_type" : "MQTT",
  "data_format" : "json",
  "service_capabilities" : [ {
    "service_id" : "Temperature.",
    "service_type" : "temperature",
    "properties" : [ {
      "property_name" : "temperature",
      "data_type" : "decimal",
      "required" : true,
      "enum_list" : null,
      "min" : "1",
      "max" : "100",
      "max_length" : 100,
      "step" : 0.1,
      "unit" : "centigrade",
      "method" : "RW",
      "description" : "force",
      "default_value" : {
        "color" : "red",
        "size" : 1
      }
    } ],
    "commands" : [ {
      "command_name" : "reboot",
      "paras" : [ {
        "para_name" : "force",
        "data_type" : "string",
        "required" : false,
        "enum_list" : null,
        "min" : "1",
        "max" : "100",
        "max_length" : 100,
        "step" : 0.1,
        "unit" : "km/h",
        "description" : "force"
      } ],
      "responses" : [ {
        "response_name" : "ACK",
        "paras" : [ {
          "para_name" : "force",
          "data_type" : "string",
          "required" : false,
          "enum_list" : null,
          "min" : "1",
          "max" : "100",
          "max_length" : 100,
          "step" : 0.1,
          "unit" : "km/h",
          "description" : "force"
        } ]
      } ]
    } ],
    "events" : [ {
      "event_type" : "reboot",
      "paras" : [ {
        "para_name" : "force",
        "data_type" : "string",
        "required" : false,
        "enum_list" : null,
        "min" : "1",
        "max" : "100",
        "max_length" : 100,
        "step" : 0.1,
        "unit" : "km/h",
        "description" : "force"
      } ]
    } ],
    "description" : "temperature",
    "option" : "Mandatory"
  } ],
  "manufacturer_name" : "ABC",
  "industry" : "smartCity",
  "description" : "this is a thermometer produced by Huawei"
}

Example Responses

Status code: 200

Successful response

{
  "app_id" : "jeQDJQZltU8iKgFFoW060F5SGZka",
  "app_name" : "testAPP01",
  "product_id" : "5ba24f5ebbe8f56f5a14f605",
  "name" : "Thermometer",
  "device_type" : "Thermometer",
  "protocol_type" : "MQTT",
  "data_format" : "json",
  "manufacturer_name" : "ABC",
  "industry" : "smartCity",
  "description" : "this is a thermometer produced by Huawei",
  "service_capabilities" : [ {
    "service_id" : "temperature",
    "service_type" : "temperature",
    "properties" : [ {
      "property_name" : "temperature",
      "required" : true,
      "data_type" : "decimal",
      "enum_list" : null,
      "min" : "1",
      "max" : "100",
      "max_length" : 100,
      "step" : 0.1,
      "unit" : "centigrade",
      "method" : "RW",
      "description" : "force",
      "default_value" : {
        "color" : "red",
        "size" : 1
      }
    } ],
    "commands" : [ {
      "command_name" : "reboot",
      "paras" : [ {
        "para_name" : "force",
        "required" : false,
        "data_type" : "string",
        "enum_list" : null,
        "min" : "1",
        "max" : "100",
        "max_length" : 100,
        "step" : 0.1,
        "unit" : "km/h",
        "description" : "force"
      } ],
      "responses" : [ {
        "response_name" : "ACK",
        "paras" : [ {
          "para_name" : "force",
          "required" : false,
          "data_type" : "string",
          "enum_list" : null,
          "min" : "1",
          "max" : "100",
          "max_length" : 100,
          "step" : 0.1,
          "unit" : "km/h",
          "description" : "force"
        } ]
      } ]
    } ],
    "events" : [ {
      "event_type" : "reboot",
      "paras" : [ {
        "para_name" : "force",
        "required" : false,
        "data_type" : "string",
        "enum_list" : null,
        "min" : "1",
        "max" : "100",
        "max_length" : 100,
        "step" : 0.1,
        "unit" : "km/h",
        "description" : "force"
      } ]
    } ],
    "description" : "temperature",
    "option" : "Mandatory"
  } ],
  "create_time" : "20190303T081011Z"
}

Status Codes

Status Code

Description

200

Successful response

400

Bad Request

401

Unauthorized

403

FORBIDDEN

404

Not Found

500

Internal Server Error

Error Codes

See Error Codes.