Navigation

Create a User API Key

The Atlas API uses HTTP Digest Authentication. Provide your Atlas username and API key as the username and password when constructing the HTTP request.

For complete documentation on configuring API access for an Atlas project, see Configure Atlas API Access.

Base URL: https://cloud.mongodb.com/api/atlas/v1.0

This endpoint creates an API key for a specific MongoDB user. You must be the MongoDB user specified in the digest authentication to successfully use this endpoint.

Note

You must have access to an API key generated from the GUI by your administrator before you can successfully use this endpoint. See generate an API Key for instructions.

Resource

POST /users/{USER-ID}/keys

Request Parameters

Request Path Parameters

Path Element Required/Optional Description
USER-ID Required. The unique identifier for your MongoDB user. Specify the value of the id field in the response body to the /orgs/{ORG-ID}/users endpoint.

Request Query Parameters

This endpoint may use any of the HTTP request query parameters available to all Atlas API resources. These are all optional.

Name Type Description Default
pretty boolean Display response in a prettyprint format. false
envelope boolean Specifies whether or not to wrap the response in an envelope. false

Request Body Parameters

Name Type Description
description string Description of the API key, which may be an empty string. Required.

Response

Name Type Description
createdAt timestamp The time the API key was created.
description string Description of the API key.
enabled boolean Indicates whether the API key is enabled.
id string The unique identifier of the API key.
key string The new API key. Atlas displays the key only one time, so you must copy it.
usedCount number The number of times that the API key has been used by the associated user.
userId string The user ID associated with the request for a new API key.

Example Request

curl -X POST --digest -u "{username}:{apiKey}" --header "Content-Type: application/json" \
 "https://cloud.mongodb.com/api/atlas/v1.0/users/69g73c0980eef52994dbgdge/keys" \
 --data '{"description":"New API Key"}'

Example Response

{
  "createdAt" : "2018-05-04T20:51:32Z",
  "description" : "Test",
  "enabled" : true,
  "id" : "6bedc7d480eef52e16fe4699",
  "key" : "5b27d00d-e454-4a21-863e-670587c49cc9",
  "usedCount" : 0,
  "userId" : "569g73c0980eef52994dbgdge"
}