cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Did you get called away in the middle of writing a post? Don't worry you can find your unfinished post later in the Drafts section of your profile page. X

REST API Authentication problem on Thingworx 8

mberber
12-Amethyst

REST API Authentication problem on Thingworx 8

Hello eveyone;

I recently discovered that in ThingWorx 8 , adding appKey to url for authentication has ben removed for security reasons.

I cant find working HTTP Requests examples which includes necessary headers with proper syntax.

I am using NodeMCU with MicroPython Flash. I can successfully make HTTP requests to any REST testing site. eg. https://httpbin.org/.

I also test my Url in Postman. which it also work properly.

http://<server>/Thingworx/Things/NodemcuTest/Properties/input


Here is my code.


Note : I use urequests library as requests.


url = 'http://<server>/Thingworx/Things/NodemcuTest/Properties/input' 

headers = {'appkey': 'xxxx-xxxx-xxx-xxxx-xxxx-xxx'

          'Accept': 'application/json'}

getreq = requests.get(url, headers=headers).json()

s = getreq["rows"][0]["cont"]

print(s)

I hope i made myself clear about the issue.

Thank you.

Murat Can

7 REPLIES 7
jamesb
5-Regular Member
(To:mberber)

Hi Murat,

The application key can be passed in as an http header called "appKey" (caplital K).

Hopefully that helps!

~James

mberber
12-Amethyst
(To:mberber)

Hi James;

I switch to using Arduino IDE to programming nodeMCU and it worked...only works on my local Thingworx Installition.

http://<host>/Thingworx/Things/testThing/Properties/testProp?method=PUT&appKey=<appkey>&value=1

This syntax must be true -it works on my local Thingworx 8.0.2- but its not working on neither Postman nor our servers which installed Thingworx 8.0.2 and 7.4.

jamesb
5-Regular Member
(To:mberber)

Hi Murat,

From a security standpoint, its preferable to use http headers over URL parameters.  For example

Post to http://localhost:8080/Thingworx/Things/JamesTestThing/Services/HelloWorld

Headers:

Content-Type: application/json

Accept: Application/json

appKey: <someAppKeyAsAVeryLongString>

This returns a result for me

{

    "dataShape": {

        "fieldDefinitions": {

            "result": {

                "name": "result",

                "description": "",

                "baseType": "STRING",

                "ordinal": 0,

                "aspects": {}

            }

        }

    },

    "rows": [

        {

            "result": "Hello World"

        }

    ]

}

Hi,

I tried your suggestions and is making a GET call to a thing property from Postman. 

I have tried sending the appKey in url and it gave me a 404 not found error.

Next, i tried sending it as Header and still I am getting a 404. please see the screen shot attached. Any help would be appreciated.

 

Thanks

Do you have this myhouse thing for which you are fetching watts property. 

This is with reference to the article
https://www.ptc.com/en/support/article?n=CS264349

https://community.thingworx.com/thread/43129

Will the appkey param also supported in the Request header in the 7-4-15 ThingWorx version ?

Announcements


Top Tags