Community Tip - Did you get an answer that solved your problem? Please mark it as an Accepted Solution so others with the same problem can find the answer easily. X
Hi,
Is there an example somewhere on how to set property values through the REST API?
In the workbook, I only saw the method of doing a GET request to the URL http://localhost/Thingworx/Things/<Thing>/Properties/<Property>?method=put&value=<value> but that doesn't seem to work with complex types (tables, location,...), or is there a way for that to work
In the Wiki (A.1.3) on the other hand, it says to do a PUT request to http://host/Thingworx/Things/thing_name, but it doesn't give any details.
When I try to do a PUT request to that URL with the properties JSON object I get from GetPropertyValues as the body, I get the error "JSONObject["thingShape"] not found.". Could you provide an example on how to set a property (or all the properties) of a Thing?
Thanks!
Hi Stefan,
To set property values through the REST API, you will indeed use the PUT method. I recommend using the developer included in most (if not all web browsers) to fish out the structure for your URL from the Network traffic. For example, to set the value of a location property, your URL would be as follows:
http://localhost/Thingworx/Things/TestThing/Properties/LocationProperty?method=put&value=34.0,55.0,0.0
Are there particular types of properties you're interested in setting? Also, what is your use case for setting these properties via the REST API rather than in a Service?
Thanks,
Adam
Also remember that in addition to our enhanced REST API, you can use regular calls as well using actual headers etc.
OK, thanks. I've looked at the Network traffic like you said. I see that an asterisk is used: http://localhost/Thingworx/Things/<Thing>/Properties/* and the request body for example. {"geolocation":{"latitude":"0.0","longitude":"0.0","units":"WGS84"}}, and Content-Type & Accept headers set to application/json. With that my question is covered.
For or use case, there are some properties that have to be set remotely (e.g. geolocation, which is determined through geocoding). We could create a Service which assigns its argument to a property and call that service with POST, but being able to set properties directly seemed more flexible.