system.net.httpGet error

Hi,
I am trying to run some GET API requests. but it gave me errors `IOError: Server returned HTTP response code: 401 for URL: https://api2.kaiza.la//v1/accessToken which related to authentication.
The original code run well in POSTMAN tools but when I converted the code to be matched with ignition it’s not working

PostMan code:

import requests

url = "https://api2.kaiza.la//v1/accessToken"

payload = {}
headers = {
  'applicationId': 'f8cd93db-8e94-4c4@2',
  'applicationSecret': '7T3OY',
  'refreshToken': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.ld5SH_Xgyq2C4fyKgGLKcal7RYzgY20VG6Y3t2mIZtU'
}
response = requests.request("GET", url, headers=headers, data = payload)
print(response.text.encode('utf8'))

My Code in ignition

import system

url = "https://api2.kaiza.la//v1/accessToken"

payload = {}
headers = {
  'applicationId': 'f8cd93db-8e94-4c4@2',
  'applicationSecret': '7T3OY',
  'refreshToken': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.ld5SH_Xgyq2C4fyKgGLKcal7RYzgY20VG6Y3t2mIZtU'
     }
response = system.net.httpGet(url,headers=headers, data = payload)
print response
print(response.text.encode('utf8'))

I don’t know if it will solve the problem, but look into using system.net.httpClient if you’re at 8.0.6 or later. @PGriffith has articulated the benefits in various places throughout the forum.

2 Likes

I’ll second @zacht’s recommendation, but, even outside of that:
Are you sure you’ve got the structure of those headers correct? Most REST/web APIs use the standard Authentication header, with a structure like Authentication: Bearer ${token} or Authentication: token ${token} - while it’s certainly possible the service is using a non-standard header like refreshToken, it seems more likely that it’s either expecting that as a URL parameter, or embedded inside an Authentication header.

1 Like

Thanks @zacht & @PGriffith
it’s work fine :pray:with system.net.httpClient()

1 Like