Thingworx Get method

Hi,

How to data read from thingworx IIOT cloud using REQUESTHTTPX (GET method) in ewon flexy.

thanks & regards,
T.udayakumar

@udayakumar

It should be relatively similar to our PUT example located here:
https://developer.ewon.biz/content/make-ewon-compatible-thingworx

I am going to test it on my Flexy with a GET request and will get back with you later today or tomorrow. I’ll be using the ThingWorx API cheat sheet located here:

It looks like you’ll just need to follow their “Get Single Property Value” example, and then parse the JSON data that is returned. I will follow up once I have a solid answer for you.

@ashley_hms

Awaiting your reply.

@udayakumar

I am unable to test with a ThingWorx account, but I have created a script that can lead you in the right direction below. It will be very similar to the PUT example we have on our website linked in my previous reply. I will be using ThingWorx’s API cheatsheet linked previously as well to compose the script example.

Please note, the script below is provided as-is and cannot be guaranteed to work in every specific situation. It is highly recommended to test your GET request in a software like POSTMAN to ensure you’re getting the correct data.

First, compose the REQUESTHTTPX with the tag value you would like to receive.

ThingWorxGetRequest:
appkey$ = "{your ThingWorx app key}"
url$ = "https ://{your ThingWorx host here}/Thingworx/Things/{MyThing}/Properties/" + tagName$ + "?appKey=" + appKey$
$method$ = "GET"
REQUESTHTTPX url$, method$
// Once the response has been received, go to Response
ONSTATUS "goto Response"

Second, parse the response body for your tag value in the Response section.

Response:
b$ = RESPONSEHTTPX "RESPONSE-BODY"
// Find the index where your tag begins
tagBegins% = INSTR 1, b$, tagName$
// Next, find where the value begins by looking for a colon followed by a starting double quote
valueStart% = INSTR tagBegins%, b$, ': "'
// Add 3 to the valueStart index to account for the colon, the space, and the double quotation
valueStart% = valueStart% + 3
// Finally, find where the tag value ends by looking for the closing double quote
valueEnd% = INSTR valueStart%, b$, '"'
// Subtract 1 from valueEnd to remove the ending double quote from your value
valueEnd% = valueEnd% - 1
// Store resulting string value of tag in a new variable
tagValue$ = b$(valueStart% to valueEnd%)

From here, if you’d like to set a tag’s value with the tagValue$ variable, you’ll need to convert it to an integer or float, as demontrated below.

// Convert tagValue$ to an integer
tagValueInt% = FCNV tagValue$,30,0,"%d"

// Convert tagValue$ to a float
tagValueFloat = FCNV tagValue$,20,0,"%f"

To see more on converting strings to different formats, please see page 35 of our Programming Reference Guide.

I hope this serves as a good starting point for performing GET requests using REQUESTHTTPX and RESPONSEHTTPX on your Flexy.