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

Create a Codec Function

Function

Provides the function of creating codec functions.

Debugging

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

URI

POST /v5/iot/{project_id}/product-functions

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.

Request Parameters

Table 2 Request header parameters

Parameter

Mandatory

Type

Description

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.

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. In the returned response header, X-Subject-Token is the desired user token. For details about how to obtain the token, see Token Authentication.

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 specify this parameter to query codec functions in the specified resource space. If this parameter is not carried, codec functions in all resource spaces are queried.

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

product_id

Yes

String

Parameter description: unique ID of the product associated with the device. The value is allocated by the platform after the product is created. For details, see Create a Product.

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

urn

Yes

String

Parameter description: uniform resource name (URN) of the function associated with the product.

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

description

No

String

Parameter description: description of a codec function.

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

Response Parameters

Status code: 201

Table 4 Response body parameters

Parameter

Type

Description

app_id

String

Parameter description: resource space ID. This parameter is optional. If you have multiple resource spaces, you can specify this parameter to query codec functions in the specified resource space. If this parameter is not carried, codec functions in all resource spaces are queried.

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

product_id

String

Parameter description: unique ID of the product associated with the device. The value is allocated by the platform after the product is created. For details, see Create a Product.

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

function_id

String

Parameter description: function ID, which is a unique ID generated after a function is configured for a product.

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

urn

String

Parameter description: uniform resource name (URN) of the function associated with the product.

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

description

String

Parameter description: description of a codec function.

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

create_time

String

Parameter description: time when a product function was created. Format: yyyyMMdd'T'HHmmss'Z', for example, 20151212T121212Z.

Example Requests

Creates a codec function.

POST https://{endpoint}/v5/iot/{project_id}/product-functions

{
  "app_id" : "0ab87ceecbfc49acbcc8d5acdef3c68c",
  "product_id" : "5ba24f5ebbe8f56f5a14f605",
  "urn" : "urn:fss:cn-north-4:46b6f338fc3445b8846c71dfb1fbd9e8:function:java:codecFunc",
  "description" : "xxx"
}

Example Responses

Status code: 201

Created

{
  "app_id" : "0ab87ceecbfc49acbcc8d5acdef3c68c",
  "product_id" : "5ba24f5ebbe8f56f5a14f605",
  "function_id" : "9739d740-4da1-46e1-8075-77145265cd92",
  "urn" : "urn:fss:cn-north-4:46b6f338fc3445b8846c71dfb1fbd9e8:function:java:codecFunc",
  "description" : "xxx",
  "create_time" : "20190303T081011Z"
}

Status Codes

Status Code

Description

201

Created

400

Bad Request

403

Forbidden

404

Not Found

500

Internal Server Error

Error Codes

See Error Codes.