Add device to a home
POST/devices
Base URL: https://api.tinkermode.com
Description
Add a device to a user's home. The complete process depends on how the project was set up and is carried out in one of two possible ways.
Devices are Pre-provisioned
If the project was configured to pre-provision all its devices, adding a device to a home means claiming ownership of an existing device and registering it to the specified home. In this scenario, the device in question must first enable registration before the user calls this API method.
Also, if a user also has permission to create devices in the project, the user can create a new device instance to be registered to a specified home later. In this scenario, the user must make a request with the projectId and deviceClass properties without claimCode.
Devices are Provisioned on Demand
If the project was configured to allow On-Demand Device Provisioning, a user must first initiate the device provisioning process and obtain a provisioning token. The token should be passed to the device hardware which will then call this API method to complete the process. The Device object returned will contain an API key. The device hardware should store the device ID and API key, so that it can begin communicating with the MODE API directly.
Authentication
Send an Authorization header of the form ModeCloud <AUTH_CODE>.
Must contain the key of a user or service account who has create access to the home devices. Required only if device is pre-provisioned.
Request body
Content type: application/x-www-form-urlencoded
| Property | Type | Required | Constraints | Description |
|---|---|---|---|---|
bundleInstalled | string | No | If present, the name of firmware bundle installed on this device. Only used with the projectId parameter | |
channel | string | No | The name of firmware channel the device should download from. Only used with the projectId parameter | |
claimCode | string | No | Unique claim code assigned to the device to be added. Required if device is pre-provisioned. | |
description | string | No | Description of device. Only used with the projectId parameter | |
deviceClass | string | No | Override the default Device Class associated with the token. Only used for On-Demand Device Provisioning | |
homeId | integer | No | ID of the home to which the device will be added. Required if device is pre-provisioned. | |
name | string | No | Display name of device. Only used with the projectId parameter | |
projectId | integer | No | ID of the project to which a new device will be added.
token parameters take precedence over this parameter.
To use this parameter, the request must contain the deviceClass parameters,
and the key of a user with create project devices permission and home devices permission.
Only used for creating a pre-provisioned device instance
| |
tag | string | No | An optional/informational tag associated with device. Can be used to store the serial number, for example. Only used with the projectId parameter | |
token | string | No | Device provisioning token issued for the device to be added. Required for On-Demand Device Provisioning. |
Request example
homeId=1885&claimCode=b4d632e16981e66aResponses
201 Successfully added device to home. Return body is device added with the home ID now specified.
Content type: application/json
| Property | Type | Required | Constraints | Description |
|---|---|---|---|---|
apiKey | string | No | read-only (server-generated) | API access key assigned to device. Usually hidden except to privileged clients, but is also present during the On-Demand Device Provisioning process. |
bundleInstallTime | string | No | read-only (server-generated); format: date-time | If present, the timestamp when the firmware bundle was installed. |
bundleInstalled | string | No | read-only (server-generated) | If present, the name of firmware bundle installed on this device. |
channel | string | No | read-only (server-generated) | The name of firmware channel the device should download from. |
claimCode | string | No | Claim code assigned to device. Hidden except to privileged clients. | |
claimExpirationTime | string | No | read-only (server-generated); format: date-time | Expiration time of device's claimable state. |
claimTime | string | No | read-only (server-generated); format: date-time | Timestamp of device being claimed by a user. |
creationTime | string | No | read-only (server-generated); format: date-time | Timestamp of device record creation. |
description | string | No | Description of device. | |
deviceClass | string | Yes | read-only (server-generated) | Device Class ID as defined by the project. |
homeId | integer | No | This property is present if device belongs to a home. | |
id | integer | Yes | read-only (server-generated) | Unique device ID. |
isConnected | boolean | No | read-only (server-generated) | Device is currently connected to MODE Cloud via a websocket or MQTT connection. |
lastConnectTime | string | No | read-only (server-generated); format: date-time | The last time the device connected to the cloud. |
lastDisconnectTime | string | No | read-only (server-generated); format: date-time | The last time the device disconnected from the cloud. |
name | string | No | Display name of device. | |
projectId | integer | Yes | read-only (server-generated) | Project that this device belongs to. |
tag | string | No | An optional/informational tag associated with device. Can be used to store the serial number, for example. |
Response example
{
"claimExpirationTime": "2019-12-17T22:54:39Z",
"claimTime": "2019-12-17T22:54:39Z",
"deviceClass": "smart_sensor",
"homeId": 1885,
"id": 34328,
"isConnected": false,
"lastConnectTime": "2019-12-17T22:54:03.321Z",
"name": "happy",
"projectId": 1260,
"tag": "0002"
}401 Authorization is required to access this resource.
Content type: application/json
| Property | Type | Required | Constraints | Description |
|---|---|---|---|---|
data | object | No | read-only (server-generated) | Any relevant data related to error. |
reason | string | Yes | read-only (server-generated) | Reason of error. |
403 Request failed because of invalid data or denied permission.
Content type: application/json
| Property | Type | Required | Constraints | Description |
|---|---|---|---|---|
data | object | No | read-only (server-generated) | Any relevant data related to error. |
reason | string | Yes | read-only (server-generated) | Reason of error. |
429 Request failed because of rate limit.
Content type: application/json
| Property | Type | Required | Constraints | Description |
|---|---|---|---|---|
data | object | No | read-only (server-generated) | Any relevant data related to error. |
reason | string | Yes | read-only (server-generated) | Reason of error. |
500 An unexpected error has occurred.
Content type: application/json
| Property | Type | Required | Constraints | Description |
|---|---|---|---|---|
data | object | No | read-only (server-generated) | Any relevant data related to error. |
reason | string | Yes | read-only (server-generated) | Reason of error. |
503 The service is temporarily unavailable.
Content type: application/json
| Property | Type | Required | Constraints | Description |
|---|---|---|---|---|
data | object | No | read-only (server-generated) | Any relevant data related to error. |
reason | string | Yes | read-only (server-generated) | Reason of error. |