Skip to main content
Nov 27, 2020 12:14 PM UTC
Question

REST API calls

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.

7 replies

Nov 27, 2020 12:39 PM UTC

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. 

Nov 27, 2020 4:06 PM UTC

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.

Nov 30, 2020 9:06 AM UTC

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.