Cisco API’s with Python

Example of python script to grab some info via the Cisco API

import requests
#import time
import urllib3
#import pprint
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
import json
from icecream import ic
from pprint import pprint

# Authenticate and get token
headers = {
    'Content-Type': 'application/x-www-form-urlencoded',
}

data = {
  'client_id': '84tffjfxr57pdfjkp*******',
  'client_secret': 'mTECmXe9mspd************',
  'grant_type': 'client_credentials'
}

response = requests.post('https://cloudsso.cisco.com/as/token.oauth2', headers=headers, data=data, verify=False)
ic(response.text)
js = response.json()
token = (js['access_token'])
ic(token)

# Check a serial number against Cisco API
headers = {
    'Accept': 'application/json',
    'Authorization': 'Bearer ' + token,

}
# THESE WORK!!
#response = requests.get('https://api.cisco.com/security/advisories/iosxe?version=16.12.1c', headers=headers, verify=False)
#print(response.text)
#response = requests.get('https://api.cisco.com/sn2info/v2/coverage/status/serial_numbers/FOC10220LK9', headers=headers, verify=False)
#print(response.text)
#response = requests.get('https://api.cisco.com/software/suggestion/v2/suggestions/software/productIds/C9500-24Y4C', headers=headers, verify=False)
#print(response.text)
#response = requests.get('https://api.cisco.com/supporttools/eox/rest/5/EOXByProductID/WS-C3560E-48PD-E', headers=headers, verify=False)
#print(response.text)
#response = requests.get('https://api.cisco.com/product/v1/information/product_ids/C9500-24Y4C', headers=headers, verify=False)
#print(response.text)