EdgeHub RESTFul APIs - 2.3.0
Changelog
| Version | Author | Update date | Comment |
|---|---|---|---|
| 2.1.0 | Sa.Jing / Yuping.Hung | 2024/02/29 | First Version |
| 2.2.0 | ITsung.Shen | 2024/03/25 | Organize documentation and add descriptions |
| 2.3.0 | Sa.Jing / Yuping.Hung | 2024/04/19 | Add Chapter 8 & Chapter 9 (for EdgeHub v2.3 or above)Modify 7.1, 7.2 api format (for EdgeHub v2.3 or above) |
1. Introduction
EdgeHub provides a RESTFul API interface that allows users to access the following contents
- User's authentication
- Groups
- Machines (objects)
- Parameters
- Parameter's Realtime or Historical data
- Devices(Gateways)
- Tag's data
2. How to use
2.1 Base URL
Each EdgeHub site can access the EdgeHub RESTFul API URL based on the following pattern
-
https://api-hub-deviceon-bi-{namespace name}-{cluster name}.{hostname} -
Example : https://api-hub-deviceon-bi-master-ensaas.edge365.advantech.com/
You can also access the API documentation using the following pattern
https://api-hub-deviceon-bi-{namespace name}-{cluster name}.{hostname}/apidoc- https://api-hub-deviceon-bi-master-ensaas.edge365.advantech.com/apidoc
2.2 Preliminary
Except for the 3.1 Login API, all other API requests must include the following two headers in the request header
-
Authorization
- SSO token of the logged-in user, which can be obtained from the Login API response.
- Example:
- Authorization: Bearer
-
IFPTenant
- Tenant ID, specifying the tenant to access, so that the relevant resources in the tenant can be obtained, which can be obtained from the Login API response.
- Example:
- IFPTenant: VGVuYW50.ZDzj9ydUUDRc55_w
3. Auth APIs
3.1 Login
-
Route
POST /v2/auth/login -
Request
-
Body
{
"username": "string (required)", // SSO user account in email format
"password": "string (required)", // SSO user's password
"setCookie": "bool (optional)" // true or false, optional, setting it to true will write a cookie to the browser
}
-
-
Response
-
Body
{
"latency": "string", // API query latency in milliseconds
"data": {
"tokenType": "string", // Token type, currently only supports Bearer
"accessToken": "string", // API access token, which needs to be included in the Authorization header of all subsequent requests
"expiresIn": "timestamp", // Token expiry date in Unix timestamp format, the token is valid for 1 hour
"refreshToken": "string", // String in Base64 format, use this key to refresh the token
"user": {
"tenants": [ // Login user's tenant information
{
"id": "string", // Tenant ID, required for requesting data-related APIs, needs to be included in the header
"name": "string" // Tenant name
}
]
}
}
}
-
-
Example
Request body:
{
"username": "sa.jing@advantech.com",
"password": "abcdefg",
"setCookie": true // optional, setting it to true will write a cookie to the browser
}
Response:
{
"latency": "81ms",
"data": {
"tokenType": "Bearer",
"accessToken": "eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJjb3VudHJ5IjoiVFciLCJjcmVhdGlvblRpbWUiOjE2NjczNjY3NDIsImV4cCI6MTY4ODAyNDMwMywiZmlyc3ROYW1lIjoiU2EiLCJpYXQiOjE2ODgwMjA3MDMsImlkIjoiY2I5MmU2M2YtNWE2ZS0xMWVkLTgyNzYtMGE1ODBhZGY0MGNkIiwiaXNzIjoid2lzZS1wYWFzIiwibGFzdE1vZGlmaWVkVGltZSI6MTY2NzM2ODAxOSwibGFzdE5hbWUiOiJKaW5nIiwicmVmcmVzaFRva2VuIjoiOGI2ODQ4OTctMTY0Ny0xMWVlLTg4YmQtMGE1ODBhZGY0MGRiIiwic3RhdHVzIjoiQWN0aXZlIiwidXNlcm5hbWUiOiJzYS5qaW5nQGFkdmFudGVjaC5jb20uY24ifQ.w9wvAPD56nPpOGJKaNyA-R61Wv6DO7k2kQQ4bKojLiXRyq0YoL4AAxyZ_eL5IxCrRtr6Q1ZdGXCRaO5a8mdJSw", // All subsequent requests need to include this token in the Authorization header
"expiresIn": 1688024303, // Token is valid for 1 hour
"refreshToken": "8b684897-1647-11ee-88bd-0a580adf40db", // Used for refreshing the token
"user": {
"tenants": [
{
"id": "VGVuYW50.Y1-NK3QAXhVOdBTZ",
"name": "Root Tenant"
},
{
"id": "VGVuYW50.ZDet-2iqhavNUEAg", // Required for data-related API requests, needs to be included in the header
"name": "satest"
}
]
}
}
}
3.2 Refresh Token
-
Route
POST /v2/auth/refreshToken -
Request
-
Body
{
token: string (required), //string in Base64 format which is got from refreshToken of Login API
}
-
-
Response
-
Body
{
latency: string, // API query latency in milliseconds
data: {
tokenType: string, // Token type, currently only supports Bearer
accessToken: string, // API access token, which needs to be included in the Authorization header of all subsequent requests
expiresIn: timestamp, // Token expiry date in Unix timestamp format, the token is valid for 1 hour
refreshToken: string, // String in Base64 format, use this key to refresh the token
}
}
-
-
Example
Request body:
{
token: 20df5ce0-165e-11ee-88bd-0a580adf40db
}
Response:
{
latency: 9ms,
data: {
tokenType: Bearer,
accessToken: eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJjb3VudHJ5IjoiVFciLCJjcmVhdGlvblRpbWUiOjE2NjczNjY3NDIsImV4cCI6MTY4ODAzNDA1MSwiZmlyc3ROYW1lIjoiU2EiLCJpYXQiOjE2ODgwMzA0NTEsImlkIjoiY2I5MmU2M2YtNWE2ZS0xMWVkLTgyNzYtMGE1ODBhZGY0MGNkIiwiaXNzIjoid2lzZS1wYWFzIiwibGFzdE1vZGlmaWVkVGltZSI6MTY2NzM2ODAxOSwibGFzdE5hbWUiOiJKaW5nIiwicmVmcmVzaFRva2VuIjoiM2RhNmUxZmYtMTY1ZS0xMWVlLTg4YmQtMGE1ODBhZGY0MGRiIiwic3RhdHVzIjoiQWN0aXZlIiwidXNlcm5hbWUiOiJzYS5qaW5nQGFkdmFudGVjaC5jb20uY24ifQ.Jmoooaz01KFPdgJhJYOv763m91JIhFCNkaxZzMmlPg4wHEKRvChu-0IqOcdoUuB0JCvoWqvXGSIdjipFBs8y3A,
expiresIn: 1688034051,
refreshToken: 3da6e1ff-165e-11ee-88bd-0a580adf40db
}
}
3.3 Set my tenant
-
Route
POST /v2/auth/setMyTenant -
Request
-
Body
{
tenantId: string (required), //string of tenant id, get it from login API
}
-
-
Response
Status: 200 OK
-
Example
Request body:
{
tenantId:VGVuYW50.ZCI4Q928Cafk07SD
}
Response:
Status: 200 OK