Saving meraki.dashboardAPI(API_KEY) in separate file.

VictorTJ
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

 

init.py

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

 

getOrganizationID.py

my_org = dashboard.organizations.getOrganizations()

 

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

 

Thanks in advance.

 

 

1 Reply 1
Jon_Hartman
Meraki Employee
Meraki Employee

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.

 

 

 

Get notified when there are additional replies to this discussion.