How to authenticate Atlassian Organization Admin API

Hi!

Ive been trying to use the admin rest api to get all user (https://developer.atlassian.com/cloud/admin/user-provisioning/rest/api-group-users/#api-scim-directory-directoryid-users-get)

Using python I am constantly running into a 403 return code.
I am an org admin, created an API key via the admin interface, which returns the API key and the directoryId.
The tenant has users being provisioned via EntraID

I am using the following code:

directory_id= "xxx"
api_key= "xxx"

url = f"https://api.atlassian.com/scim/directory/{directory_id}/Users"

headers = {
  "Accept": "application/json",
  "Authorization": f"Bearer {api_key}"
}

response = requests.request(
   "GET",
   url,
   headers=headers
)

I am constantly getting the following response:

{
    "detail": "Not authorized to access: /api/scim/directory/xxx/Users",
    "schemas": [
        "urn:ietf:params:scim:api:messages:2.0:Error"
    ],
    "scimType": "invalidValue",
    "status": "403"
}

Ive also tried Basic authentication by base64 encoding my email and the api key, which then returns a 401 'Not authorized" instead.

Any ideas what might be the issue here?

Thanks a lot

Ive just tried another, different, api request (https://developer.atlassian.com/cloud/admin/user-management/rest/api-group-profile/#api-users-account-id-manage-profile-get) and I didnt encounter this error using the same API key used for the request thats not working.

Might it be related to the directoryId? Ive used the one that I got when creating the API key.
Now I think its not related to the authentication anymore, but maybe something else?