Skip to main content

API Special Parameters

1. CreateEntity

实体创建API

Input

名称必要类型描述
idtruestring创建实体的id
typetruestring为实体指定type
ownertruestring创建 API 指定owner
sourcetruestring创建 API 指定source
propertiestrueobject创建实体,指定实体的属性。属性满足Key-Value规范。

Output

# core 的 API 返回结构
type Base struct {
ID string
Type string
Owner string
Source string
Version int64
LastTime int64
Mappers []MapperDesc
KValues map[string]constraint.Node
Configs map[string]constraint.Config
}

# Config 是 API 的交互结构
type Config struct {
ID string
Type string
Weight int
Enabled bool
EnabledSearch bool
EnabledTimeSeries bool
Description string
Define map[string]interface{}
LastTime int64
}

Example

创建实体,payload 指定为k-v结构。

Request:

curl -X POST "http://localhost:3500/v1.0/invoke/core/method/v1/entities?id=device123" \
-H "Owner: admin" \
-H "Type: DEVICE" \
-H "Source: dm" \
-H "Content-Type: application/json" \
-d '{
"status": "start",
"temp": 2344,
"object": {
"field1": "value1",
"field2": 123,
"field3": {
"ffff": "vvv"
},
"field4": [
{
"age":21,
"name": "tom"
},
{
"age":22,
"name": "tomas"
}
]
}
}'

Response:

{
"id": "device123",
"source": "dm",
"owner": "admin",
"type": "DEVICE",
"configs": {},
"properties": {
"object": {
"field1": "value1",
"field2": 123,
"field3": {
"ffff": "vvv"
},
"field4": [
{
"age": 21,
"name": "tom"
},
{
"age": 22,
"name": "tomas"
}
]
},
"status": "start",
"temp": 2344
}
}

2. UpdateEntity

实体属性更新API

Input

名称必要类型描述
idtruestring创建实体的id
typetruestring为实体指定type
ownertruestring创建 API 指定owner
sourcetruestring创建 API 指定source
propertiestrueobject创建实体,指定实体的属性。属性满足Key-Value规范。

Output

# core 的 API 返回结构
type Base struct {
ID string
Type string
Owner string
Source string
Version int64
LastTime int64
Mappers []MapperDesc
KValues map[string]constraint.Node
Configs map[string]constraint.Config
}

# Config 是 API 的交互结构
type Config struct {
ID string
Type string
Weight int
Enabled bool
EnabledSearch bool
EnabledTimeSeries bool
Description string
Define map[string]interface{}
LastTime int64
}

Example

创建实体,payload 指定为k-v结构。

Request:

curl -X PUT "http://localhost:3500/v1.0/invoke/core/method/v1/entities/device123" \
-H "Owner: admin" \
-H "Type: DEVICE" \
-H "Source: dm" \
-H "Content-Type: application/json" \
-d '{
"status": "end",
"temp": 123
}'

Response:

{
"id": "device123",
"source": "dm",
"owner": "admin",
"type": "DEVICE",
"configs": {
"temp2": {
"define": {
"max": 500,
"min": 10,
"unit": "°"
},
"description": "",
"enabled": true,
"enabled_search": false,
"enabled_time_series": false,
"id": "temp2",
"last_time": 0,
"type": "int",
"weight": 0
}
},
"properties": {
"object": {
"field1": "value1",
"field2": 123,
"field3": {
"ffff": "vvv"
},
"field4": [
{
"age": 21,
"name": "tom"
},
{
"age": 22,
"name": "tomas"
}
]
},
"status": "start",
"temp": 2344
}
}

3. PatchEntity

实体属性更新API

Input

名称必要类型描述
idtruestring创建实体的id
typetruestring为实体指定type
ownertruestring创建 API 指定owner
sourcetruestring创建 API 指定source
propertiestruearray使用 patch 操作更新实体属性。

Output

