[Solved] Post new Gateway or Peripheral devices with Losant API node


I need to be able to create/delete/manage devices through Experience Endpoint Triggers. I am using the Losant API node to perform the actual work in the associated workflow. Is there a way to create Gateway and/or Peripheral devices directly via Losant API? Using the Devices: Post resource, it appears that device type defaults to Standalone. Alternatively, is there a way to create a device according to a preexisting recipe via Losant API or alternative mechanism?



You can create Gateway or Peripheral devices directly through the Losant API - you just need to set the deviceClass property to the type that you want (you can see more detail about that in the device post schema). You can use the Losant API node to do this as well, following that same schema.

We do have plans for a friendly device creation and update nodes (similar to the device(s) get node that already exists), since creating or updating devices on the fly is a pretty common action.

As far as creating a device from a recipe, there is the bulk device creation endpoint which you can use, but that is probably a bit heavy for your use case. We do not have a simple endpoint for just creating a single device from a recipe (which is a good idea, and I’ll add it to our ticket system).

1 Like


Thanks for the response. I see how to declare deviceClass, but do not see how to associate a new peripheral device with a gateway device.



You’ll need to pass a “gatewayId” parameter on the peripheral device. That ID should be the ID of the device you want to serve as that peripheral’s gateway – and the class of that device should be “gateway”.



In the Losant API node where the peripheral device is being created, the parameter block looks like this now.

“name”: “{{ data.body.deviceName }}”,
“tags”: [
{ “key”: “deviceType”,
“value”: “{{data.body.deviceType }}” },
{ “key”: “owner”,
“value”: “{{ experience.user.id }}” },
{ “key”: “manufacturerId”,
“value”: “{{ data.body.manufacturerId }}” }
“attributes”: [
{ “name”: “level”,
“dataType”: “number” }
“deviceClass”: “peripheral”,
“gatewayId”: “{{ data.body.gatewayId }}”

data.body.gateWayId is being populated corrected with the deviceId of the gateway device, but I get this error in the payload in newDevice.error.

“message”:"device.gatewayId pattern mismatch

Am I doing something wrong?



It looks like you’re passing the property through the API node under the key “gatewayID”; in fact, it should be “gatewayId”. Note the difference in capitalization.

If that doesn’t fix it, can you connect a debug node at the end of the workflow and paste its contents here? That will help us track down what’s going on.



I actually had called gatewayId originally. I changed it back to that and the same problem still exists. Here is the debug. Thanks.

“time”: “2017-05-05T22:01:53.565Z”,
“data”: {
“path”: “/devices”,
“params”: {},
“method”: “post”,
“headers”: {
“content-type”: “application/json”,
“content-lenth”: “116”,
“authorization”: “REDACTED”,
“connection”: “close”,
“transfer-encoding”: “chunked”,
“x-forwarded-proto”: “http”,
“x-forwarded-for”: “”
“query”: {},
“body”: {
“deviceType”: “Area”,
“deviceName”: “Kitchen”,
“manufacturerId”: “PMMI 00000001”,
“gateWayId”: “590cf64cc8f13000014788ff”
“cookies”: {},
“replyId”: “59078383b420670001553ba8.Syf4mVRAl.S1qILucyWE”,
“newDevice”: {
“error”: {
“statusCode”: 400,
“type”: “Validation”,
“message”: “device.gatewayId pattern mismatch”
“accessKey”: {
“error”: {
“statusCode”: 400,
“type”: “Validation”,
“message”: “applicationKey.deviceIds.0 pattern mismatch”
“applicationId”: “58f8fd024d33880001a45b0d”,
“triggerId”: “59078383b420670001553ba8”,
“triggerType”: “endpoint”,
“experience”: {
“endpoint”: {
“method”: “post”,
“enabled”: true,
“access”: “authenticated”,
“route”: “/devices”,
“description”: “Registers a new device and links it to an authenticated user”,
“applicationId”: “58f8fd024d33880001a45b0d”,
“creationDate”: “2017-05-01T18:50:43.656Z”,
“lastUpdated”: “2017-05-01T18:50:43.714Z”,
“experienceEndpointId”: “59078383b420670001553ba8”,
“id”: “59078383b420670001553ba8”,
“experienceGroups”: []
“user”: {
“email”: "my.awsome.user@example.com",
“userTags”: {},
“applicationId”: “58f8fd024d33880001a45b0d”,
“creationDate”: “2017-04-28T21:18:44.914Z”,
“lastUpdated”: “2017-05-01T18:30:09.915Z”,
“passwordLastUpdated”: “2017-04-28T21:18:44.915Z”,
“lastLogin”: “2017-05-01T18:30:09.906Z”,
“experienceUserId”: “5903b1b43265360001666df3”,
“avatarUrl”: “https://secure.gravatar.com/avatar/527b54db1085e9866e69a951690d3c3d?d=retro&s=240”,
“id”: “5903b1b43265360001666df3”,
“experienceGroups”: []
“relayId”: “5903b1b43265360001666df3”,
“relayType”: “experienceUser”,
“flowId”: “5907846aeef63b00015f9f12”,
“flowName”: “endpoint - POST /devices”,
“applicationName”: “PMMI Lighting”,
“globals”: {}



I see the issue -

In your payload, per your debug output, your device gateway is under gateWayId. When you reference it in the device creation, you’re looking for the value at data.body.gatewayId. It’s another capitalization issue.

So, you should either change the key in your request body to gatewayId, or you should, when creating your peripheral, change the gatewayId to reference data.body.gateWayId.



Thank you! That did it.