In Previous Posts ive built some Meraki applications, which are all based on the v0 API, Meraki first built their API set on v0. This was a good set, but not complete (it covers maybe 70% of the GUI dashboard options) so does limit you to what can be managed.
They started working on the v1 set in 2020, and in August 2020 they released v1 out of beta. Its got more options than v0, and will continue to be developed as Meraki drive towards a 1:1 parity between API and GUI (unlike v0 which will no longer be updated).
BUT what do you do if you have v0 API code ? The v1 calls are different, so you need to go through and change all you code to support it right ? No – you can keep both versions on your system and have them BOTH work in the same application. Lets look how to make this work.
The Meraki guide stored HERE shows how to install the Meraki python module. Essentially its:
pip install meraki
But that will install v0. If you want v1, you need to run:
pip install meraki==1.0
Both these calls will install the Meraki python module, but also they both install in the same folder, thus overwriting each other. So the first thing we need to do is get separate copies of the modules so we can call them. Simplest way to do this is run the “pip install meraki” call first, then rename this folder to ‘meraki_v0’ in the python modules folder, then run “pip install meraki==1.0” to install v1 into the ‘meraki’ module folder.
In windows (and I assume other operating systems) the modules folder is “Python\Lib\site-packages”, so do the renaming there once the v0 is downloaded.
So now we have both API modules stored and ready for use. Within the python app, we now just need to create 2 sessions to the Meraki API dashboard – one for v0 and one for v1. The following snippets can be added to your code to support making calls to both API sets:
import meraki_v0, meraki
base_urlv0=’https://api.meraki.com/api/v0/’
base_urlv1=’https://api.meraki.com/api/v1/’
client = meraki.DashboardAPI(
api_key=x_cisco_meraki_api_key,
base_url=base_urlv0,
log_file_prefix=os.path.basename(__file__)[:-3],
log_path=”,
print_console=False)
client2 = meraki.DashboardAPI(
api_key=x_cisco_meraki_api_key,
base_url=base_urlv1,
log_file_prefix=os.path.basename(file)[:-3],
log_path=”,
print_console=False)
Now we have 2 clients sessions we an call on, based on if we want to use the v0 or v1 API set. For example:
network_list = client.networks.getOrganizationNetworks(params[“organization_id”])
access_policy = client2.switch.getNetworkSwitchAccessPolicies(params[“network_id”])
The eventual aim would be to only be using the v1 API for all calls, but for now at least your existing code will still work properly whilst the transition to the new API set happens and you have both v0 and v1 calls in the same application..