Skip to content

Writing structs through REST API

Hi,

I have a python3 application running where I use REST API to communicate with the RTM. I've got everything working except for writing variables which are a struct variable. Reading variables (including structs) does work, so does writing non-struct variables.

For writing variables i use a POST method:


r = requests.put(url=url, headers=headers, data=json.dumps(payload), verify=False)


 

While I debug and run, the arguments would end up with these values:

url: 'https://192.168.100.125/_pxc_api/api/variables/'

headers: {'Authorization': 'Bearer 64ef2acc6444b9ee'}

data: '{"variables": [{"path": "Arp.Plc.Eclr/test", "value": {"i1": 0, "i2": 33}}]}'

 

The request method will answer with this response:

{'Server': 'nginx', 'Date': 'Thu, 19 Dec 2019 14:14:36 GMT', 'Content-Type': 'application/json', 'Content-Length': '198', 'Connection': 'keep-alive', 'Status': '200 OK', 'Cache-Control': 'no-cache'}

b'{"apiVersion":"1.2.0.0","projectCRC":323846263,"userAuthenticationRequired":true,"variables":[{"path":"Arp.Plc.Eclr/test","value":{"i1":0,"i2":0},"uri":"/_pxc_api/api/variables/Arp.Plc.Eclr/test"}]}'

The response says ok, but the values have not updated

 

The following is the value of the data argument for a non-struct integer variable which does work:

'{"variables": [{"path": "Arp.Plc.Eclr/alive", "value": 33}]}'

 

Is it possible to update struct variables that way?

 

 

 

Comments

  • Hello jannes,
    I think you will have to do something like this.
    Take the Variable link as a PathPrefix and the Path as the Stuct element.<br /><br />

    The thing that comes to my mind is:
    ->how to handle multi layer nested types efficiently?{ "sessionID": "%OptionalSessionID%", "pathPrefix": "Arp.Plc.Eclr/Instance.Program.testStruct", "variables": [ { "path": "i1", "value": "%ConstantValue1%", }, { "path": "i2", "value": "%ConstantValueN%", "valueType": "Constant" } ] }<br /><br />I dont find any hints of key:value pairs for struct in the documentation.


    I will see if we have this planed as a feature at the moment.

    kind regards,
    Oliver

Sign In or Register to comment.