EventGet 50% off your ticket to MongoDB.local London on October 2. Use code WEB50Learn more >>
MongoDB Developer
Atlas
plus
Sign in to follow topics
MongoDB Developer Centerchevron-right
Developer Topicschevron-right
Productschevron-right
Atlaschevron-right

Configuring Atlas in Postman With the Atlas Administration API

Luke Sanderson7 min read • Published Aug 19, 2024 • Updated Aug 19, 2024
Postman APIAtlas
Facebook Icontwitter iconlinkedin icon
Rate this tutorial
star-empty
star-empty
star-empty
star-empty
star-empty
MongoDB's Atlas Administration API is a great way to perform administrative tasks for Atlas programmatically. The Administration API can be used to manage your Atlas organizations, projects, deployments and more. This allows you to automate and integrate your administrative tasks into your own systems.
To explore the MongoDB Atlas Administration API, you can use the public MongoDB Administration API workspace provided by the MongoDB Developer Relations team. In this article, we will show you how to create and manage a cluster in MongoDB Atlas using the MongoDB Administration API and Postman.

Getting started

To complete this tutorial, you will need a Postman account. Postman also recommends installing the desktop app to avoid issues with sending requests from the web browser. You will need to set up your Altas cluster and fork the Postman collection to start using it. The following sections provide some more detailed instructions on how to achieve this if you need them.

Set up your MongoDB Atlas account

The first step is to set up a MongoDB Atlas account. If you don't have an account already, you can get one for free. For this tutorial, an API key with the Organization Owner role is required. Follow the instructions from the documentation for detailed directions on granting programmatic access. Make sure you keep track of the public API key and private API key as these will be used later.
Image of the MongoDB Atlas logo

Fork the Postman collection

From the public MongoDB Administration API workspace on Postman, you will find many Postman collections, one for each version of the API. The most recent version, which appears at the bottom of the list, is the one we are interested in. Click on the three dots next to the collection name and select Create a fork from the popup menu.
Then, follow the instructions on-screen to add this collection to your private workspace. Make sure to also select the MongoDB Atlas Administration API environment in the Environments to fork drop-down.
Screenshot of menu for creating a fork of the Postman Collection. The MongoDB Atlas Administration API Environment has been selected to also fork.

Configure your environment

You will now need to configure the Postman environment that you just forked. Start by opening the Environments tab on the left-hand side. Next, find the MongoDB Atlas Administration API environment.
Here, you find a table of variables, namely digestAuthUsername and digestAuthPassword. These will hold the initial values of {{vault:mongodb-public-api-key}} and {{vault:mongodb-private-api-key}}. These point to secrets in the Postman vault, which you need to create.
To create these secrets, click the Vault button in the bottom right of the screen or use the control + shift + v shortcut. Create two fields named mongodb-public-api-key and mongodb-private-api-key and enter the public and private keys you created earlier. The value of secrets stored in the Postman vault are stored locally and are encrypted using Advanced Encryption Standard (AES) with a 256-bit key length.
If you're using the Postman web app to send requests with references to vault secrets, you must use the Postman Desktop Agent or the Postman Browser Agent. By default, the requests will return a 401 unauthorized response. We recommend using the Postman desktop app to avoid issues related to the web app and its many Postman Agents.
Finally, select MongoDB Atlas Administration API as the active environment from the environment drop-down.
Screenshot of the Postman Vault screen. Two secrets have been added called 'public-api-key' and 'private-api-key'. The user is also selecting the MongoDB Atlas Administration API Environment as the active environment.

Using the Atlas Administration API

Now you are ready to use the Atlas Administration API, navigate back to the forked collection by selecting the Collection tab on the left-hand side.

Checking your connection

To start, use the search bar to find the request called "Return the status of this MongoDB application." Click on the GET request with that name, which will show the options for sending the request.
To send this request, simply click Send. The authorization parameters will be automatically filled from the vault by using the active environment. This should result in a response that displays the public API key that was used as well as the roles it has. The response body should look similar to below:
If the request fails or the API key does not have the ORG_OWNER role, then retry the previous steps.
Copy the orgId from this response as this will be used in the next request.
One great feature of Postman is the ability to generate code snippets for any given request. By clicking the </> icon on the right-hand side of the screen, you can generate a code snippet for the "Return the status of this MongoDB application" request in cURL. Clicking on the drop-down initially labelled cURL gives you the option to generate code for most major programming languages.

Create a project

