Listing Project Database Users via Python

I have a new requirement from auditing for get a list of all Database users on all of our Projects. We’ve been manually going in and taking screenshots which is extremely tedious. I was looking into a way to automate this with Python. I couldnt really find any good guides or anything to lead me in the right direction but was able to piece together something.

Im able to connect to my project and run a very basic query with:

import requests
from requests.auth import HTTPDigestAuth
import pprint

base_url = “

Replace these with your MongoDB Atlas username and API key

atlas_user = “<your_username>”
atlas_user_key = “<your_api_key>”

auth = HTTPDigestAuth(atlas_user, atlas_user_key)

response = requests.get(base_url, auth=auth)

But looking for suggestions on how to construct the url to retrieve the user list. I came up with but keep getting and error that thats an invalid url. Not sure how to construct the url so I can query the list of databases users. Any suggestions would be greatly appreciated

Hi @Chase_Russell

The syntax for this call is{groupId}/databaseUsers the groupId is required not self.

 curl -s -n --digest \
--header "Accept: application/vnd.atlas.2023-11-15+json"  \
--request GET "" \
| jq '.results[]|select(.username=="cdellaway")'
Output, click to expand
  "awsIAMType": "NONE",
  "databaseName": "admin",
  "groupId": "588fc162d383ad09d65f7ae2",
  "labels": [],
  "ldapAuthType": "NONE",
  "links": [
      "href": "",
      "rel": "self"
  "oidcAuthType": "NONE",
  "roles": [
      "databaseName": "admin",
      "roleName": "atlasAdmin"
      "databaseName": "admin",
      "roleName": "clusterMonitor"
  "scopes": [],
  "username": "cdellaway",
  "x509Type": "NONE"