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.
Syntax¶
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.
Options¶
Option | Type | Description | Required? |
---|---|---|---|
--desc | string | Description of the API key. | yes |
--projectId | string | Unique identifier of the project. If omitted, uses the project ID in the profile or environment variable. | no |
--output , -o | string | Command output format. Valid values are:
If omitted, the command returns output in the default format. | no |
--profile , -P | string | Name of the profile where your credentials are saved. You must have credentials with the If omitted, uses the default profile. To learn more about creating a profile, see Configure the MongoDB CLI. | no |
--role | string | 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. | yes |
Output¶
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>
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:
Examples¶
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