Skip to content

Instantly share code, notes, and snippets.

@isamarietr
Created October 2, 2023 19:58
Show Gist options
  • Save isamarietr/5b0525d0f2d73960b05565b4af78a54d to your computer and use it in GitHub Desktop.
Save isamarietr/5b0525d0f2d73960b05565b4af78a54d to your computer and use it in GitHub Desktop.
MongoDB - Make authenticated call to admin api
import requests
import pprint
public_api_key = "your_public_api_key"
private_api_key = "your_private_api_key"
payload = {"username": public_api_key, "apiKey": private_api_key}
url = f'https://realm.mongodb.com/api/admin/v3.0/auth/providers/mongodb-cloud/login'
# get access token
response = requests.post(url, json=payload)
response_json = response.json()
pprint.pprint(response_json)
token = response_json['access_token']
# make authenticated call
headers = {
'Authorization': f'Bearer {token}'
}
groupId = "your_project_id"
url = f'https://realm.mongodb.com/api/admin/v3.0/groups/{groupId}/apps'
response = requests.get(url, headers=headers)
response_json = response.json()
pprint.pprint(response_json)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment