Closed seanmathias closed 3 years ago
Unless I'm mistaken, there is no endpoint to check if the API is working.
Your suggestion for improvement can be simply carried out (in the meantime) through a function similar to this one:
import meraki
def is_valid_apikey(apikey: str) -> bool:
try:
meraki.DashboardAPI(api_key=apikey, suppress_logging=True, print_console=False).organizations.getOrganizations()
except meraki.exceptions.APIError as e:
if '401' in str(e).lower():
return False
return True
Thanks, that is a reasonable approach, I was just looking for buiilt-in functionality rather than adding my own.
Consider that since validating the API key requires making an API call, if it is valid, then that's one of your 5 calls per second gone just to validate a key that really should have been known to work in advance.
Customers who are frugal with their API call budget might not be thrilled that a generally unnecessary API call is made on their behalf--so it is a fundamentally better approach to not pre-validate the API key.
On Wed, Dec 9, 2020 at 5:37 PM Sean Mathias notifications@github.com wrote:
Thanks, that is a reasonable approach, I was just looking for buiilt-in functionality rather than adding my own.
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/meraki/dashboard-api-python/issues/126#issuecomment-742175767, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA5EUKVPCJKDP3VCVJNATK3SUAQ6DANCNFSM4TSM7YTA .
A call to DashboardAPI using a bogus API key returns a seemingly valid session. It is only when making a subsequent API call that the API key is flagged as invalid.
Typically I would expect the key to be flagged as invalid when attempting to establish a session so this condition can be trapped earlier and in the logical place.