mongocli iam organization apikey create¶
The iam organization apikey create
command creates a new
API key for the specified organization.
You must have the Organization Owner
role to create an API key for
the organization.
Syntax¶
mongocli iam organization|organizations|org|orgs apiKey|apiKeys|apikeys create --desc "<description-of-key>" [ --orgId <organization-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 |
--orgId | string | Unique identifier of the organization for which you want to create an API key. If specified, this value overrides any organization ID stored in your profile or environment variable. If omitted, your profile must contain the organization ID. | 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 Organization Owner
credentials, the organization ID, and specifies the Atlas
service. The output is returned in the default format.
mongocli iam organization apikey create --desc "My API key" --role ORG_OWNER
The previous command creates the API key and prints the following to the terminal.
API Key '5f3d8790c12345678903c8d66' created. Public API Key abcdefgh Private API Key b4d12345-b4a3-1234-b24e-729b3f35642d