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

PropertyTypeRequiredConstraintsDescription
bundleInstalledstringNoIf present, the name of firmware bundle installed on this device. Only used with the projectId parameter
channelstringNoThe name of firmware channel the device should download from. Only used with the projectId parameter
claimCodestringNoUnique claim code assigned to the device to be added. Required if device is pre-provisioned.
descriptionstringNoDescription of device. Only used with the projectId parameter
deviceClassstringNoOverride the default Device Class associated with the token. Only used for On-Demand Device Provisioning
homeIdintegerNoID of the home to which the device will be added. Required if device is pre-provisioned.
namestringNoDisplay name of device. Only used with the projectId parameter
projectIdintegerNoID 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
tagstringNoAn optional/informational tag associated with device. Can be used to store the serial number, for example. Only used with the projectId parameter
tokenstringNoDevice provisioning token issued for the device to be added. Required for On-Demand Device Provisioning.

Request example

homeId=1885&claimCode=b4d632e16981e66a

Responses

201 Successfully added device to home. Return body is device added with the home ID now specified.

Content type: application/json

PropertyTypeRequiredConstraintsDescription
apiKeystringNoread-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.
bundleInstallTimestringNoread-only (server-generated); format: date-timeIf present, the timestamp when the firmware bundle was installed.
bundleInstalledstringNoread-only (server-generated)If present, the name of firmware bundle installed on this device.
channelstringNoread-only (server-generated)The name of firmware channel the device should download from.
claimCodestringNoClaim code assigned to device. Hidden except to privileged clients.
claimExpirationTimestringNoread-only (server-generated); format: date-timeExpiration time of device's claimable state.
claimTimestringNoread-only (server-generated); format: date-timeTimestamp of device being claimed by a user.
creationTimestringNoread-only (server-generated); format: date-timeTimestamp of device record creation.
descriptionstringNoDescription of device.
deviceClassstringYesread-only (server-generated)Device Class ID as defined by the project.
homeIdintegerNoThis property is present if device belongs to a home.
idintegerYesread-only (server-generated)Unique device ID.
isConnectedbooleanNoread-only (server-generated)Device is currently connected to MODE Cloud via a websocket or MQTT connection.
lastConnectTimestringNoread-only (server-generated); format: date-timeThe last time the device connected to the cloud.
lastDisconnectTimestringNoread-only (server-generated); format: date-timeThe last time the device disconnected from the cloud.
namestringNoDisplay name of device.
projectIdintegerYesread-only (server-generated)Project that this device belongs to.
tagstringNoAn 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

PropertyTypeRequiredConstraintsDescription
dataobjectNoread-only (server-generated)Any relevant data related to error.
reasonstringYesread-only (server-generated)Reason of error.

403 Request failed because of invalid data or denied permission.

Content type: application/json

PropertyTypeRequiredConstraintsDescription
dataobjectNoread-only (server-generated)Any relevant data related to error.
reasonstringYesread-only (server-generated)Reason of error.

429 Request failed because of rate limit.

Content type: application/json

PropertyTypeRequiredConstraintsDescription
dataobjectNoread-only (server-generated)Any relevant data related to error.
reasonstringYesread-only (server-generated)Reason of error.

500 An unexpected error has occurred.

Content type: application/json

PropertyTypeRequiredConstraintsDescription
dataobjectNoread-only (server-generated)Any relevant data related to error.
reasonstringYesread-only (server-generated)Reason of error.

503 The service is temporarily unavailable.

Content type: application/json

PropertyTypeRequiredConstraintsDescription
dataobjectNoread-only (server-generated)Any relevant data related to error.
reasonstringYesread-only (server-generated)Reason of error.