Now that we know all the variables have been set correctly and we know the organization ID, let's create a project. Search for the request named "Create One Project."
This is a POST request and requires a body to describe the project we are creating. Navigate to the Body tab and paste the following body into the text box, replacing <orgID> with the organization ID copied from the previous response.
Now, send this request. This should result in the creation of a new project and a response body similar to below:
Copy the value of the "id" field as this is your project/group ID. As you can see from the clusterCount field, there are currently no clusters in this project so let's create one.

Create a cluster

Navigate to the request named "Create One Cluster from One Project" via the search function. This POST request uses both path variables under the Params tab as well as a body under the Body tab.
In the Params tab, set the :groupId variable to the ID copied from the previous response body. This is used to select the project the operation is under.
In the Body tab, paste the following body into the text box.
This states the configuration options for an M0 cluster. M0 clusters are free forever and suitable for users learning MongoDB or developing small proof-of-concept applications.
Click Send to create the cluster.
To view a more detailed description of this endpoint as well as a detailed explanation of the request body schema, click the Documentation icon and follow the link to the documentation page for each endpoint.
Screenshot of the 'Create One Cluster from One Project' request page. The user is currently on the body tab and has entered a body that describes a free M0 cluster. The user also has the documentation tab open on the right side.

Load a sample dataset

Navigate to the request named "Load Sample Dataset Request into Cluster" via the search function. This POST request only uses path variables under the Params tab.
Enter the same groupId from previous steps. For the name field, enter "MyFreeCluster" or the name of the cluster that was just created if you chose a different name.
Click Send to load the sample dataset. This should result in a response body such as:
As you can see, the state is set to WORKING. To check if the dataset has finished being loaded, navigate to the "Check Status of Cluster Sample Dataset Request" request page.
On the params page, enter your groupId. The sampleDatasetId value is the value of _id in the previous response body.
Sending this GET request will give you an update on the progress of the dataset loading. Once the dataset has been loaded, the response body will look similar to the following:

Retrieve metrics about your cluster

Now that we have set up a cluster and loaded some sample data, let's retrieve some metrics about the cluster during that operation.
First, to retrieve the measurements, we need the IDs of the MongoDB processes in the cluster. To do this, navigate to the "Return All MongoDB Processes in One Project" request.
Enter the groupId and click Send. This will result in a response containing information about all the processes in the project --- in this case, just one cluster.
We are interested in the process with the typeName field being equal to REPLICA_PRIMARY as this is the primary node of this cluster. Copy the id of this process as this will be used in the next request.
Finally, navigate to the request called "Return Measurements for One MongoDB Process." This is a GET request with many path and query parameters. You may wish to look at the documentation for a full explanation of each of these parameters but for our request, we only require the following query parameters. Click on the Params tab to see those parameters.
  • m --- List of types of measurements to request. Set this field to "CONNECTIONS."
  • period --- Duration in the ISO 8601 duration format over which Atlas reports the metrics. Set this field to "PT1H."
  • granularity --- Duration that specifies the interval at which Atlas reports the metrics. Set this field to "PT1M."
Make sure these three query parameters are enabled with the checkbox and all others are disabled. This query requests the number of connections over each minute for the past hour.
Next, set the path variables. Set the id copied from the previous request body to the field named ProcessId. The groupId field should be set to the same value as the previous requests.
Sending this GET request should result in a response with a body similar to the following:
These data points can be plotted to show the number of connections over time. To learn in more detail about the different metrics this endpoint can provide, click on the Documentation icon and follow the link to the documentation for the Atlas Administration API.

Summary

And just like that, we created a project, deployed a cluster, and requested metrics about the cluster all through the Atlas Administration API using Postman. If you want to learn more about using the Atlas Administration API programmatically, a great place to start is Calling the MongoDB Atlas Administration API: How to Do it From Node, Python, and Ruby.
Top Comments in Forums
There are no comments on this article yet.
Start the Conversation

Facebook Icontwitter iconlinkedin icon
Rate this tutorial
star-empty
star-empty
star-empty
star-empty
star-empty
Related
Tutorial

How to Do Semantic Search in MongoDB Using Atlas Vector Search


Jan 12, 2024 | 8 min read
Tutorial

Getting Started With MongoDB and C


Sep 17, 2024 | 12 min read
Article

A Free REST API for Johns Hopkins University COVID-19 dataset


Aug 15, 2024 | 5 min read
Code Example

Trends Analyser


Sep 11, 2024 | 1 min read
Table of Contents
  • Getting started