Showing results for 
Show  only  | Search instead for 
Did you mean: 

Saving meraki.dashboardAPI(API_KEY) in separate file.

Here to help

Saving meraki.dashboardAPI(API_KEY) in separate file.

I'm newbie to python would like some guidance.


I want to create a file with the meraki.dashboardAPI(API_KEY) in it and call it from scripts I write.  I don't want to have the call in every script.  I got the API_KEY in a file and call it into the script using from key import API_KEY and it works.  I would like to create the same for the dashboardAPI call.


For example

dashboard = meraki.DashboardAPI(
     api_key = api_key,
     base_url = '',
     #log_file_prefix = os.path.basename(__file__[:-3],
     #log_path= './Logs',
    print_console = False

my_org = dashboard.organizations.getOrganizations()


I can't figure out how to get the dasboard info into the file.


Thanks in advance.



Meraki Employee

Re: Saving meraki.dashboardAPI(API_KEY) in separate file.

If you run two separate scripts, they won't share variables between them. Based on the text below, it appears that functions may be what you're actually looking for. You can pass values into them and return values from them.


Given the chance, I recommend reading this guide or watching this video to get you started.




They'll also describe how to load the API key into an environmental variable, which is a safer method to use than dropping it into a file. It prevents things like accidentally uploading your key to a GitHub repository.




Welcome to the Meraki Community!
To start contributing, simply sign in with your Cisco account. If you don't yet have a Cisco account, you can sign up.