Docs Menu
Docs Home
/ /
MongoDB Command Line Interface
/ / /

mongocli iam organization apikey create

On this page

  • Syntax
  • Options
  • Output
  • Examples

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.

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>

Note

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

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:

  • json for output in JSON format

  • go-template for custom output using the Go template

  • go-template-file for custom output specified using Go template file

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 Organization Owner role to create an API key for the organization.

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

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>

Warning

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 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

The following command creates an API key using the myOM profile, which contains Organization Owner credentials and specifies the Ops Manager service. The output is returned in JSON format.

mongocli iam organization apikey create --desc "My API key" --orgId 5a1b39eec902201990f12345 --role ORG_OWNER,ORG_MEMBER --profile myOM --output json

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

{
"id": "5f3d8ea3c9022019903c9fce",
"desc": "My API key",
"roles": [
{
"orgId": "5a1b39eec902201990f12345",
"roleName": "ORG_OWNER"
},
{
"orgId": "5a1b39eec902201990f12345",
"roleName": "ORG_MEMBER"
}
],
"privateKey": "b4d12345-b4a3-1234-b24e-729b3f35642d",
"publicKey": "abcdefgh"
}

Back

Organization API Keys