SolvedAPI & Developers
API returns 401 although I generated a key
Asked by Ryan Mitchell15 days ago
I am trying to script monitor creation. I looked for an API key section in settings and could not find one, so I tried using my account password with basic auth and got 401. What is the correct way to authenticate against the API?
Accepted answer from MonoDuty Support
62
Deniz ArslanMonoDuty Support Engineer12 days ago
Exactly. The flow is:
1. Post your email and password to the login endpoint. The response contains a token field.
2. Send that value on every subsequent request as an Authorization header with the Bearer prefix.
3. When you are finished, you can call the logout endpoint, which revokes only the token you used, not your other sessions.
A few practical notes for scripting:
The auth endpoints are rate limited to 10 requests per minute per IP, and that budget is shared across register, login, password reset and Google sign-in. So authenticate once at the start of your script and reuse the token, rather than logging in per request. A loop that logs in each iteration will hit the limit quickly.
Store the token as a secret in your CI system, never in the repository. If it leaks, resetting the account password revokes every token for that account.
And since the token is tied to a user, that user's role determines what the script can do. Creating monitors requires organization owner or admin, so a script running as a plain member will get authorization errors rather than 401.
Was this helpful?62 of 64 found this helpful
3 replies
Deniz ArslanMonoDuty Support Engineer14 days ago
Hi Ryan, you did not miss a settings page, there is no separate API key concept. Authentication uses the token you receive when you sign in, sent as a bearer token. Basic auth is not supported, which is why you got a 401.
Ryan Mitchell13 days ago
So I log in from the script and reuse the token it returns?
Ryan Mitchell12 days ago
Working now. The tip about the shared auth rate limit saved me a debugging session.