Creating a device with specific properties- through API

I am using the below API to create a device under certain device_Type

https://ubidots.com/docs/sw/#operation/Create%20Datasource

However I am unable to realize the proper syntax to assign values to device properties that are defined in the device_Type.

below is the payload I am using while creating the device through above API, where “deviceroom” is one of the property I wish to set.

{
"enabled": true,
"parent": {
"name": "string"
},
"name": "device7",
"context": {

"deviceroom": "room-1",
}
}

Bumping up the post. I dont necessarily need an answer from Mods/experts but if you have a clue of how above is done please let us know.

@Team, appreciate your inputs ASAP though, as we need to deliver this solution to the client for a COVID related urgency.

Hi there, device types have fixed properties and you cannot dinamycally assign new properties to them. The way to add new properties to a device is to use a PATCH request, please find below the structure to do that using a curl command:

curl 'https://industrial.api.ubidots.com/api/v1.6/datasources/<DEVICE_ID> \
  -X 'PATCH' \
  -H 'X-Auth-Token: <ACCOUNT_TOKEN>' \
  -H 'Content-Type: application/json' \
  --data-binary '{"context":{"<PROPERTY-1>":<VALUE>,"<PROPERTY-2>":<VALUE>,"_device_type":"<DEVICE_TYPE_LABEL>", "_config":{"<PROPERTY-1>":{"text":"<PROPERTY-1-NAME>","type":"number","description":""},"<PROPERTY-2>":{"text":"<PROPERTY-2-NAME"","type":"number"}}}}' 

You will need to set the property type inside the _config key, properties may be number, text, list, bool or date type.

All the best

Hey,
I’d really like to implement this. Need to assign a text property to a device via http interface on my iot device.
I can create the property name on the Ubidots side, but need to populate it from the device.
Have http interface on iot device (Telit LE910) but doesn’t look like PATCH is supported (just POST, PUT, GET, HEAD, DELETE.
An alternative would be a variable that can populated with a text string. So far can’t see a way to do either.
Cheers
Rob

Tried using curl, and got a reply from industrial.ubidots.com that PATCH is forbidden on the server. Only GET, POST, HEAD, OPTIONS are permitted. Is there an alternative?

It seems like this should work as per API doc here…
https://docs.ubidots.com/reference#update-device
However, it refers to v2.0 API rather than v1.6. Trying the PATCH on v1.6 API result in a permission denied error. v2.0 API is just 404 not found.
Bump please? Any ideas?
Regards
Rob

Hi @robby,

With respect to the below message, it makes sense you got the that response through industrial.ubidots.com because the official API domain is actually industrial.api.ubidots.com. For any API interaction, please use the later domain, regardless if you’re using v1.6 or v2.0.

Now, you can use either API v1.6 or v2.0 to PATCH your device’s properties. In order to better help you, can you please share with me the cURL command you’re using with v2.0 so I can determine what’s wrong and the reason behind the 404 Not Found error response code?
Furthermore, since you’re using this version, I recommend reading this section to understand the different operations modes of the API v2.0.
In a nutshell, you’ll see that must of the endpoints receive a <key> as the entity identifier. This <key> can be either the entity ID or its label, however, when using labels you’ll need to prefix it with the tilde (“~”) character so the API knows you’re querying it with labels instead of IDs. For example, say you’re Device label is “demo”, in the URL you need to enter it as “~need”.

Best,

–David