Community Tip - Need to share some code when posting a question or reply? Make sure to use the "Insert code sample" menu option. Learn more! X
I'm trying to read and update property values using the REST API guide. I'm using Postman to test the following query:
GET [xxxxxx]/Thingworx/Things/HouseThing/Properties
I've specified my ThingWorx login credentials under HTTP Basic Auth parameters in Postman but the API is returning 401 Unauthorized. Am I supposed to have a different set of credentials for this authentication?
***************
Updates:
I did have to create a new user (see the Users link on the left-side of the Composer window). Too bad this isn't mentioned under the REST API tutorial, or the Foundation tutorial, or the Quickstart tutorial. I couldn't see any indication from the API or the instructional documentation about the different types of ThingWorx credentials.
Now I'm having a different issue: when I run this query,
http://34.192.26.37/Thingworx/Things/HouseThing/Properties
I expect to see a list of the same properties that I see when I visit the "Properties" link under the HouseThing Composer view. In fact, I don't see *any* of the HouseThing parameters. The API response is as follows (why doesn't it show the address/temperature/light properties?):
<HTML>
<HEAD>
<TITLE>Property Listing For HouseThing</TITLE>
<LINK rel='Stylesheet' href='/Thingworx/css/thingworxapi.css' type='text/css'></LINK>
<META http-equiv='Content-Type' content='text/html'></META>
<META http-equiv='cache-control' content='no-cache, no-store'></META>
<META http-equiv='expires' content='-1'></META>
<META http-equiv='pragma' content='no-cache, no-store'></META>
<META http-equiv='refresh' content='30'></META>
</HEAD>
<BODY>
<IMG SRC="/Thingworx/images/ThingworxLogo.png"/>
<BR/>
<H1>Property Listing For HouseThing</H1>
<TABLE>
<TR>
<TH>name</TH>
<TH>value</TH>
</TR>
</TABLE>
</BODY>
</HTML>
Solved! Go to Solution.
Do you have necessary permissions set up on the user you are running the call from?
Do you have necessary permissions set up on the user you are running the call from?
This was the issue. I had to go to "Security->Runtime" under HouseThing and add the newly created user. Thanks!
Awesome, thanks for the update!
When putting together REST calls with ThingWorx, the API will assume that data should be returned in HTML format unless you specify a different format using the "Accept" header. For example, you can get the result back in JSON format by adding:
Accept: application/json
To your Postman request. This will return the results in a JSON object. Similar can be done for XML:
Accept: application/xml
Your response above does list the properties on the entity, just in HTML format.
It is a bit strange that you're not receiving any values. Have you configured the properties as persistent and set a value?
Yep, they were configured as persistent and had a value set. The issue was user permissions. I am able to successfully get parameters in both HTML and json format now. Thanks!