Community Tip - New to the community? Learn how to post a question and get help from PTC and industry experts! X
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.
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.
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.
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.
Hi,
This way we are doing it already. But we want to know is there any way to directly send infotable in payload.
One suggestion is to check how it's being sent in the mashup(infotable update). Open the network tab and observe the input params, copy and send same in the rest API too. I believe this should work.
Tried this part. But the json which we are posting through python REST API call is shown as undefined when its receiving at Thingworx platform.
Need some help if anyone has some example codes for this.
Hi @NN_8935737.
Can you try with another client like Postman so we can rule out if the problem is with the Python code or if something is wrong in general?
Regards.
--Sharon