# core 的 API 返回结构
type Base struct {
ID string
Type string
Owner string
Source string
Version int64
LastTime int64
Mappers []MapperDesc
KValues map[string]constraint.Node
Configs map[string]constraint.Config
}

# Config 是 API 的交互结构
type Config struct {
ID string
Type string
Weight int
Enabled bool
EnabledSearch bool
EnabledTimeSeries bool
Description string
Define map[string]interface{}
LastTime int64
}

Example

创建实体,payload 指定为k-v结构。

Request:

curl -X PATCH "http://localhost:3500/v1.0/invoke/core/method/v1/entities/device123" \
-H "Source: dm" \
-H "Owner: admin" \
-H "Type: DEVICE" \
-H "Content-Type: application/json" \
-d '[
{
"path": "temp",
"operator": "replace",
"value": 20
}
]'

Response:

{
"id": "device123",
"source": "dm",
"owner": "admin",
"type": "DEVICE",
"configs": {
"temp2": {
"define": {
"max": 500,
"min": 10,
"unit": "°"
},
"description": "",
"enabled": true,
"enabled_search": false,
"enabled_time_series": false,
"id": "temp2",
"last_time": 0,
"type": "int",
"weight": 0
}
},
"properties": {
"object": {
"field1": "value1",
"field2": 123,
"field3": {
"ffff": "vvv"
},
"field4": [
{
"age": 21,
"name": "tom"
},
{
"age": 22,
"name": "tomas"
}
]
},
"status": "end",
"temp": 20
}
}

4. SetConfigs

实体属性更新API

Input

名称必要类型描述
idtruestring创建实体的id
typetruestring为实体指定type
ownertruestring创建 API 指定owner
sourcetruestring创建 API 指定source
configstrueobject实体属性配置信息。

Output

# core 的 API 返回结构
type Base struct {
ID string
Type string
Owner string
Source string
Version int64
LastTime int64
Mappers []MapperDesc
KValues map[string]constraint.Node
Configs map[string]constraint.Config
}

# Config 是 API 的交互结构
type Config struct {
ID string
Type string
Weight int
Enabled bool
EnabledSearch bool
EnabledTimeSeries bool
Description string
Define map[string]interface{}
LastTime int64
}

Example

创建实体,payload 指定为k-v结构。

Request:

curl -X POST "http://localhost:3500/v1.0/invoke/core/method/v1/entities/device123/configs?type=BASIC&owner=admin&source=dm" \
-H "Content-Type: application/json" \
-d '[
{
"id": "metrics",
"type": "struct",
"define": {
"fields": {
"temp": {
"define": {
"max": 500,
"min": 10,
"unit": "°"
},
"description": "",
"enabled": true,
"enabled_search": false,
"enabled_time_series": false,
"id": "temp",
"last_time": 0,
"type": "int",
"weight": 0
}
}
},
"enabled": true,
"enabled_search": true
}
]'





Response:

{
"id": "device123",
"source": "dm",
"owner": "admin",
"type": "DEVICE",
"configs": {
"temp": {
"define": {
"max": 500,
"min": 10,
"unit": "°"
},
"description": "",
"enabled": true,
"enabled_search": false,
"enabled_time_series": false,
"id": "temp",
"last_time": 0,
"type": "int",
"weight": 0
}
},
"properties": {
"object": {
"field1": "value1",
"field2": 123,
"field3": {
"ffff": "vvv"
},
"field4": [
{
"age": 21,
"name": "tom"
},
{
"age": 22,
"name": "tomas"
}
]
},
"status": "end",
"temp": 20
}
}

5. PatchConfigs

Input

名称必要位置类型描述
idtruequery/headerstring创建实体的id
typetruequery/headerstring为实体指定type
ownertruequery/headerstring创建 API 指定owner
sourcetruequery/headerstring创建 API 指定source
configstruebodyobject实体属性配置信息,信息由下文中的output.Config定义,其中ID在request中被忽略,其他字段可选。

Output

