mongocli iam organizations apiKeys create
On this page
Create an API Key for your organization.
MongoDB returns the private API key only once. After you run this command, immediately copy, save, and secure both the public and private API keys.
To use this command, you must authenticate with a user account or an API key with the Organization User Admin role.
Syntax
Command Syntax
mongocli iam organizations apiKeys create [options]
Options
Name | Type | Required | Description |
---|---|---|---|
--desc | string | true | Description of the API key. |
-h, --help | false | help for create | |
--orgId | string | false | Organization ID to use. This option overrides the settings in the configuration file or environment variable. |
-o, --output | string | false | Output format. Valid values are json, json-path, go-template, or go-template-file. To see the full output, use the -o json option. |
--role | strings | true | Role or roles that you want to assign to the API key. To assign more than one role, specify each role with a separate role flag or specify all of the roles as a comma-separated list using one role flag. To learn which values the CLI accepts, see the Items Enum for roles in the Atlas API spec: https://www.mongodb.com/zh-cn/docs/atlas/reference/api-resources-spec/v2/#tag/Programmatic-API-Keys/operation/createApiKey/. |
Inherited Options
Name | Type | Required | Description |
---|---|---|---|
-P, --profile | string | false | Name of the profile to use from your configuration file. To learn about profiles for MongoCLI, see https://dochub.mongodb.org/core/atlas-cli-configuration-file. |
Output
If the command succeeds, the CLI returns output similar to the following sample. Values in brackets represent your values.
API Key '<ID>' created. Public API Key <PublicKey> Private API Key <PrivateKey>
Examples
# Create an organization API key with organization owner access in the organization with the ID 5a1b39eec902201990f12345: mongocli iam organizations apiKeys create --role ORG_OWNER --desc "My API Key" --orgId 5a1b39eec902201990f12345 --output json