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

mongocli iam globalApiKey create

On this page

  • Syntax
  • Options
  • Output
  • Examples

The iam globalApiKey create command creates a new Global API Key for the specified Ops Manager instance. You must have the Global Owner role to create a Global API key. You can also create the key through the Ops Manager UI and API.

mongocli iam globalApiKey|globalApiKeys create
--desc "<description-of-key>"
[ --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. This description can’t be longer than 250 characters.
yes
--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. If omitted, uses the default profile. To learn more about creating a profile, see Configure the MongoDB CLI.

You must have credentials with the Global Owner role to create a Global API Key.

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. Global roles accepted by default include:

Role Value in API
Role
GLOBAL_AUTOMATION_ADMIN
GLOBAL_BACKUP_ADMIN
GLOBAL_MONITORING_ADMIN
GLOBAL_OWNER
GLOBAL_READ_ONLY
GLOBAL_USER_ADMIN
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.

For the complete list of JSON fields returned by the command, see the public API reference. The default output contains only a subset of the fields returned by this command.

The following command creates a Global API Key using a profile named om-admin, which contains the Organization Owner credentials, the organization ID, and specifies the Ops Manager service. The output is returned in the default format.

mongocli iam globalApiKey create --desc "My Global API key" --role "GLOBAL_READ_ONLY","GLOBAL_USER_ADMIN" --profile om-admin

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 a Global API Key using a profile named om-admin, which contains the Organization Owner credentials, the organization ID, and specifies the Ops Manager service. The output is returned in JSON format.

mongocli iam globalApiKey create --desc "My Global API key" --role "GLOBAL_READ_ONLY","GLOBAL_USER_ADMIN" --profile om-admin --output json

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

{
"id": "5f3d8ea3c9022019903c9fce",
"desc": "My Global API key",
"roles": [
{
"roleName": "GLOBAL_READ_ONLY"
},
{
"roleName": "GLOBAL_USER_ADMIN"
}
],
"privateKey": "b4d12345-b4a3-1234-b24e-729b3f35642d",
"publicKey": "abcdefgh"
}

Back

Global API Keys