Update work/tbx/meraki_api.md
This commit is contained in:
@@ -830,4 +830,316 @@ Understanding the hierarchy used by Meraki to organize networks and devices is c
|
||||
By practicing with the Meraki Dashboard API and using `jq` to parse and manipulate the JSON data, you can gain deeper insights into your network and improve your overall management capabilities. If you have any further questions or need additional examples, feel free to ask!
|
||||
|
||||
---
|
||||
### Understanding the Meraki Dashboard API
|
||||
|
||||
The Meraki Dashboard API is designed to enable programmatic management and monitoring of Cisco Meraki networks. It allows you to automate tasks, gather data, and create custom solutions for network administration. This guide will walk you through the basics of using the Meraki Dashboard API, including finding organization IDs, network IDs, and device information, as well as retrieving device uplink addresses.
|
||||
|
||||
### Getting Started with the Meraki Dashboard API
|
||||
|
||||
#### Tools
|
||||
|
||||
- **Postman Collection:** A graphical tool to explore and interact with the Meraki API.
|
||||
- **Python Library:** The Meraki Python library can be installed via `pip install meraki` for scripting API interactions.
|
||||
|
||||
#### Base URI
|
||||
|
||||
The base URI for API requests is typically:
|
||||
|
||||
```
|
||||
https://api.meraki.com/api/v1
|
||||
```
|
||||
|
||||
For specific regions, use the respective URIs:
|
||||
|
||||
| Country | URI |
|
||||
|----------------------|-------------------------------------|
|
||||
| Canada | https://api.meraki.ca/api/v1 |
|
||||
| China | https://api.meraki.cn/api/v1 |
|
||||
| India | https://api.meraki.in/api/v1 |
|
||||
| United States FedRAMP| https://api.gov-meraki.com/api/v1 |
|
||||
|
||||
#### Authorization
|
||||
|
||||
The API requires a bearer token for authorization. Include the following header in your requests:
|
||||
|
||||
```json
|
||||
{
|
||||
"Authorization": "Bearer <Meraki_API_Key>"
|
||||
}
|
||||
```
|
||||
|
||||
### Step-by-Step Guide
|
||||
|
||||
#### 1. Find Your Organization ID
|
||||
|
||||
The first step is to retrieve the organization ID associated with your API key. This ID is required for most API requests.
|
||||
|
||||
**Request:**
|
||||
|
||||
```sh
|
||||
curl https://api.meraki.com/api/v1/organizations \
|
||||
-L -H 'Authorization: Bearer {MERAKI-API-KEY}'
|
||||
```
|
||||
|
||||
**Response:**
|
||||
|
||||
```json
|
||||
[
|
||||
{
|
||||
"id": "549236",
|
||||
"name":"DevNet Sandbox"
|
||||
}
|
||||
]
|
||||
```
|
||||
|
||||
#### 2. Find Your Network ID
|
||||
|
||||
With the organization ID, you can list all networks within the organization.
|
||||
|
||||
**Request:**
|
||||
|
||||
```sh
|
||||
curl https://api.meraki.com/api/v1/organizations/{organizationId}/networks \
|
||||
-L -H 'Authorization: Bearer {MERAKI-API-KEY}'
|
||||
```
|
||||
|
||||
**Response:**
|
||||
|
||||
```json
|
||||
[
|
||||
{
|
||||
"id":"N_1234",
|
||||
"organizationId":"12345678",
|
||||
"type": "wireless",
|
||||
"name":"My network",
|
||||
"timeZone": "US/Pacific",
|
||||
"tags": null
|
||||
}
|
||||
]
|
||||
```
|
||||
|
||||
#### 3. Find Your Devices and Their Serials
|
||||
|
||||
Use the organization ID to list all devices within the organization.
|
||||
|
||||
**Request:**
|
||||
|
||||
```sh
|
||||
curl https://api.meraki.com/api/v1/organizations/{organizationId}/devices \
|
||||
-L -H 'Authorization: Bearer {MERAKI-API-KEY}'
|
||||
```
|
||||
|
||||
**Response:**
|
||||
|
||||
```json
|
||||
[
|
||||
{
|
||||
"name": "My AP",
|
||||
"lat": 37.4180951010362,
|
||||
"lng": -122.098531723022,
|
||||
"address": "1600 Pennsylvania Ave",
|
||||
"notes": "My AP note",
|
||||
"tags": [ "recently-added" ],
|
||||
"networkId": "N_24329156",
|
||||
"serial": "Q234-ABCD-5678",
|
||||
"model": "MR34",
|
||||
"mac": "00:11:22:33:44:55",
|
||||
"lanIp": "1.2.3.4",
|
||||
"firmware": "wireless-25-14",
|
||||
"productType": "wireless"
|
||||
}
|
||||
]
|
||||
```
|
||||
|
||||
#### 4. Get Devices Uplink Addresses
|
||||
|
||||
Retrieve the uplink addresses for specific devices using their serial numbers.
|
||||
|
||||
**Request for One Device:**
|
||||
|
||||
```sh
|
||||
curl "https://api.meraki.com/api/v1/organizations/{organizationId}/devices/uplinks/addresses/byDevice?serials[]={serial}" \
|
||||
-L -H 'Authorization: Bearer {MERAKI-API-KEY}'
|
||||
```
|
||||
|
||||
**Response for One Device:**
|
||||
|
||||
```json
|
||||
[
|
||||
{
|
||||
"mac": "00:11:22:33:44:55",
|
||||
"name": "My Switch 1",
|
||||
"network": {
|
||||
"id": "L_24329156"
|
||||
},
|
||||
"productType": "switch",
|
||||
"serial": "{serial}",
|
||||
"tags": [
|
||||
"example",
|
||||
"switch"
|
||||
],
|
||||
"uplinks": [
|
||||
{
|
||||
"interface": "man1",
|
||||
"addresses": [
|
||||
{
|
||||
"protocol": "ipv4",
|
||||
"address": "10.0.1.2",
|
||||
"gateway": "10.0.1.1",
|
||||
"assignmentMode": "dynamic",
|
||||
"nameservers": {
|
||||
"addresses": [
|
||||
"208.67.222.222",
|
||||
"208.67.220.220"
|
||||
]
|
||||
},
|
||||
"public": {
|
||||
"address": "78.11.19.49"
|
||||
}
|
||||
},
|
||||
{
|
||||
"protocol": "ipv6",
|
||||
"address": "2600:1700:ae0::c8ff:fe1e:12d2",
|
||||
"gateway": "fe80::fe1b:202a",
|
||||
"assignmentMode": "dynamic",
|
||||
"nameservers": {
|
||||
"addresses": [
|
||||
"::",
|
||||
"::"
|
||||
]
|
||||
},
|
||||
"public": {
|
||||
"address": null
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
```
|
||||
|
||||
**Request for Two Devices:**
|
||||
|
||||
```sh
|
||||
curl "https://api.meraki.com/api/v1/organizations/{organizationId}/devices/uplinks/addresses/byDevice?serials[]={serial1}&serials[]={serial2}" \
|
||||
-L -H 'Authorization: Bearer {MERAKI-API-KEY}'
|
||||
```
|
||||
|
||||
**Response for Two Devices:**
|
||||
|
||||
```json
|
||||
[
|
||||
{
|
||||
"mac": "00:11:22:33:44:55",
|
||||
"name": "My Switch 1",
|
||||
"network": {
|
||||
"id": "L_24329156"
|
||||
},
|
||||
"productType": "switch",
|
||||
"serial": "{serial1}",
|
||||
"tags": [
|
||||
"example",
|
||||
"switch"
|
||||
],
|
||||
"uplinks": [
|
||||
{
|
||||
"interface": "man1",
|
||||
"addresses": [
|
||||
{
|
||||
"protocol": "ipv4",
|
||||
"address": "10.0.1.2",
|
||||
"gateway": "10.0.1.1",
|
||||
"assignmentMode": "dynamic",
|
||||
"nameservers": {
|
||||
"addresses": [
|
||||
"208.67.222.222",
|
||||
"208.67.220.220"
|
||||
]
|
||||
},
|
||||
"public": {
|
||||
"address": "78.11.19.49"
|
||||
}
|
||||
},
|
||||
{
|
||||
"protocol": "ipv6",
|
||||
"address": "2600:1700:ae0::c8ff:fe1e:12d2",
|
||||
"gateway": "fe80::fe1b:202a",
|
||||
"assignmentMode": "dynamic",
|
||||
"nameservers": {
|
||||
"addresses": [
|
||||
"::",
|
||||
"::"
|
||||
]
|
||||
},
|
||||
"public": {
|
||||
"address": null
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"mac": "00:11:22:33:44:55",
|
||||
"name": "My Switch 2",
|
||||
"network": {
|
||||
"id": "L_24329156"
|
||||
},
|
||||
"productType": "switch",
|
||||
"serial": "{serial2}",
|
||||
"tags": [
|
||||
"example",
|
||||
"switch"
|
||||
],
|
||||
"uplinks": [
|
||||
{
|
||||
"interface": "man1",
|
||||
"addresses": [
|
||||
{
|
||||
"protocol": "ipv4",
|
||||
"address": "10.0.1.3",
|
||||
"gateway": "10.0.1.1",
|
||||
"assignmentMode": "dynamic",
|
||||
"nameservers": {
|
||||
"addresses": [
|
||||
"208.67.222.222",
|
||||
"208.67.220.220"
|
||||
]
|
||||
},
|
||||
"public": {
|
||||
"address": "78.11.19.49"
|
||||
}
|
||||
},
|
||||
{
|
||||
"protocol": "ipv6",
|
||||
"address": "2600:1700:ae0:f84c::9c2f",
|
||||
"gateway": "fe80::aa46:202a",
|
||||
"assignmentMode": "dynamic",
|
||||
"nameservers": {
|
||||
"addresses": [
|
||||
"::",
|
||||
"::"
|
||||
]
|
||||
},
|
||||
"public": {
|
||||
"address": null
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
```
|
||||
|
||||
### Conclusion
|
||||
|
||||
The Meraki Dashboard API provides a robust set of tools for managing and monitoring Meraki networks. By following this guide, you can:
|
||||
|
||||
1. Retrieve organization IDs.
|
||||
2. List networks within an organization.
|
||||
3. Find devices and their serial numbers.
|
||||
4. Retrieve uplink addresses for devices.
|
||||
|
||||
This allows for efficient automation and detailed network management, enabling you to streamline network operations and create custom solutions to fit your specific needs. If you have any questions or need further assistance, feel free to ask!
|
||||
|
||||
Reference in New Issue
Block a user