Retrieve API data with requests

BorrahDanikls
New here

Retrieve API data with requests

I am trying to retrieve switch data via the Meraki API. Instructions and samples for the API's are here:

# https://dashboard.meraki.com/api_docs#return-a-switch-port

Sample Request

$ curl -L \
-H 'X-Cisco-Meraki-API-Key: <key>' \
-H 'Content-Type: application/json' \
-X GET 'https://dashboard.meraki.com/api/v0/devices/[serial]/switchPorts/[number]'

Sample Response

Successful HTTP Status: 200

{
  "number": 1,
  "name": "my port",
  "tags": "dorm-room limited",
  "enabled": true,
  "type": "access",
  "vlan": 10,
  "voiceVlan": 20,
  "poeEnabled": true,
  "isolationEnabled": false,
  "rstpEnabled": true,
  "stpGuard": "disabled",
  "accessPolicyNumber": "asdf1234",
  "linkNegotiation": "Auto negotiate"
}

I am using Python's requests instead of curl. My code is: (NOTE I have altered the serial number and API key just for this post. I use the correct values when I run the code)

import requests

headers = {
    'X-Cisco-Meraki-API-Key': '1111111111111111111111111111111111111111',
    'Content-Type': 'application/json',
}

# response = requests.get('https://dashboard.meraki.com/api/v0/devices/[serial]/switchPorts/[number]', headers=headers)
response = requests.get('https://dashboard.meraki.com/api/v0/devices/1111-2222-3333/switchPorts/1', headers=headers)
print(response)


# <Response [200]>

I am getting back <Response [200]> instead of the JSON data that the API above shows.

My HTTP Status is correct, however. What am I missing in order to actually get back the JSON data?

3 Replies 3
PhilipDAth
Kind of a big deal
Kind of a big deal

That is using the V0 API.  That is deprecated.  You need to be using the V1 API now.

https://developer.cisco.com/meraki/api-v1/#!get-device-switch-port 

 

On the right-hand side click on "Template" and then "Python - Request" to see an example.

 

PhilipDAth_0-1672388332683.png

 

PhilipDAth
Kind of a big deal
Kind of a big deal

You can even click on "Configuration" and "Run" to test executing the API call.

 

PhilipDAth_2-1672388510878.png

 

PhilipDAth
Kind of a big deal
Kind of a big deal

ps. It is much simpler to use the Meraki Python module ...

Get notified when there are additional replies to this discussion.