Ignition API Keys

I am currently experimenting with Ignition 8.3’s new API Key feature. However I cant seem to get the authentication right. I am currently trying to follow this post here:

But I am sort of reverse engineering it to write a script using httpClienth.get() to grab the information. Is there something I am missing or doing wrong?

Here is the script I am using:
client = system.net.httpClient() url = 'http://localhost:8070/app/platform/security/api-keys'

headers = { 'Authorization': 'Reader: TOKEN HERE ', 'Content-Type': 'application/json' }

response = client.get(url, headers=headers) print(response) #print(response.text)

client = system.net.httpClient() url = 'http://localhost:8070/data/api/v1/resources/names/com.inductiveautomation.opcua/device'

headers = { 'Authorization': 'Reader: TOKEN HERE', 'Content-Type': 'application/json' }

response = client.get(url, headers=headers) print(response) #print(response.text)

I forgot to add, here is the response I get from both:

image

Try this:

url = 'http://localhost:8070/data/api/v1/resources/names/com.inductiveautomation.opcua/device'

headers = { 
	'X-Ignition-API-Token': 'TOKEN HERE',
}

response = system.net.httpClient.get(url, headers=headers)
print(response.json)

I get the same response 401. It also seems that the .json at the end of response is not liked by the script console.

Here is the code I have:

url = 'http://localhost:8070/data/api/v1/resources/names/com.inductiveautomation.opcua/device'

headers = {
'X-Ignition-API-Token': 'Reader:TOKEN HERE',
}

response = system.net.httpClient.get(url, headers=headers)
print(response)

Something's wrong with your API key or the way you're providing it - have you given it a security level that has gateway read access?

The same script works fine for me:

url = 'http://localhost:8088/data/api/v1/resources/names/com.inductiveautomation.opcua/device'

headers = { 
	'X-Ignition-API-Token': 'API:KZFH8OAhqIInsGeFku7xw9eyJE2N940B_EbxtDHd1Vc',
}

response = system.net.httpClient.get(url, headers=headers)
print(response.json['items'])

The 'unable to parse response body as JSON' is because of the 401 error - we return a plain text error that's not valid JSON.

1 Like

Here is the Security General Settings I have set up:

And here is the API Keys setting:

You have 'require secure connections' set but you're using an HTTP URL.

2 Likes

It worked!!! Thank You!!!

2 Likes