# core 的 API 返回结构
type Base struct {
ID string
Type string
Owner string
Source string
Version int64
LastTime int64
Mappers []MapperDesc
KValues map[string]constraint.Node
Configs map[string]constraint.Config
}

# Config 是 API 的交互结构
type Config struct {
ID string
Type string
Weight int
Enabled bool
EnabledSearch bool
EnabledTimeSeries bool
Description string
Define map[string]interface{}
LastTime int64
}

Example

创建实体,payload 指定为k-v结构。

Request:

# append cpu_used
curl -X POST "http://localhost:3500/v1.0/invoke/core/method/v1/entities/device123/configs/patch?type=BASIC&owner=admin&source=dm" \
-H "Content-Type: application/json" \
-d '[{
"path": "cpu_used",
"operator": "replace",
"value": {
"type": "float",
"define": {
"max": 1,
"min": 0,
"ext": {"test":123}
},
"enabled": true,
"enabled_search": true
}
}]'

# remove cpu_used
curl -X POST "http://localhost:3500/v1.0/invoke/core/method/v1/entities/device123/configs/patch?type=BASIC&owner=admin&source=dm" \
-H "Content-Type: application/json" \
-d '[{
"path": "metrics.mem_used",
"operator": "remove"
}]'

# append metrics.mem_used
curl -X POST "http://localhost:3500/v1.0/invoke/core/method/v1/entities/device123/configs/patch?type=BASIC&owner=admin&source=dm" \
-H "Content-Type: application/json" \
-d '[
{
"path": "metrics.mem_used",
"operator": "add",
"value": {
"type": "float",
"define": {
"max": 1,
"min": 0
},
"enabled": true,
"enabled_search": true
}
}]'


# copy metrics.mem_used
curl -X POST "http://localhost:3500/v1.0/invoke/core/method/v1/entities/device123/configs/patch?type=BASIC&owner=admin&source=dm" \
-H "Content-Type: application/json" \
-d '[{
"path": "metrics.mem_used",
"operator": "copy"
}]'

# remove metrics.cpu_used
curl -X POST "http://localhost:3500/v1.0/invoke/core/method/v1/entities/device123/configs/patch?type=BASIC&owner=admin&source=dm" \
-H "Content-Type: application/json" \
-d '[{
"path": "metrics.mem_used",
"operator": "remove"
}]'

# make path if not exists.
curl -X POST "http://localhost:3500/v1.0/invoke/core/method/v1/entities/device123/configs/patch?type=BASIC&owner=admin&source=dm" \
-H "Content-Type: application/json" \
-d '[
{
"path": "metrics.pathnotfound.ttt",
"operator": "add",
"value": {
"type": "float",
"define": {
"max": 1,
"min": 0
},
"enabled": true,
"enabled_search": true
}
}]'

# add root config.
curl -X POST "http://localhost:3500/v1.0/invoke/core/method/v1/entities/device123/configs/patch?type=BASIC&owner=admin&source=dm" \
-H "Content-Type: application/json" \
-d '[
{
"path": "root2.pathnotfound.xxx",
"operator": "add",
"value": {
"type": "float",
"define": {
"max": 1,
"min": 0
},
"enabled": true,
"enabled_search": true
}
}]'


# remove
curl -X POST "http://localhost:3500/v1.0/invoke/core/method/v1/entities/device123/configs/patch?type=BASIC&owner=admin&source=dm" \
-H "Content-Type: application/json" \
-d '[{
"path": "root2.pathnotfound.ttt",
"operator": "remove"
}]'

Response:

