Dashboard API for Service Providers
Overview
This lab simulates a real-world business case where a network or systems engineer must find a solution utilizing the Meraki Dashboard API. It will teach you to understand application requirements, gather details and then demonstrate your capabilities using Postman.
Prerequisites
Postman with Meraki Collection
Collections for use in the lab
Example scenario
A large Service Provider needs to roll-out Meraki Devices at hundreds of managed Service Customers and will use local 3rd party technicians to complete the task. Since they are unclear of the specific serial numbers being delivered to each site, the on-site technician will need to record this information using a custom tool. The tech will then configure an SSID with the location’s preferred name and password. Finally, a report of the inventory, license status, and potentially other reports should be available.
Sample App Mockup
The app will simply have a menu to perform the various tasks and view the reports.
Developer / Partner Meeting
The developer/partner is excited to build a Meraki Technician App, but first needs to understand how to interact with our API’s. Your mission is not to program the software, but to demonstrate the various API calls to provide the details and functions they require.
Objective
Use the SP API Lab Postman collection of API calls to walk through the lab steps and demonstrate the ability to deliver on the application requirements.
Obtaining your Meraki Dashboard API key
The “SP API Lab” organization already has API Access enabled. You can verify this in Dashboard by navigating to Organizations → Settings → API Access: Enabled
Go to your profile (my profile link) to generate an API key.
Postman Setup
Environment Variables
Since many of your API calls will use the same settings, it’s best to use a variable for this. Postman has a convenient function to handle this called Environment Variables. You can create your own environment to store things like the API key and frequent attributes. For the Lab you can download the Template environment via above link and update the values according to your settings.
- Import the Environment Template by clicking the gear-wheel icon on the top right corner to Manage your Environment. TThereyou’ll have the option to import the Environment File.
- Go ahead and update the variables of the Template according to your settings.
- To start with, create an attribute for the API key:
X-Cisco-Meraki-API-Key
- Then place your API key in the value form.
0000000123123123671547612576125764 (your real key !)
- You can then access these variables in the API calls with following syntax: {{yourVariable}}
Postman Collection
Via the import button in the Top Left Corner please import the SP Lab API Collection file.
Part 1 – Postman Lab Tasks:
- GET a list of organizations
- Copy the Org ID of the SP API Lab
(it should be: 644577696667402365)
- Manage your environment variables to add this “organizationId” for subsequent API calls
- List networks for the organization
- List inventory
- Create a network
- After selecting the “Create a network” API call, select the Body tab and change the name to “API Lab-<your lab #>”
- Note the “id” of the newly created network in the response and manage your environment again to update the “networkId” variable with your new “id” value. (see above section “Environment Variables” how to manage your environment)
- GET the SSID configuration of the new network
- Rename the currently only configured SSID and set a PSK (password)
- This will require modifications to the sample Body as shown in the example below (use n145.meraki.com as shown for this lab vs. dashboard.meraki.com), as well you have to add the SSID-Number to the end of your PUT-call:
change/add the encryptionMode, psk, and authMode
(don’t forget commas before the last key:value pair !)
Part 2 – Python Lab Tasks
In part 1 of this lab you learned to work with Postman and how to test and demonstrate specific Dashboard API calls. Part 2 will now guide you to use Python to automate specific tasks.
A prerequisite of the lab is that you have some basic Python knowledge. If you don’t know anything about Python try to run through the lab and if you are interested in learning more we would recommend Introduction courses like Coursera or Codeacademy.
Key at this lab is to understand simple scripts that can make the SPs life easier, know where to watch for code and get your Laptops/Macs ready to edit and run python scripts.
Preparation Tasks:
- Get your Laptop ready to run Python (the below labs are based on Python2.7, which is preinstalled on MACs).
- Install the requests module (needed for REST API calls)
- Get a Python Script Editor of your choice:
Examples: Sublime, Atom, Komodo Edit, … - Run the following test script to see whether you get a proper result:
- Download the file test-call.py
- Run it by opening a terminal and entering “python test-call.py” in the directory, you saved the script to and you should get a list of Dashboard Organizations as a result. This indicates that your Python environment is ready to run scripts with REST API-calls! Rock’n Roll ☺
Use-Case 1: PoS-Report
A Service Provider has created a managed WLAN service for the SOHO/SMB space. The SP fills its warehouses with thousands of Access Points. For a service like that Cisco asks monthly PoS reports to properly compensate the Sales People. All info needed (which device is located at which customer) is in the dashboard, so find a way to automatize the creation of this monthly PoS report by writing the information needed into a CSV file.
- Download the File getPOSReport.py and open it in your Editor.
- Have a look on the Python-script and especially focus on how the request-calls are used to make REST-API calls.
- There are two rows in the script that are commented with “COMPLETE…..”. Adapt these parts of the code by entering your API key and completing the inventory-URL.
- Run the python-script in a terminal by entering
<python getPOSReport.py ‘SP API Lab’>
A CSV-File should be created in the same directory that contains the relevant info. - Play with the output variable by using the print command → What’s behind this variable? What does it contain? How is it formatted?
Use-Case 2: Scaling Multisite Deployment
Configuration templates can allow many Cisco Meraki devices to be deployed following a single base configuration. This makes it much easier to roll-out new sites/users and maintains consistency across each site’s configuration. It is most useful in cases where a large number of sites exist that share a common network design.
In our example, a SP customer connects i.e. 2000 branches with its headquarter. All 2000 branch-MX networks can be configured by configuring one single Configuration-Template.
By using a template for configuration the local networks of the 2000 branches will get randomized IP-address-ranges. In a greenfield-environment this is probably not a big challenge, but if there is an existing IP-address concept already these IP-address have to be updated in all 2000 branches. You can leverage the API to do so.
This lab-scenario consist of 3 parts:
- Create a Configuration-Template in Meraki dashboard (this task always has to be done in dashboard)
- Create 3 Security-Appliance Networks (could be 2000 Security-Appliance Networks as mentioned above) and bind them to the configured Configuration-Template – as we want to practice working with the API use Postman to do so (not the dashboard)
- Use a Python script to automatically update the IP address-ranges of your branch-networks.
Let’s get started:
- Create and configure a configuration-template
- Login to the dashboard of the SP API Lab organization
- Under Organization/Monitor/Configuration Templates create a new Template and name it “Lab-<your Lab Number>-Template” (Do not bind any networks to it at that point)
- After creating it; navigate to the Template configuration and under Security Appliance/Configure/Addressing & VLANs configure 3 VLANs with unique subnets each (name/number them as you wish and leave the subnet settings as they are).
This setting will now create 3 VLANs on every Sec-network that is bound to this Template and add a randomized /24 subnet from the 10.0.0.0/8 range to each of them.
- Create 3 Security Appliance Networks (use Postman to create them / not Dashboard)
- Use the PUT – Create Network command to create 3 Networks with type “appliance” and name them “Lab-<your Lab Number>-Network-x” (x stands for 1,2 and 3).
- Using the API, bind these networks to the template you have created before. Find the proper REST calls yourself.
(Hints if you are stuck: GET configuration templates (find out the correct id); POST bind network to template) - You can now again login to dashboard and check the Appliance settings of your security networks and you will see that they have been given randomized IP spaces.
- Use Python Script to update the IP address-spaces
- Get the script from github here and the corresponding csv-template here. copy paste the script into a file called “change-vlans.py”.
- Update the csv-template with your network names and the address spaces you’d like to see in these networks.
- Edit the script by adding your API-key and run it by entering “python change-vlans.py <name of your csv-file> <ORG-Name>” in the directory of your script.
- Check in dashboard whether your networks have been properly updated.
BONUS:
- Check out the dns-o-matic script on github.com
Appendix:
Create your own Postman Collection
Collections are a way to group related API calls. You can do this for various platforms or use cases. Today we will be creating a collection for the customer/partner.
- To create and save a collection, first create an API call. Next, click the Save As.. button, which will allow you to create your collection and add any details.
- You will now have a collection on the left menu.
- You can also duplicate calls and move them between collections. This makes routine tasks very easy.