Hi all,
I’m once again pushing my Ignition knowledge limits trying to do HTTP requests via an API for an external website.
I have found the resource on Ignition function system.net.httpGet: https://docs.inductiveautomation.com/display/DOC/system.net.httpGet
And that put me in the right direction, but I’m still not sure how to properly handle the result data.
If the server returns an HTTP error status code, how can i extract that and log the appropriate error message?
My code so far:
[code]
import system
Generate URL for API call to read products
url = “https://inventory.dearsystems.com/ExternalApi/Products?Page=1&Limit=100&Name=Log”
Create header with information required by API
header = {“Content-type”:“application/json”, “api-auth-accountid”:“XXXX-XXXX”, “api-auth-applicationkey:”:“XXXX-XXXX”}
try:
source = system.net.httpGet(url,’’ ,’’ ,’’,’’,header)
print source
except:
print(“Error calling DEAR API”)[/code]
I don’t think i have quite set up the headers correctly, the reference document for the API i’m trying to call is in PHP, and i have no experience in PHP so might be misinterpreting it.
This is the example given to connect to the API: http://support.dearsystems.com/support/solutions/articles/1000054245-connecting-to-the-api
Any help on creating an http request and dealing with the returned data would be much appreciated.