03-25-2024 01:45 AM
Hello,
I was exploring the API functionallity of the Extreme Management Center through the built in nbi explorer, since we are migrating to the newer XIQ Site Engine it would be useful to be able to transfer data between them.
I did create a simple python script just to verify basic access to the API.
I am getting the access token from the ems, but when trying to post the query to the /nbi/graphql endpoint, i am getting a 401 Unauthorized back. I even tried including the same credentials as i used for aquiring the initial access_token, but no luck there either.
The query in question:
query {network {devices { up ip sysName siteData { siteId siteName location }}}}
Solved! Go to Solution.
03-26-2024 08:10 AM
I still not get, why you not use the existing Python class.
However, you added a equal sign where no equal sign should be
03-25-2024 06:04 AM
just to answer your question. The token you got during login have to be used like this for all the GraphQL queries until the token expired.
03-25-2024 05:42 AM
on GitHub is a Python class available offload all the pain of fiddling with the API detail.
ExtremeScripting/XMC_XIQ-SE/nbi_clients at master · extremenetworks/ExtremeScripting (github.com)
03-25-2024 05:29 AM
Hello,
Please check the Administration --> Client API access to make sure you have configured API access accordingly.
I would also recommend looking into use of this tool:
https://github.com/extremenetworks/ExtremeScripting/blob/master/XMC_XIQ-SE/nbi_clients/README.md
Some modification will be necessary to get it to point to your XIQ-SE, but I've used it to get API access remotely.
Thanks
-Ryan
03-26-2024 01:23 AM - edited 03-26-2024 01:34 AM
In XMC i have checked the "northbound API" for the client.
I have attached the script i am using to test api access. Did i miss something?
import requests
import json
from urllib3.exceptions import InsecureRequestWarning
requests.packages.urllib3.disable_warnings(category = InsecureRequestWarning)
host='https://<redacted>:8443'
nbi_uri = host + '/nbi/graphql'
token_url = 'https://<redacted>:8443/oauth/token/access-token?grant_type=client_credentials'
client_id='<redacted>'
secret='<redacted>'
auth_headers = { "Content-Type":"application/x-www-form-urlencoded" }
response = requests.post(token_url,auth=(client_id,secret),headers=auth_headers,verify=False,timeout=3)
result = response.json()
access_token = result['access_token']
nbi_query = 'network { devices { up ip sysName siteData { siteId siteName location } } }'
s = requests.Session()
s.verify = False
s.timeout = 5
s.headers.update = ({"Accept":"application/json",
"Content-type": "application/json",
"Cache-Control":"no-cache",
"Authorization": "Bearer " + access_token,
})
res = s.post(nbi_uri,json={'query':nbi_query})
print(res)