{
"id": "device123",
"source": "dm",
"owner": "admin",
"type": "DEVICE",
"configs": {
"metrics": {
"define": {
"fields": {
"mem_used": {
"define": {
"max": 1,
"min": 0
},
"description": "",
"enabled": true,
"enabled_search": false,
"enabled_time_series": false,
"id": "mem_used",
"last_time": 0,
"type": "float",
"weight": 0
},
"pathnotfound": {
"define": {
"fields": {
"ttt": {
"define": {
"max": 1,
"min": 0
},
"description": "",
"enabled": true,
"enabled_search": false,
"enabled_time_series": false,
"id": "ttt",
"last_time": 0,
"type": "float",
"weight": 0
}
}
},
"description": "",
"enabled": true,
"enabled_search": false,
"enabled_time_series": false,
"id": "pathnotfound",
"last_time": 0,
"type": "struct",
"weight": 0
},
"temp": {
"define": {
"max": 500,
"min": 10,
"unit": "°"
},
"description": "",
"enabled": true,
"enabled_search": false,
"enabled_time_series": false,
"id": "temp",
"last_time": 0,
"type": "int",
"weight": 0
}
}
},
"description": "",
"enabled": true,
"enabled_search": false,
"enabled_time_series": false,
"id": "metrics",
"last_time": 0,
"type": "struct",
"weight": 0
},
"root": {
"define": {
"fields": {
"pathnotfound": {
"define": {
"fields": {
"ttt": {
"define": {
"fields": {
"ttt": {
"define": {
"max": 1,
"min": 0
},
"description": "",
"enabled": true,
"enabled_search": false,
"enabled_time_series": false,
"id": "ttt",
"last_time": 0,
"type": "float",
"weight": 0
}
}
},
"description": "",
"enabled": true,
"enabled_search": false,
"enabled_time_series": false,
"id": "ttt",
"last_time": 0,
"type": "struct",
"weight": 0
}
}
},
"description": "",
"enabled": true,
"enabled_search": false,
"enabled_time_series": false,
"id": "pathnotfound",
"last_time": 0,
"type": "struct",
"weight": 0
}
}
},
"description": "",
"enabled": true,
"enabled_search": false,
"enabled_time_series": false,
"id": "root",
"last_time": 0,
"type": "struct",
"weight": 0
},
"root2": {
"define": {
"fields": {
"pathnotfound": {
"define": {
"fields": {}
},
"description": "",
"enabled": true,
"enabled_search": false,
"enabled_time_series": false,
"id": "pathnotfound",
"last_time": 0,
"type": "struct",
"weight": 0
}
}
},
"description": "",
"enabled": true,
"enabled_search": false,
"enabled_time_series": false,
"id": "root2",
"last_time": 0,
"type": "struct",
"weight": 0
}
},
"properties": {
"object": {
"field1": "value1",
"field2": 123,
"field3": {
"ffff": "vvv"
},
"field4": [
{
"age": 21,
"name": "tom"
},
{
"age": 22,
"name": "tomas"
}
]
},
"status": "testing",
"temp": 123
}
}

5. AppendConfigs

实体属性更新API

Input

名称必要类型描述
idtruestring创建实体的id
typetruestring为实体指定type
ownertruestring创建 API 指定owner
sourcetruestring创建 API 指定source
configstrueobject实体属性配置信息。

Output

# core 的 API 返回结构
type Base struct {
ID string
Type string
Owner string
Source string
Version int64
LastTime int64
Mappers []MapperDesc
KValues map[string]constraint.Node
Configs map[string]constraint.Config
}

# Config 是 API 的交互结构
type Config struct {
ID string
Type string
Weight int
Enabled bool
EnabledSearch bool
EnabledTimeSeries bool
Description string
Define map[string]interface{}
LastTime int64
}

Example

创建实体,payload 指定为k-v结构。

Request:

curl -X PUT "http://localhost:3500/v1.0/invoke/core/method/v1/entities/device123/configs?type=BASIC&owner=admin&source=dm" \
-H "Content-Type: application/json" \
-d '[
{
"id": "temp3",
"type": "int",
"define": {
"unit": "°",
"max": 500,
"min": 10
},
"enabled": true,
"enabled_search": true
}
]'

Response:

