Navigation
  • API >
  • Configure Atlas API Access

Configure Atlas API Access

To access the Atlas API, you must generate an API key for either programmatic access for an organization or a Personal API Key (deprecated) for an Atlas user.

Preferred Method to Use API

MongoDB recommends using Programmatic API Keys instead of Personal API Keys (deprecated).

Programmatic API Keys cannot use the Cloud Manager User Interface

API keys that are associated with an organization are not associated with user credentials and cannot log in to the Atlas user interface.

Prerequisite

Enable API Whitelisting for Your Organization

For Atlas users with a non-empty API whitelist, all API access must originate from a whitelisted IPv4 address. Ensure your configured whitelist entries provide appropriate coverage for all clients which require API access. An empty API whitelist grants access to all API endpoints except those that explicitly require whitelisting.

You can configure Atlas to require API whitelisting at the organization level. When this setting is enabled, all API calls within that organization must originate from an entry on each respective Atlas user’s API whitelist. For organizations that require API whitelisting, Atlas users cannot access any API operations until they define at least one API whitelist entry.

To require an API whitelist for an Organization:

  1. Log into Atlas.
  2. Access the Organization using the Context picker in the top-left hand corner of the Atlas UI.
  3. Click Settings from the left hand navigation.
  4. Toggle the Require IP Whitelist for Public API setting to On.

For a description of the Atlas API’s principles and conventions, see the API.

Programmatic API Keys

To grant programmatic access to an organization or project using only the API, you can create an API key. API keys:

  • Have two parts: a Public Key and a Private Key. These serve the same function as a username and Personal API Key when making API requests to Atlas.
  • Cannot be used to log into Atlas through the user interface.
  • Must be granted roles as you would Users to make sure the API Keys can call API endpoints without errors.
  • Can belong to one organization, but may be granted access to any number of projects in that organization.

Manage Programmatic Access to an Organization

Required Permissions

To perform any of the following actions, you must have the Organization Owner role.

Create an API Key in an Organization

  1. From the Context menu, select the organization that you want to view.

  2. Click Access.

  3. Click the tab for API Keys.

  4. Select Create API Key from the Manage button menu.

  5. From the API Key Information step of the Add API Key page, enter a description for the new API Key in the Description box.

  6. Select the new role or roles for the API Key from the Organization Permissions menu.

  7. Click Next.

  8. From the Private Key & Whitelist step of the Add API Key page, click Add Whitelist Entry.

  9. Enter an IPv4 address from which you want Atlas to accept API requests for this API Key.

    You can also click Use Current IP Address if the host you are using to access Atlas also will make API requests using this API Key.

  10. Click Save.

    Copy the Private Key Before Leaving this Page

    The Private Key is only shown once: on this page. Click the Copy button to add the Private Key to the clipboard. Save and secure this Private Key as you would any other password.

View the Details of an API Key in an Organization

  1. From the Context menu, select the organization that you want to view.

  2. Click Access.

  3. Click the tab for API Keys to see the available keys.

  4. From the ellipsis menu to the right of the API Key, click View Details.

    The <Public Key> API Key Details modal displays:

    • The obfuscated Private Key
    • The date the Key was last used
    • The date the Key was created
    • The IPv4 addresses on which the key is whitelisted
    • The projects to which the Key has been granted access

Change an API Key in an Organization

You can change the roles, description, or whitelist of an API Key in an Organization.

  1. From the Context menu, select the organization that you want to view.

  2. Click Access.

  3. Click the tab for API Keys to see the available keys.

  4. From the ellipsis menu to the right of the API Key you want to change, click Edit.

  5. From the API Key Information step of the Add API Key page, you can change the description of the API Key in the Description box.

  6. You can change existing or add new roles to the API Key from the Organization Permissions menu.

  7. Click Next.

  8. From the Private Key & Whitelist step of the Add API Key page, you can add or remove an IP address to the whitelist.

    • To add an IP address from which you want Atlas to accept API requests for this API Key, click Add Whitelist Entry and type an IPv4 address.

      You can also click Use Current IP Address if the host you are using to access Atlas also will make API requests using this API Key.

    • To remove a whitelisted IP address, click trash icon to the right of the whitelisted IP address.

  9. Click Save.

Delete an API Key from an Organization

  1. From the Context menu, select the organization that you want to view.

  2. Click Access.

  3. Click the tab for API Keys to see the available keys.

  4. Click trash icon to the right of the API Key that you want to delete.

  5. Click Delete to confirm that you want to delete this API Key or Cancel to leave the key in the Organization.

    Removing an API Key from an Organization also removes that key from any projects to which the key was granted access.

