Created
October 2, 2023 19:58
-
-
Save isamarietr/5b0525d0f2d73960b05565b4af78a54d to your computer and use it in GitHub Desktop.
MongoDB - Make authenticated call to admin api
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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