How to use Private key and Public key in MongoDB API call using node.js?

106 views
Skip to first unread message

Kuldeep Kushwaha

unread,
Sep 20, 2019, 9:26:22 AM9/20/19
to mongodb-user

I want to get a list of projects in MongoDB using its API "https://cloud.mongodb.com/api/atlas/v1.0/groups" but every time I get error as "401 You are not authorized for this resource". Seems like I am passing the Private_key and Public_key in the wrong way.

Below is my request object

{
method: 'GET',
headers: {
  'Accept': 'application/json',
},
auth: {
  user: 'Public_Key',
  pass: 'Private_key'
  }
}  

Can anyone please help me with this.

Kevin Adistambha

unread,
Sep 23, 2019, 12:49:11 AM9/23/19
to mongodb-user

Hi,

There’s an example on listing all projects in an organization: Get All Projects in an Organization. In that page there is a step-by-step example on how to get all projects in your org.

I think the URI you’re using is not complete. You need to determine your Org-Id and include it in the GET request, e.g.: https://cloud.mongodb.com/api/atlas/v1.0/orgs/{ORG-ID}/groups. Without the Org-Id, it’s an invalid request.

You also need the correct permission set up for the public/private key pair, and the IP whitelist for the API call, otherwise the request will be rejected.

If you need further help, you can use the online chat button in the Atlas page (the button on the lower right hand corner of the screen).

Best regards,
Kevin

Reply all
Reply to author
Forward
0 new messages