Having trouble getting a response from our API using the below code, when i run it on my test platform I am recieving a response. I am not sure if it is the formatting of system.net.httpPost or what I am doing wrong, any help would be appreciated.
system.net.httpPost('https://APIWEBSITE.COM/APIQ$12345',
headerValues={
'XT-UserAgent': 'ABC',
'Authenticate': 'XXXXX-XXX-XXX-XXX-XXX',
'DataFormat': 'JSON',
},
postData={
'table': 'COMPINFO',
'columns': 'COMPID'
})
What doesn’t work? What happens? Is there a response?
Traceback (most recent call last):
File "<input>", line 1, in <module>
IOError: Server returned HTTP response code: 400 for URL: https://API.COM/Q1234
400 means you got a response from the server but it didn’t like something about your request.
You may need to compare a working request to the non-working on in Wireshark or by using a local/dev HTTP proxy tool if you can’t make the request without HTTPS.
I’d also recommend using system.net.httpClient instead if you are on Ignition 8.x. system.net.httpClient - Ignition User Manual 8.1 - Ignition Documentation
Ah, possibly your postData
, in which you are supplying a Python dictionary and not a JSON string. Try encoding it with system.util.jsonEncode
.
Or use httpClient
which will do that for you when supplied a dictionary.
thanks so much I will try that
Thank you Kevin httpClient post worked great no issue 