-
Notifications
You must be signed in to change notification settings - Fork 0
/
get-site-json.py
executable file
·36 lines (29 loc) · 1 KB
/
get-site-json.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import requests
import json
#DNA get authentication token
url = "https://sandboxdnac.cisco.com/dna/system/api/v1/auth/token"
payload = {}
headers = {
'Content-Type': 'application/json',
'Authorization': 'Basic ZGV2bmV0dXNlcjpDaXNjbzEyMyE='
}
response = requests.request("POST", url, headers=headers, data = payload)
dna_token = json.loads(response.text.encode('utf8'))
#print(json.dumps(dna_token, sort_keys=True, indent=1))
token=dna_token['Token']
#print(token)
#USE to GET request
url = "https://sandboxdnac.cisco.com/dna/intent/api/v1/site"
payload = {}
headers = {
'Content-Type': 'application/json',
'X-Auth-Token': token
}
response = requests.request("GET", url, headers=headers, data = payload)
#print(response.text.encode('utf8'))
json_object=json.loads(response.text.encode('utf8'))
print(json.dumps(json_object, sort_keys=True, indent=4))
#Site names on devnet DNA
site_names = json_object['response']
for sitename in site_names:
print('Site Name:' + sitename['name'] + '\t site_id:' + sitename['id'])