mongocli iam project apikey create

The iam project apikey create command creates a new API key for the specified project.

You must have GROUP_USER_ADMIN privileges to create an API key for the project.

mongocli iam project|projects apiKey|apiKeys|apikeys create
--desc "<description-of-key>"
[ --projectId <project-id> ]
[ --output|-o <output-format> ]
[ --profile|-P <profile-name> ]
--role <list-of-roles>

Use -h or --help to view the command-line help for this command.

Description of the API key.

Unique identifier of the project. If omitted, uses the project ID in the profile or environment variable.

--output, -o

Command output format. Valid values are:

  • json for output in JSON format
  • go-template for custom output using the Go template
  • go-template-file for custom output specified using the Go template file

If omitted, the command returns output in the default format.

--profile, -P

Name of the profile where your credentials are saved.

You must have credentials with the Project Owner role to create an API key for the project.

If omitted, uses the default profile. To learn more about creating a profile, see Configure the MongoDB CLI.

Role or roles to assign to the API key. To assign more than one role, you can specify each role with a --role flag or specify the roles in a comma-separated list with one --role flag.

If the command succeeds, it prints the following output to the terminal. If the command returns errors, see Troubleshooting for recommended solutions.

API Key '<api-key-id>' created.
Public API Key <public-key>
Private API Key <private-key>
Copy and Save Public and Private Keys

MongoDB CLI returns the Private API Key only once. After running this command, immediately copy, save, and secure both the Public and Private API Keys.

The default output is a subset of the fields returned by this command. For the complete list of JSON fields returned by the command, see the Public API reference for your MongoDB service:

The following command creates an API key using the default profile, which contains Project Owner credentials, the project ID, and specifies the Atlas service. The output is returned in the default format.

mongocli iam project apikey create --desc "My API key" --role GROUP_OWNER

The previous command creates the API key and prints the following to the terminal.

API Key '5f46abb2d58b421fe3edbb3a' created.
Public API Key cofodjld
Private API Key c5730d9a-7b85-41be-88c3-16225b08c795
Give Feedback