-
Notifications
You must be signed in to change notification settings - Fork 142
How to use
The DeviceHive Server is the central part of the framework which allows different components to interact with each other. The API provides access to information about registered components in the system, and allows them to exchange messages in real time.
DeviceHive Metadata is the information about users, networks of devices, and the specific devices within these networks. This data can be accessed and modified via the REST api.
Represents a user with credentials and API access rights (client or administrator). Administrators automatically have all possible API access rights.
Method | Authorization | Uri |
---|---|---|
list | ManageUser | GET /user |
get | GetCurrentUser | GET /user/{id} |
insert | ManageUser | POST /user |
update | UpdateCurrentUser | PUT /user/{id} |
delete | ManageUser | DELETE /user/{id} |
getCurrent | GetCurrentUser) | GET /user/current |
updateCurrentUser | UpdateCurrentUser | PUT /user/current |
getNetwork | ManageUser | GET /user/{id}/network/{networkId} |
assignNetwork | ManageUser | PUT /user/{id}/network/{networkId} |
unassignNetwork | ManageUser | DELETE /user/{id}/network/{networkId} |
name | value |
---|---|
id | (integer, optional) |
login | (string) |
passwordHash | (string, optional) |
passwordSalt | (string, optional) |
loginAttempts | (integer, optional) |
role | (string, optional) = ['ADMIN', 'CLIENT'] |
status | (string, optional) = ['ACTIVE', 'LOCKED_OUT', 'DISABLED', 'DELETED'] |
lastLogin | (string, optional) |
googleLogin | (string, optional) |
facebookLogin | (string, optional) |
githubLogin | (string, optional) |
data | (JsonStringWrapper, optional) |
admin | (boolean, optional) |
POST /user
Creates new user.
Type | Name | Description | Schema |
---|---|---|---|
Body |
body required |
User body | UserUpdate |
HTTP Code | Description | Schema |
---|---|---|
201 | If successful, this method returns a User resource in the response body. | UserVO |
400 | If request is malformed | No Content |
401 | If request is not authorized | No Content |
403 | If principal doesn't have permissions | No Content |
application/json
application/json
GET /user
Gets list of users.
Type | Name | Description | Schema | Default |
---|---|---|---|---|
Query |
login optional |
Filter by user login. | string | |
Query |
loginPattern optional |
Filter by user login pattern. | string | |
Query |
role optional |
Filter by user role. 0 is Administrator, 1 is Client. | integer (int32) | |
Query |
skip optional |
Number of records to skip from the result list. | integer (int32) | 0 |
Query |
sortField optional |
Result list sort field. | enum (ID, Login) | |
Query |
sortOrder optional |
Result list sort order. Available values are ASC and DESC. | enum (ASC, DESC) | |
Query |
status optional |
Filter by user status. 0 is Active, 1 is Locked Out, 2 is Disabled. | integer (int32) | |
Query |
take optional |
Number of records to take from the result list. | integer (int32) | 20 |
HTTP Code | Description | Schema |
---|---|---|
200 | If successful, this method returns array of User resources in the response body. | < UserVO > array |
400 | If request parameters invalid | No Content |
401 | If request is not authorized | No Content |
403 | If principal doesn't have permissions | No Content |
application/json
application/json
GET /user/current
Get information about the current user.
HTTP Code | Description | Schema |
---|---|---|
200 | If successful, this method returns a User resource in the response body. | UserVO |
401 | If request is not authorized | No Content |
403 | If principal doesn't have permissions | No Content |
409 | If user is not signed in | No Content |
application/json
application/json
PUT /user/current
Updates an existing user. Only administrators are allowed to update any property of any user. User-level accounts can only change their own password in case:
- They already have a password.
- They provide a valid current password in the 'oldPassword' property.
Type | Name | Description | Schema |
---|---|---|---|
Body |
body required |
User body | UserUpdate |
HTTP Code | Description | Schema |
---|---|---|
204 | If successful, this method returns an empty response body. | No Content |
400 | If request is malformed | No Content |
401 | If request is not authorized | No Content |
403 | If principal doesn't have permissions | No Content |
application/json
application/json
GET /user/{id}
Gets information about user and its assigned networks. Only administrators are allowed to get information about any user. User-level accounts can only retrieve information about themselves.
Type | Name | Description | Schema |
---|---|---|---|
Path |
id required |
User identifier. | integer (int64) |
HTTP Code | Description | Schema |
---|---|---|
200 | If successful, this method returns a User resource in the response body. | UserVO |
400 | If request is malformed | No Content |
401 | If request is not authorized | No Content |
403 | If principal doesn't have permissions | No Content |
404 | If user is not found | No Content |
application/json
application/json
PUT /user/{id}
Type | Name | Description | Schema |
---|---|---|---|
Path |
id required |
User identifier. | integer (int64) |
Body |
body required |
User body | UserUpdate |
HTTP Code | Description | Schema |
---|---|---|
404 | If user not found | No Content |
application/json
application/json
DELETE /user/{id}
Deletes an existing user.
Type | Name | Description | Schema |
---|---|---|---|
Path |
id required |
User identifier. | integer (int64) |
HTTP Code | Description | Schema |
---|---|---|
204 | If successful, this method returns an empty response body. | No Content |
401 | If request is not authorized | No Content |
403 | If principal doesn't have permissions | No Content |
404 | If access key is not found | No Content |
application/json
application/json
GET /user/{id}/network/{networkId}
Gets information about user/network association.
Type | Name | Description | Schema |
---|---|---|---|
Path |
id required |
User identifier. | integer (int64) |
Path |
networkId required |
Network identifier. | integer (int64) |
HTTP Code | Description | Schema |
---|---|---|
200 | If successful, this method returns a Network resource in the response body. | NetworkVO |
401 | If request is not authorized | No Content |
403 | If principal doesn't have permissions | No Content |
404 | If user or network not found | No Content |
application/json
application/json
PUT /user/{id}/network/{networkId}
Associates network with the user.
Type | Name | Description | Schema |
---|---|---|---|
Path |
id required |
User identifier. | integer (int64) |
Path |
networkId required |
Network identifier. | integer (int64) |
HTTP Code | Description | Schema |
---|---|---|
204 | If successful, this method returns an empty response body. | No Content |
401 | If request is not authorized | No Content |
403 | If principal doesn't have permissions | No Content |
404 | If user or network not found | No Content |
application/json
application/json
DELETE /user/{id}/network/{networkId}
Removes association between network and user.
Type | Name | Description | Schema |
---|---|---|---|
Path |
id required |
User identifier. | integer (int64) |
Path |
networkId required |
Network identifier. | integer (int64) |
HTTP Code | Description | Schema |
---|---|---|
204 | If successful, this method returns an empty response body. | No Content |
401 | If request is not authorized | No Content |
403 | If principal doesn't have permissions | No Content |
404 | If user or network not found. | No Content |
application/json
application/json
Represents an isolation entity that encapsulates multiple devices with controlled access.
Method | Authorization | Uri |
---|---|---|
list | GetNetwork | GET /network |
get | GetNetwork | GET /network/{id} |
insert | ManageNetwork | POST /network |
update | ManageNetwork | PUT /network/{id} |
delete | ManageNetwork | DELETE /network/{id} |
name | value |
---|---|
id | (integer, optional) |
key | (string, optional) |
name | (string) |
description | (string, optional) |
entityVersion | (integer, optional) |
POST /network
Creates new device network.
Type | Name | Description | Schema |
---|---|---|---|
Body |
body required |
Network body | NetworkVO |
HTTP Code | Description | Schema |
---|---|---|
201 | If successful, this method returns a Network resource in the response body. | NetworkVO |
400 | If request is malformed | No Content |
401 | If request is not authorized | No Content |
403 | If principal doesn't have permissions | No Content |
application/json
GET /network
Gets list of device networks the client has access to.
Type | Name | Description | Schema | Default |
---|---|---|---|---|
Query |
name optional |
Filter by network name. | string | |
Query |
namePattern optional |
Filter by network name pattern. | string | |
Query |
skip optional |
Number of records to skip from the result list. | integer (int32) | 0 |
Query |
sortField optional |
Result list sort field. | enum (ID, Name) | |
Query |
sortOrder optional |
Result list sort order. | enum (ASC, DESC) | |
Query |
take optional |
Number of records to take from the result list. | integer (int32) | 20 |
HTTP Code | Description | Schema |
---|---|---|
200 | If successful, this method returns array of Network resources in the response body. | < NetworkVO > array |
400 | If request parameters invalid | No Content |
401 | If request is not authorized | No Content |
403 | If principal doesn't have permissions | No Content |
application/json
GET /network/{id}
Gets information about device network and its devices.
Type | Name | Description | Schema |
---|---|---|---|
Path |
id required |
Network identifier. | integer (int64) |
HTTP Code | Description | Schema |
---|---|---|
200 | If successful, this method returns a Network resource in the response body. | NetworkVO |
400 | If request is malformed | No Content |
401 | If request is not authorized | No Content |
403 | If principal doesn't have permissions | No Content |
404 | If network not found | No Content |
application/json
PUT /network/{id}
Updates an existing device network.
Type | Name | Description | Schema |
---|---|---|---|
Path |
id required |
Network identifier. | integer (int64) |
Body |
body required |
Network body | NetworkUpdate |
HTTP Code | Description | Schema |
---|---|---|
204 | If successful, this method returns an empty response body. | No Content |
400 | If request is malformed | No Content |
401 | If request is not authorized | No Content |
403 | If principal doesn't have permissions | No Content |
application/json
DELETE /network/{id}
Deletes an existing device network.
Type | Name | Description | Schema |
---|---|---|---|
Path |
id required |
Network identifier. | integer (int64) |
HTTP Code | Description | Schema |
---|---|---|
204 | If successful, this method returns an empty response body. | No Content |
401 | If request is not authorized | No Content |
403 | If principal doesn't have permissions | No Content |
404 | If network not found | No Content |
application/json
Represents a unit that runs microcode.
Method | Authorization | Uri |
---|---|---|
list | GetDevice | GET /device |
get | GetDevice | GET /device/{id} |
register | RegisterDevice | PUT /device/{id} |
delete | RegisterDevice | DELETE /device/{id} |
equipment | GetDeviceState | GET /device/{id}/equipment |
equipmentByCode | GetDeviceState | GET /device/{id}/equipment/{code} |
name | value |
---|---|
id | (integer, optional) |
guid | (string, optional) |
name | (string, optional) |
data | (JsonStringWrapper, optional) |
network | (NetworkVO, optional) |
deviceClass | (DeviceClassVO, optional) |
isBlocked | (boolean, optional) |
GET /device
Gets list of devices.
Type | Name | Description | Schema | Default |
---|---|---|---|---|
Query |
deviceClassId optional |
Filter by associated device class identifier. | integer (int64) | |
Query |
deviceClassName optional |
Filter by associated device class name. | string | |
Query |
name optional |
Filter by device name. | string | |
Query |
namePattern optional |
Filter by device name pattern. | string | |
Query |
networkId optional |
Filter by associated network identifier. | integer (int64) | |
Query |
networkName optional |
Filter by associated network name. | string | |
Query |
skip optional |
Number of records to skip from the result list. | integer (int32) | 0 |
Query |
sortField optional |
Result list sort field. | enum (Name, Status, Network, DeviceClass) | |
Query |
sortOrder optional |
Result list sort order. | enum (ASC, DESC) | |
Query |
take optional |
Number of records to take from the result list. | integer (int32) | 20 |
HTTP Code | Description | Schema |
---|---|---|
200 | If successful, this method returns array of Device resources in the response body. | < DeviceVO > array |
400 | If request parameters invalid | No Content |
401 | If request is not authorized | No Content |
403 | If principal doesn't have permissions | No Content |
application/json
application/json
GET /device/{id}
Gets information about device.
Type | Name | Description | Schema |
---|---|---|---|
Path |
id required |
Device unique identifier. | string |
HTTP Code | Description | Schema |
---|---|---|
200 | If successful, this method returns a Device resource in the response body. | No Content |
400 | If request is malformed | No Content |
401 | If request is not authorized | No Content |
403 | If principal doesn't have permissions | No Content |
404 | If device is not found | No Content |
application/json
application/json
PUT /device/{id}
Registers or updates a device. For initial device registration, only 'name' and 'deviceClass' properties are required.
Type | Name | Description | Schema |
---|---|---|---|
Path |
id required |
Device unique identifier. | string |
Body |
body required |
Device body | DeviceUpdate |
HTTP Code | Description | Schema |
---|---|---|
204 | If successful, this method returns an empty response body. | No Content |
400 | If request is malformed | No Content |
401 | If request is not authorized | No Content |
403 | If principal doesn't have permissions | No Content |
application/json
application/json
DELETE /device/{id}
Deletes an existing device.
Type | Name | Description | Schema |
---|---|---|---|
Path |
id required |
Device unique identifier. | string |
HTTP Code | Description | Schema |
---|---|---|
204 | If successful, this method returns an empty response body. | No Content |
400 | If request is malformed | No Content |
401 | If request is not authorized | No Content |
403 | If principal doesn't have permissions | No Content |
404 | If device is not found | No Content |
application/json
application/json
GET /device/{id}/equipment
Gets current state of device equipment. The equipment state is tracked by framework and it could be updated by sending 'equipment' notification with the following parameters: equipment: equipment code parameters: current equipment state
Type | Name | Description | Schema |
---|---|---|---|
Path |
id required |
Device unique identifier. | string |
HTTP Code | Description | Schema |
---|---|---|
200 | If successful, this method returns an array of DeviceEquipment resources in the response body. | < DeviceEquipmentVO > array |
400 | If request is malformed | No Content |
401 | If request is not authorized | No Content |
403 | If principal doesn't have permissions | No Content |
404 | If device is not found | No Content |
application/json
application/json
GET /device/{id}/equipment/{code}
Gets current state of device equipment by code.
Type | Name | Description | Schema |
---|---|---|---|
Path |
code required |
Equipment code. | string |
Path |
id required |
Device unique identifier. | string |
HTTP Code | Description | Schema |
---|---|---|
200 | If successful, this method returns a DeviceEquipment resource in the response body. | DeviceEquipmentVO |
401 | If request is not authorized | No Content |
403 | If principal doesn't have permissions | No Content |
404 | If device or equipment is not found. | No Content |
application/json
application/json
Represents an entity that holds all meta-information about particular type of devices.
Method | Authorization | Uri |
---|---|---|
list | ManageDeviceClass | GET /device/class |
get | GetDevice | GET /device/class/{id} |
insert | ManageDeviceClass | POST /device/class |
update | ManageDeviceClass | PUT /device/class/{id} |
delete | ManageDeviceClass | DELETE /device/class/{id} |
name | value |
---|---|
id | (integer, optional) |
name | (string) |
isPermanent | (boolean, optional) |
data | (JsonStringWrapper, optional) |
entityVersion | (integer, optional) |
equipment | (Array[DeviceClassEquipmentVO], optional) |
POST /device/class
Creates new device class.
Type | Name | Description | Schema |
---|---|---|---|
Body |
body required |
Device class body | DeviceClassWithEquipmentVO |
HTTP Code | Description | Schema |
---|---|---|
201 | If successful, this method returns a DeviceClass resource in the response body. | DeviceClassWithEquipmentVO |
400 | If request is malformed | No Content |
401 | If request is not authorized | No Content |
403 | If principal doesn't have permissions or device class with same name exists. | No Content |
application/json
application/json
GET /device/class
Gets list of device classes.
Type | Name | Description | Schema | Default |
---|---|---|---|---|
Query |
name optional |
Filter by device class name. | string | |
Query |
namePattern optional |
Filter by device class name pattern. | string | |
Query |
skip optional |
Number of records to skip from the result list. | integer (int32) | 0 |
Query |
sortField optional |
Result list sort field. | enum (ID, Name) | |
Query |
sortOrder optional |
Result list sort order. | enum (ASC, DESC) | |
Query |
take optional |
Number of records to take from the result list. | integer (int32) | 20 |
HTTP Code | Description | Schema |
---|---|---|
200 | If successful, this method returns array of DeviceClass resources in the response body. | < DeviceClassWithEquipmentVO > array |
400 | If request parameters invalid | No Content |
401 | If request is not authorized | No Content |
403 | If principal doesn't have permissions | No Content |
application/json
application/json
POST /device/class/{deviceClassId}/equipment
Creates equipment
Type | Name | Description | Schema |
---|---|---|---|
Path |
deviceClassId required |
Device class {id} | integer (int64) |
Body |
body required |
Equipment body | DeviceClassEquipmentVO |
HTTP Code | Description | Schema |
---|---|---|
201 | Equipment successfully created | DeviceClassEquipmentVO |
400 | Invalid request parameters | No Content |
403 | Duplicate equipment entry with code = {code} for device class with id :{id} | No Content |
404 | Device Class with current id Not Found | No Content |
application/json
GET /device/class/{deviceClassId}/equipment/{id}
Returns equipment by device class id and equipment id
Type | Name | Description | Schema |
---|---|---|---|
Path |
deviceClassId required |
Device class id | integer (int64) |
Path |
id required |
Equipment id | integer (int64) |
HTTP Code | Description | Schema |
---|---|---|
200 | Equipment was found | DeviceClassEquipmentVO |
404 | If equipment not found | No Content |
PUT /device/class/{deviceClassId}/equipment/{id}
Updates equipment. Returns empty body if equipment updated.
Type | Name | Description | Schema |
---|---|---|---|
Path |
deviceClassId required |
Device class id | integer (int64) |
Path |
id required |
Equipment id | integer (int64) |
Body |
body required |
Equipment body | EquipmentUpdate |
HTTP Code | Description | Schema |
---|---|---|
204 | Equipment successfully updated | No Content |
404 | If equipment not found | No Content |
application/json
DELETE /device/class/{deviceClassId}/equipment/{id}
Deletes equipment
Type | Name | Description | Schema |
---|---|---|---|
Path |
deviceClassId required |
Device class id | integer (int64) |
Path |
id required |
Equipment id | integer (int64) |
HTTP Code | Description | Schema |
---|---|---|
204 | Equipment successfully deleted | No Content |
404 | If equipment not found | No Content |
application/json
GET /device/class/{id}
Gets information about device class and its equipment.
Type | Name | Description | Schema |
---|---|---|---|
Path |
id required |
Device class identifier. | integer (int64) |
HTTP Code | Description | Schema |
---|---|---|
200 | If successful, this method returns a DeviceClass resource in the response body. | DeviceClassWithEquipmentVO |
400 | If request is malformed | No Content |
401 | If request is not authorized | No Content |
403 | If principal doesn't have permissions | No Content |
404 | If device class not found | No Content |
application/json
application/json
PUT /device/class/{id}
Updates an existing device class.
Type | Name | Description | Schema |
---|---|---|---|
Path |
id required |
Device class identifier. | integer (int64) |
Body |
body required |
Device class body | DeviceClassUpdate |
HTTP Code | Description | Schema |
---|---|---|
204 | If successful, this method returns an empty response body. | No Content |
400 | If request is malformed | No Content |
401 | If request is not authorized | No Content |
403 | If principal doesn't have permissions | No Content |
404 | If device class is not found | No Content |
application/json
application/json
DELETE /device/class/{id}
Deletes an existing device class.
Type | Name | Description | Schema |
---|---|---|---|
Path |
id required |
Device class identifier. | integer (int64) |
HTTP Code | Description | Schema |
---|---|---|
204 | If successful, this method returns an empty response body. | No Content |
401 | If request is not authorized | No Content |
403 | If principal doesn't have permissions | No Content |
404 | If access key is not found | No Content |
application/json
application/json
Operational data is created in real time and translated between devices and servers. It is required for the proper functioning of the IoT network. Operational data consists of Notifications and Commands.
Notifications are units of information dispatched from devices.
Commands are sent to devices and typically mean some command that is to be executed by the device.
Method | Authorization | Uri | Description |
---|---|---|---|
query | GetDeviceNotification | GET /device/{deviceGuid}/notification | Returns notifications by provided parameters. |
get | GetDeviceNotification | GET /device/{deviceGuid}/notification/{id} | Returns notification by device guid and notification id |
insert | CreateDeviceNotification | POST /device/{deviceGuid}/notification | Creates new device notification. |
poll | GetDeviceNotification | GET /device/{deviceGuid}/notification/poll | Polls new notifications for specific device. This method returns all device notifications that were created after specified timestamp. |
pollMany | GetDeviceNotification | GET /device/notification/poll | Polls new device notifications. This method returns all device notifications that were created after specified timestamp. |
Method | Authorization | Uri | Description |
---|---|---|---|
query | GetDeviceCommand | GET /device/{deviceGuid}/command | Queries device commands. |
get | GetDeviceCommand | GET /device/{deviceGuid}/command/{id} | Gets information about device command. |
insert | CreateDeviceCommand | POST /device/{deviceGuid}/command | Creates new device command. |
update | UpdateDeviceCommand | PUT /device/{deviceGuid}/command/{id} | Updates an existing device command. |
poll | GetDeviceCommand | GET /device/{deviceGuid}/command/poll | Returns all device commands that were created after specified timestamp for specific device. |
wait | GetDeviceCommand | GET /device/{deviceGuid}/command/{id}/poll | Wait for a command to be processed |
pollMany | GetDeviceCommand | GET /device/command/poll | Polls new device commands. |
The service allows devices to exchange messages with the DeviceHive server using a single persistent connection.
After connection is established, devices need to register using the device/save message, perform authentication and then start sending notifications using the notification/insert message.
Devices may also subscribe to commands using the command/subscribe message and then start receiving server-originated messages about new commands.
Message | Originator | Authorization | Description |
---|---|---|---|
authenticate | Device | None | Authenticates a device. After successful authentication, all subsequent messages may exclude deviceId and deviceKey parameters. |
command/subscribe | Device | Device | Subscribes the device to commands. After subscription is completed, the server will start to send command/insert messages to the connected device. |
command/unsubscribe | Device | Device | Unsubscribes the device from commands. |
command/update | Device | Device | Updates an existing device command. |
device/get | Device | Device | Gets information about the current device. |
device/save | Device | Device | Registers or updates a device. |
notification/insert | Device | Device | Creates new device notification. |
server/info | Device | None | Gets meta-information of the current API. |
srv: command/insert | Server | n/a | Notifies the device about new command. |