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
I have been trying to send data to ThingWorx. To start I had created a Thing and a property to send a value to. I have a web application called www.markcheli.com/dummyPhonedata and am trying to send values from the Javascript in there to Thingworx.
I tried the following command:
$.ajax({
url: 'http://acadev1.cloud.thingworx.com/Thingworx/Things/Am2302Thing/Properties/Prop_Temperature/',
type: 'PUT',
data: 'value=1'
})
Using AJAX I am just trying to send Dummy data to the property "Prop_Temperature". On my phone this website
asks for permission to Thingworx using a login- after logging in the data does not send so the endpoint is never reached.
If I post to http://acadev1.cloud.thingworx.com/Thingworx/Things/Am2302Thing/Properties/Prop_Temperature ?method=put&value=4 it will send the value of
4 to the Thing property of Prop_Temperature.
Additionally, If I do not use the safari web browser on my phone it does not request permission to ThingWorx,thus it cannot even try to put this data on the website.
I tried using request to get access to ThingWorx:
Where 54.164.99.104 is the IP address of ThingWorx, AM2302Thing is our thing, and 8d2d147f-09cd-4df9-bb5e-d749060ce787 is our API key
Is there a different Rest call that will allow access to ThingWorx and send the value to a given property?
Also is there a problem with my PUT request that is not allowing to send the data to a given property?
h3. Hi DeAnna,
Also make sure that the Thing you created on Thingworx has a GenericThing Template and not a RemoteThing one because this will make the properties read-only and won't allow you to set properties to them through Rest Calls only through the EMS methods.
Hi Veronica:
I am trying to use URL http://localhost:8080/Thingworx/Things/TestDHTThing2/Properties/Temperature?appKey=2d8ae62b-4690-4078-98cc-b6db69c135ff&x-thingworx-session=true&method=put&value=22 in chrome browser to set thing's properties. It does not work, is it forbidden in Thingworx 6.0.1 ? The thing is based on GenericThing template and properties are not read-only.
Hi,
Yes, calling rest calls in the browser search bar has been disabled starting with ThingWorx 6.0. You can enable them by following these steps :
1. Click on Subsystems under SYSTEM within the left pane of Composer
2. Click on PlatformSubsystem
3. Click on Configuration
4. Check the box next to Allow Request Method Switch to allow all REST API calls through a browser URL
5. Uncheck Filter Content-Type
Starting with ThingWorx 6.0 is recommended that you use an HTTP request web plugin like POSTMAN to test the rest calls.
Let me know if this fixes the issue.
Thank you,
Veronica
Hi,
I want to know whether it is possible to pass multiple parameters in a URL. For eg: I have thing with 3 properties and i wanted to pass this properties in the URL and update it. How it is possible? Can anyone help me out?
Hi Supriya V,
All Things have a SetPropertyValues service which allows you to set multiple properties at once. This service needs an infotable as inputThis is how the rest call for this service would look like for a Thing that has these properties: Temperature, Humidity, Luminosity and Location
http://yourThingWorx.cloud.thingworx.com/Thingworx/Things/YourThingName/Services/SetPropertyValues?method=post&appKey=yourAppKey&values={"dataShape":{"fieldDefinitions":{"Temperature":{"name":"Temperature","baseType":"NUMBER"},"Humidity":{"name":"Humidity","baseType":"NUMBER"},"Luminosity":{"name":"Luminosity","baseType":"NUMBER"},"Location":{"name":"Location","baseType":"LOCATION"}}},"rows":[{"Temperature":1.0,"Humidity":2.0,"Luminosity":3.0,"Location":{"latitude":4.0,"longitude":5.0,"elevation":0.0}}]}
You need to change what is in bold to make it work on your ThingWorx instance.
Note that the values for the properties are given in the rows array.
Please let me know if you need help in adjusting this rest call to fit your needs.
You can also create your own customized service that will set the properties that you want. Check out the tutorial for Weather app with Arduino Uno that uses this approach.
Best regards,
Veronica
Hi Veronica,
Thankyou for your help.
I tried doing so, But i got an error "Unable To Convert From java.lang.String to INFOTABLE" .What should I do ?
When this is done will this be affected in the property list of the thing?
What I have to do is,pass the values of the properties through the URL for the project that we are doing.When this is fired, It should get updated in the mashup and the property list of the thing in the composer.
Regards,
Supriya
Hi Supriya,
The properties need to already exist on your Thing and have the same type (Number, Location etc) as the one that you declared in the infotable of your Rest call. This SetPropertyValues service purpose is only to update your property values, it won't create properties for your Thing.
Best regards,
Veronica
Hello @vmihai ,
I am trying the same thing and it doesn't work. There is no error returned, I get a 200 HTTP OK but the value doesn't change. I have tried with Remote as well as Generic thing, both gave me same results. Could you please help?
Also, the tuturial link is no longer valid, could you please provide a latest link if there is one.
Has it changed with Thingworx version 8.5.5?
Below is my request:
curl --location --request POST 'https://<HostName>/Thingworx/Things/<GenericThingName>/Services/SetPropertyValues' \
--header 'appkey: <AppKey>' \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--data-raw '{
"dataShape": {
"fieldDefinitions": {
"TestProp1": {
"name": "TestProp1",
"description": "",
"baseType": "STRING"
}
}
},
"rows": [
{
"TestProp1": "TestValue123"
}
]
}'