Navigation

Enable/Disable 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

Use this endpoint to enable or disable a user’s API key. You must be the MongoDB user specified in the digest authentication to successfully use this endpoint.

Resource

PATCH /users/{USER-ID}/keys/{KEY-ID}

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.
KEY-ID Required The unique identifier for the user API key that you want to enable or disable.

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
enabled boolean Indicates whether the API key is enabled or disabled. 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.
obfuscatedKey string The last twelve digits of the API key that you enabled or disabled. The remainder of the key is obfuscated for security.
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

The following example disables a user API key:

curl -X PATCH --digest -u "{userName}:{apiKey}" --header "Content-Type: application/json" \
 "https://cloud.mongodb.com/api/atlas/v1.0/users/69g73c0980eef52994dbgdge/keys/5af48e7f87d9d67a814ab1g5" \
 --data '{"enabled":"false"}'

Example Response

{
  "createdAt" : "2018-05-10T21:29:27Z",
  "description" : "My API Key",
  "enabled" : false,
  "id" : "5af4b9b787d9d624af93c04c",
  "obfuscatedKey" : "********-****-****-670587c49cc9",
  "usedCount" : 1,
  "userId" : "69g73c0980eef52994dbgdge"
}