Shardherdfor MongoDB Atlas
Guide

MongoDB Atlas API keys and service accounts

By the Shardherd team · Updated · 3 min read · Sources

Short answer

The Atlas Administration API accepts two kinds of programmatic credentials: service accounts (OAuth 2.0 client ID and secret, which mint one-hour access tokens) and the older API keys (a public and private key pair). Create either in the organization's Applications page (under Identity & Access), give it the smallest roles that work, and add the IP addresses it will call from to its API access list: organizations created in the Atlas UI require that list, and calls from other addresses get HTTP 403.

Service accounts or API keys?

Service accountAPI key
CredentialClient ID and client secret (secret starts mdb_sa_sk_)Public key and private key
How calls authenticateExchange the ID and secret for an OAuth 2.0 access token, send it as Authorization: BearerHTTP Digest authentication with the key pair
Token lifetimeAccess token lasts 1 hour (3600 seconds); request a new one, there is no refreshNo tokens; the key works until revoked
ScopeOrganization or project rolesOrganization or project roles

MongoDB's docs lead with service accounts for new work: tokens expire, secrets can be rotated, and OAuth is supported by more tooling. API keys still work and are what many older scripts and Terraform setups use.

Create a service account

  1. You need Organization Owner to create service accounts or API keys for an organization.
  2. In Atlas, select the organization, click Applications under Identity & Access in the sidebar, then Add new Service Account. Give it a name, the organization roles it needs, and a client secret expiration.
  3. Copy the client secret straight away. It is shown once; if you lose it you must generate a new one.
  4. Add an API access list entry for each IP or CIDR range the account will call from. Use Current IP Address fills in your own.
  5. To work on specific projects, grant the service account roles on those projects.

Then get a token and call the API. The token request can come from anywhere; the access list applies when you use the token:

curl --user "$CLIENT_ID:$CLIENT_SECRET" \
  --data "grant_type=client_credentials" \
  https://cloud.mongodb.com/api/oauth/token

curl --header "Authorization: Bearer $TOKEN" \
  --header "Accept: application/vnd.atlas.2025-03-12+json" \
  https://cloud.mongodb.com/api/atlas/v2/groups

Why your API calls return 403

When you create an organization in the Atlas UI, Atlas turns on Require IP Access List for the Atlas Administration API. With it on, a request from an address that isn't on the credential's API access list gets HTTP 403, even with a perfectly valid token. With it off, an empty list allows any address, but once you add one entry only listed addresses work.

The setting lives in Organization Settings, and only an Organization Owner can change it. It matters most for anything whose IP moves: laptops on different networks, CI runners, and phones, which can change IP several times a day. The options are to list the addresses (or the CIDR range of your office or VPN egress), to switch the setting off and rely on the secret alone, or to use a way of signing in that the list doesn't cover. MongoDB's docs note that API access lists apply only to programmatic API keys and service accounts, not to the Atlas CLI or to delegated access through Atlas App Connections.

This is a different list from the project's IP access list, which controls who can connect to your databases.

Least privilege and rotation

  • Read-only first. A monitoring script needs read roles; only give Project Owner to tools that must change things.
  • One credential per tool. Easier to revoke, and the Activity Feed tells you who did what.
  • Rotate secrets. Service account secrets expire (you choose how long when creating one), and Atlas has a default alert for organizations with service accounts when secrets are about to expire.
  • Never commit them. Keep client secrets and private keys in a secret store, not in a repository or a connection string.

Questions

Why does the Atlas API return 403 with a valid token?

Most often because the caller's IP is not on the service account's or API key's API access list, and the organization requires that list (the default for organizations created in the Atlas UI).

How long does an Atlas service account token last?

One hour (3600 seconds). It can't be refreshed; request a new token with the client ID and secret when it is close to expiry, and reuse it until then.

Are Atlas API keys deprecated?

No, programmatic API keys still work, but MongoDB's docs now present service accounts first for new integrations.

Sources

Checked on 28 November 2026. Prices and limits change; the linked pages are the authority.

  1. Configure API Accesswww.mongodb.com
  2. Configure IP Access List Entrieswww.mongodb.com
  3. Configure Alert Settingswww.mongodb.com

Shardherd brings your Atlas clusters to iPhone.