{
"id": "device123",
"source": "dm",
"owner": "admin",
"type": "DEVICE",
"configs": {
"temp": {
"define": {
"max": 500,
"min": 10,
"unit": "°"
},
"description": "",
"enabled": true,
"enabled_search": false,
"enabled_time_series": false,
"id": "temp",
"last_time": 0,
"type": "int",
"weight": 0
},
"temp3": {
"define": {
"max": 500,
"min": 10,
"unit": "°"
},
"description": "",
"enabled": true,
"enabled_search": false,
"enabled_time_series": false,
"id": "temp3",
"last_time": 0,
"type": "int",
"weight": 0
}
},
"properties": {
"object": {
"field1": "value1",
"field2": 123,
"field3": {
"ffff": "vvv"
},
"field4": [
{
"age": 21,
"name": "tom"
},
{
"age": 22,
"name": "tomas"
}
]
},
"status": "end",
"temp": 20
}
}

6. RemoveConfigs

实体属性更新API

Input

名称必要类型描述
idtruestring创建实体的id
typetruestring为实体指定type
ownertruestring创建 API 指定owner
sourcetruestring创建 API 指定source
property_idstruestring指定需要删除的实体属性id,property_ids=temp,temp2,temp3

Output

# core 的 API 返回结构
type Base struct {
ID string
Type string
Owner string
Source string
Version int64
LastTime int64
Mappers []MapperDesc
KValues map[string]constraint.Node
Configs map[string]constraint.Config
}

# Config 是 API 的交互结构
type Config struct {
ID string
Type string
Weight int
Enabled bool
EnabledSearch bool
EnabledTimeSeries bool
Description string
Define map[string]interface{}
LastTime int64
}

Example

创建实体,payload 指定为k-v结构。

Request:

curl -X DELETE "http://localhost:3500/v1.0/invoke/core/method/v1/entities/device123/configs?type=BASIC&owner=admin&source=dm&property_ids=temp3"  -H "Content-Type: application/json" 

Response:

{
"id": "device123",
"source": "dm",
"owner": "admin",
"type": "DEVICE",
"configs": {
"temp": {
"define": {
"max": 500,
"min": 10,
"unit": "°"
},
"description": "",
"enabled": true,
"enabled_search": false,
"enabled_time_series": false,
"id": "temp",
"last_time": 0,
"type": "int",
"weight": 0
}
},
"properties": {
"object": {
"field1": "value1",
"field2": 123,
"field3": {
"ffff": "vvv"
},
"field4": [
{
"age": 21,
"name": "tom"
},
{
"age": 22,
"name": "tomas"
}
]
},
"status": "end",
"temp": 20
}
}

7. QueryConfigs

实体属性更新API

Input

名称必要类型描述
idtruestring创建实体的id
typetruestring为实体指定type
ownertruestring创建 API 指定owner
sourcetruestring创建 API 指定source
property_idstruestring指定需要删除的实体属性id,支持嵌套,property_ids=temp,temp2,temp3, metrics.temp

Output

# core 的 API 返回结构
type Base struct {
ID string
Type string
Owner string
Source string
Version int64
LastTime int64
Mappers []MapperDesc
KValues map[string]constraint.Node
Configs map[string]constraint.Config
}

# Config 是 API 的交互结构
type Config struct {
ID string
Type string
Weight int
Enabled bool
EnabledSearch bool
EnabledTimeSeries bool
Description string
Define map[string]interface{}
LastTime int64
}

Example

创建实体,payload 指定为k-v结构。

Request:

curl -X GET "http://localhost:3500/v1.0/invoke/core/method/v1/entities/device123/configs?type=BASIC&owner=admin&source=dm&property_ids=temp"  -H "Content-Type: application/json" 

Response:

{
"id": "device123",
"source": "dm",
"owner": "admin",
"type": "DEVICE",
"configs": {
"temp": {
"define": {
"max": 500,
"min": 10,
"unit": "°"
},
"description": "",
"enabled": true,
"enabled_search": false,
"enabled_time_series": false,
"id": "temp",
"last_time": 0,
"type": "int",
"weight": 0
}
},
"properties": {}
}