Hello,
Fighting with special characters, maybe someone can shed me some light and help me out.
Trying some APIs to get work orders from an externel software, and all looks good when trying API on Postman.
I expect results to look something like this:
I created a method to retried the same information:
def getWorks(code):
#obter o token
baseUrl = "https://xxx.xxx.xxx/api/"
access_token = manwinwin.helper.getToken(baseUrl)
#obter a lista das ordens de trabalho para o equipamento
filterDict = {"State":['Scheduled','InProgress','NotPerformed'],"Item":code}
filter = system.util.jsonEncode(filterDict)
headerValues = {'Authorization': 'Bearer ' + access_token, "Accept": "application/json; charset=utf-8"}
details = system.net.httpGet(baseUrl + "Works?Filter="+filter,headerValues=headerValues)
print details
detailsJSON = system.util.jsonDecode(details)
return detailsJSON
What I get is:
I tried a few encode and decode but never got a satisfatory result.
Any suggestions?
Thank you.
What version of Ignition are you using?
system.net.httpClient
is faster, more ergonomic, and significantly smarter in every way than the single-purpose httpX
functions.
https://docs.inductiveautomation.com/display/DOC81/system.net.httpClient
Version: 8.1.17 (b2022051210)
I’ll take a look at httpclient.
Would be something like this:
def getWorks(code):
#obter o token
baseUrl = "https://xxx.xxx.xxx/api/"
access_token = manwinwin.helper.getToken(baseUrl)
#obter a lista das ordens de trabalho para o equipamento
filterDict = {"State":['Scheduled','InProgress','NotPerformed'],"Item":code}
headers = {'Authorization': 'Bearer ' + access_token}
client = system.net.httpClient()
params = {"Filter": system.util.jsonEncode(filterDict)}
response = client.get(baseUrl + "Works", params=params, headers=headers)
print response
return response.json
1 Like
PGriffith:
#obter a lista das ordens de trabalho para o equipamento
filterDict = {"State":['Scheduled','InProgress','NotPerformed'],"Item":code}
headers = {'Authorization': 'Bearer ' + access_token}
client = system.net.httpClient()
params = {"Filter": system.util.jsonEncode(filterDict)}
response = client.get(baseUrl + "Works", params=params, headers=headers)
print response
return response.json
Thank you very much. I can now map the result with everything looking perfect.
1 Like