cancel
Showing results forĀ 
Search instead forĀ 
Did you mean:Ā 

XMC API Authentication

XMC API Authentication

Johnny69
New Contributor II

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 }}}}

1 ACCEPTED SOLUTION

I still not get, why you not use the existing Python class.

However, you added a equal sign where no equal  sign should be

Markus_Nikulski_0-1711465846423.png

 

View solution in original post

7 REPLIES 7

Markus_Nikulski
Extreme Employee

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.

Markus_Nikulski_0-1711371842841.png

 

Markus_Nikulski_1-1711371881905.png

 

 

Markus_Nikulski
Extreme Employee

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)

Ryan_Yacobucci
Extreme Employee

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/Python3/XMC_N...

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

 

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)

 

 

GTM-P2G8KFN