Manage Programmatic Access to a Project

Required Permissions

To perform any of the following actions, you must have either the Project User Admin role.

Create an API Key for a Project

  1. From the Context menu, select the project that you want to view.

  2. Click Access.

  3. Click the tab for API Keys.

  4. Select Create API Key from the Manage button menu.

  5. From the API Key Information step of the Add API Key page, enter a description for the new API Key in the Description box.

  6. Select the new role or roles for the API Key from the Project Permissions menu.

  7. Click Next.

  8. From the Private Key & Whitelist step of the Add API Key page, click Add Whitelist Entry.

  9. Enter an IPv4 address from which you want Atlas to accept API requests for this API Key.

    You can also click Use Current IP Address if the host you are using to access Atlas also will make API requests using this API Key.

  10. Click Save.

Copy the Private Key Before Leaving this Page

The Private Key is only shown once: on this page. Click the Copy button to add the Private Key to the clipboard. Save and secure this Private Key as you would any other password.

View the Details of an API Key in a Project

  1. From the Context menu, select the project that you want to view.
  2. Click Access.
  3. Click the tab for API Keys to see the available keys.
  4. From the ellipsis menu to the right of the API Key, click View Details.

The <Public Key> API Key Details modal displays the obfuscated Private Key, the date the key was last used, the date it was created, and the IPv4 addresses on which the key is whitelisted.

Change an API Key’s Roles in a Project

  1. From the Context menu, select the project that you want to view.
  2. Click Access.
  3. Click the tab for API Keys to see the available keys.
  4. From the ellipsis menu to the right of the API Key, click Edit Permissions.
  5. Select the new role or roles for the API Key from the menu.
  6. Click on the checkmark to save.

Delete an API Key from a Project

  1. From the Context menu, select the project that you want to view.
  2. Click Access.
  3. Click the tab for API Keys to see the available keys.
  4. Click trash icon to the right of the API Key.

Personal API Keys (Deprecated)

Important

Personal API keys are deprecated, use Programmatic API Keys instead.

To access the Atlas API, each user must generate an API key. Each user can have up to 10 API keys associated with their account. Each key can be either enabled or disabled but all count toward the 10 key limit.

An API key is like a password. Keep it secret.

When accessing Atlas through the API, you have the same level of access as you do through the Atlas interface. Your Atlas roles apply to both the interface and the API.

Generate Personal API Keys

Important

When you generate a key, Atlas displays it one time only. You must copy it. Atlas will never display the full key again.

  1. On the upper-right hand corner, click on your user name and select Account. Click on Public API Access.

  2. In the API Keys section, click Generate.

  3. Type a description into the Description box.

  4. Click Generate.

  5. If prompted for two-factor authentication:

    1. Type the authentication code.
    2. Click Verify.
    3. Click Generate.
  6. Copy and record the key.

    Warning

    Copy the key immediately. Atlas displays the full key one time only. You will not be able to view the full key again.

    Record the key in a secure place. After you record the key, click Close.

Limit API Operations to Whitelisted IPv4 Addresses

To access whitelisted API operations, you must configure your API whitelist with the IPv4 addresses from which you will issue the whitelisted commands. You also must have the Organization Owner role to issue whitelisted commands.

Address-based whitelists protect API operations. Only client requests that originate from a whitelisted IPv4 address are permitted to perform the operations.

Users have their own whitelists and own API keys. When you issue an API call, you must use an API key from your user account and must issue the command from an address on your user account’s whitelist. You cannot use your key to issue a whitelisted API request from an address on another user’s whitelist, unless, of course, you’ve added that address to your own whitelist.

On the resources pages in this guide, whitelisted operations are marked as such.

Add an IPv4 Address to the API Whitelist

  1. On the upper-right hand corner, click on your user name and select Account. Click on Public API Access.

  2. In the API Whitelist section, click Add.

  3. Enter an IPv4 address or CIDR range. To add multiple entries to your whitelist, repeat this step. If you leave your whitelist empty, you have no access to whitelisted operations.

    You can enter any of the following:

    Entry Grants
    An IPv4 address Access to whitelisted operations from that address.
    A CIDR-notated range of IPv4 addresses Access to whitelisted operations from those addresses.

Delete an IPv4 Address from the API Whitelist

  1. On the upper-right hand corner, click on your user name and select Account.
  2. Click on Public API Access.
  3. In the Whitelist section, click the address’s gear icon and select Delete.
←   API API Resources  →