Updating access IP for project via API

I am trying to make a call to


to add an IP address.

I have tried using an API key associated with the organization, and an API key associated with the project.

I am gettting a “not authorized” response. Help!

app_id = “application-0-blahblahblach” #app_config[“mongo”][“project_id”]
group_id = “abunchofnunmbersandletters” #app_config[“mongo”][“application_id”]

# IP address and optional comment
ip_address = ""
comment = "Added for accessing application"

# API endpoint
url = f"https://cloud.mongodb.com/api/atlas/v1.0/groups/{group_id}/apps/{app_id}/accessList"

# Headers with API keys
headers =  {
    "apiKey": api_key_public,
    "apiSecret": api_key_private,
    "Content-Type": "application/json"

# Data payload for the new IP address
data =  {
    "ipAddress": ip_address,
    "comment": comment

# Send the POST request
response = requests.post(url, headers=headers, json=data)

# Check the response status
if response.status_code == 201:
    return("IP address added successfully!")
    return(f"Error adding IP address: {response.status_code} - {response.text}")

Have you carefully worked through the examples here?