Skip to main content
12-Amethyst
December 18, 2017
Question

REST API Authentication problem on Thingworx 8

  • December 18, 2017
  • 2 replies
  • 7718 views

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

2 replies

5-Regular Member
December 18, 2017

Hi Murat,

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

Hopefully that helps!

~James

mberber12-AmethystAuthor
12-Amethyst
December 20, 2017

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.

5-Regular Member
December 21, 2017

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"

        }

    ]

}

1-Visitor
March 9, 2018

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