meraki.DashboardAPI: setting custom user agent string

JM2024
New here

meraki.DashboardAPI: setting custom user agent string

Hi,
I am using the python merakiDashboardAPI and would like to set the custom user agent string when doing API-callls. 
I am following this guide:

https://developer.cisco.com/meraki/api-v1/user-agents-overview/#formatting

 

This are some parts of my code:

dashboard = meraki.DashboardAPI(suppress_logging=True,output_log=False,print_console=False,caller="testing testing")
admins=dashboard.organizations.getOrganizationAdmins(organizationId=merakiOrgID)
.....
apiCalls=dashboard.organizations.getOrganizationApiRequests(organizationId=merakiOrgID)

When I look into the "apiCalls"-variable I see in the userAgent-field a very long string, like this:
python-meraki/1.42.0 %7B%22implementation%22%3A%20%7B%22name%22%3A%20%22CPython%22%2C%20%22version%22%3A%20%223.10.12%22%7D%2C%20%22system%22%3A%20%7B%22name%22%3A%20%22Linux%22%2C%20%22release%22%3A%20%226.5.0-35-generic%22%7D%2C%20%22cpu%22%3A%20%22x86_64%22%2C%20%22caller%22%3A%20%22getApiUsage/1.0%20testing%22%7D

I would expect, to see only "testing".

What do I do wrong?
Or, is this the normal output?

Greetings
Juergen
 
 

 

2 Replies 2
rhbirkelund
Kind of a big deal

If you use urllib.parse package, you can use it to unquote it to something readable.

 

>>> import meraki
>>> import urllib.parse
>>> 
>>> dashboard = meraki.DashboardAPI(
...     suppress_logging=True,
...     caller="testing testing"
... )
>>> 
>>> admins = dashboard.organizations.getOrganizationAdmins(orgID)
>>> apiCalls = dashboard.organizations.getOrganizationApiRequests(orgID)
>>> 
>>> print(apiCalls[0]['userAgent'])
python-meraki/1.46.0 %7B%22implementation%22%3A%20%7B%22name%22%3A%20%22CPython%22%2C%20%22version%22%3A%20%223.11.6%22%7D%2C%20%22distro%22%3A%20%7B%22name%22%3A%20%22macOS%22%2C%20%22version%22%3A%20%2214.5%22%7D%2C%20%22system%22%3A%20%7B%22name%22%3A%20%22Darwin%22%2C%20%22release%22%3A%20%2223.5.0%22%7D%2C%20%22cpu%22%3A%20%22arm64%22%2C%20%22caller%22%3A%20%22testing%20testing%22%7D
>>> 
>>> testing = urllib.parse.unquote(apiCalls[0]['userAgent'])
>>> 
>>> print(testing)
python-meraki/1.46.0 {"implementation": {"name": "CPython", "version": "3.11.6"}, "distro": {"name": "macOS", "version": "14.5"}, "system": {"name": "Darwin", "release": "23.5.0"}, "cpu": "arm64", "caller": "testing testing"}
>>> 
LinkedIn ::: https://blog.rhbirkelund.dk/

Like what you see? - Give a Kudo ## Did it answer your question? - Mark it as a Solution 🙂

All code examples are provided as is. Responsibility for Code execution lies solely your own.
RicardoD
Meraki Employee
Meraki Employee

You can use this: 

print(urllib.parse.unquote(apiCalls[0]['userAgent'])) to find the caller.
Get notified when there are additional replies to this discussion.