Skip to main content
1-Visitor
November 27, 2020
Question

REST API calls

  • November 27, 2020
  • 1 reply
  • 2873 views

I'm trying to do a Python rest API call for the Thingworx service 'AddStreamEntry'. But i'm facing issues while passing the infotable in payload.

 

val = {"rows": [{"PropertyName": "NP", "ThingName": "Coffee3", "Date": "2020-11-27T10:00:00"}], "dataShape": {"fieldDefinitions": {"PropertyName": {"name": "PropertyName", "aspects": {}, "description": "", "baseType": "STRING", "ordinal": 0}, "ThingName": {"name": "ThingName", "aspects": {}, "description": "", "baseType": "STRING", "ordinal": 0}, "Date": {"name": "Date", "aspects": {}, "description": "", "baseType": "DATETIME", "ordinal": 0}}}}

url = '*****/services/AddStreamEntryNP'
payload = {
'values': val
}
getreq = requests.post(url,data=payload, headers=headers)
print(getreq)

 

Thingworx Java code :

result = me.AddStreamEntry({
sourceType: 'Python' /* STRING */,
values: values /* INFOTABLE */,
location: loc /* LOCATION */,
source: 'Python' /* STRING */,
tags: undefined /* TAGS */,
timestamp: timestamp /* DATETIME */
});

 

But getting error code 500.

 

Could someone help me with some way.

1 reply

1-Visitor
November 27, 2020

What is the error in logs?

Is location and time_stamp defined properly? Also observed that source, source_type and timestamp are hardcoded, if time_stamp, type and source are same, then it might override the entry in the stream. 

1-Visitor
November 27, 2020

Hi Abhiramk,

 

No specific error. It just says error code 500.

And regarding the hard coded values they were just for testing purpose. code is not inserting/updating..

Just to make sure the error is with infotable value passing have hard-coded these values. 

Need to understand how exactly the structure of infotable(json of infotable) should be passed.

1-Visitor
November 30, 2020

I think better way is to send data in JSON format and parse that on Thingworx side and add it to infotable and store, so the request payload will be light and it also easy to form a json for the person who's making the rest call.