RESTful API¶
Provides a way to connect the device to the platform via a RESTful API that uses HTTP protocol. The API functionality can be tested at (ทดสอบการทำงานของ API ได้ที่ https://trial-api.netpie.io). There are two groups of API’s that are currently available.
Device API¶
It is an API related to devices. Its domain name is https://api.netpie.io/v2/device. The details are as follows:
1. Publish messages to various topics, can be used in two ways:
Type 1: Topic is specified in the URL path.
EndPoint |
https://api.netpie.io/v2/device/message/{any}/{topic} |
Method |
PUT |
Request Header |
Authorization : Device ClientID:Token |
Request Body |
Content-type : text/plain
| Message to Publish to Topic
|
Return |
|
Example
PUT /device/message/mythings/bedroom/light HTTP/1.1
Host: api.netpie.io/v2/device
Authorization: Device 777d5c96-4c83-4aa6-a273-5ee7c5f453b1:abcduKh8r2tP1zVc1W1nG8YWZeu21234
ON
Type 2: Specify Topic through parameter (Query string)
EndPoint |
https://api.netpie.io/v2/device/message |
Method |
PUT |
Request Header |
Authorization : Device ClientID:Token |
Parameter |
|
Return |
|
Example
PUT /device/message?topic=mything/bedroom/light HTTP/1.1
Host: api.netpie.io/v2/device
Authorization: Device 777d5c96-4c83-4aa6-a273-5ee7c5f453b1:abcduKh8r2tP1zVc1W1nG8YWZeu21234
OFF
Caution
Setting Topic in the REST API is different from that of MQTT protocol. If the message is sent via REST, you need not put “@msg” at the front in the Topic, as the system will autocomplete for you. But, if you are sending a message via MQTT, you still need to add the prefix “@msg” in the Topic.
2. Reading the Shadow Data of the Device (Must be a Device belonging to the same Group)
EndPoint |
https://api.netpie.io/v2/device/shadow/data |
Method |
GET |
Request Header |
Authorization : Device ClientID:Token |
Parameter |
|
Return |
|
Example
GET /device/shadow/data?alias=sensor HTTP/1.1
Host: api.netpie.io/v2/device
Authorization: Device 777d5c96-4c83-4aa6-a273-5ee7c5f453b1:abcduKh8r2tP1zVc1W1nG8YWZeu21234
3. Writing Data to Shadow Data as Merge
EndPoint |
https://api.netpie.io/v2/device/shadow/data |
Method |
PUT |
Request Header |
Authorization : Device ClientID:Token |
Parameter |
|
Request Body |
The data that you want to write to the Shadow Data will be in json format as follows:
|
Return |
|
Example
PUT /device/shadow/data?alias=test HTTP/1.1
Host: api.netpie.io/v2/device
Authorization: Device 777d5c96-4c83-4aa6-a273-5ee7c5f453b1:abcduKh8r2tP1zVc1W1nG8YWZeu21234
{
"data": {
"temperature": 33.7,
"config": {"item1": "a", "item2": "b"},
"note": "test case"
}
}
4. Writing Data to Shadow Data as to Overwrite (Overwrite)
EndPoint |
https://api.netpie.io/v2/device/shadow/data |
Method |
POST |
Request Header |
Authorization : Device ClientID:Token |
Parameter |
|
Request Body |
The data that you want to write to Shadow Data will be in JSON format as follows:
|
Return |
|
Example
POST /device/shadow/data?alias=test HTTP/1.1
Host: api.netpie.io/v2/device
Authorization: Device 777d5c96-4c83-4aa6-a273-5ee7c5f453b1:abcduKh8r2tP1zVc1W1nG8YWZeu21234
{
"data": {
"temperature": 33.7,
"config": {"item1": "a", "item2": "b"},
"note": "test case"
}
}
Data Store API¶
It is an API used to retrieve data stored in the Time-Series database. The API’s domain name is https://ds.netpie.io/feed. The database used is KairosDB. The parameters will be sent in the same format as KairosDB
EndPoint |
https://ds.netpie.io/feed/api/v1/datapoints/query |
Method |
POST |
Request Header |
Authorization : Bearer UserToken or Device ClientID:DeviceToken, Content-Type : |
Request Body |
The terms used in the query are JSON format and can be classified into two types:
|
Return |
|