I am trying to make a call to
https://cloud.mongodb.com/api/atlas/v1.0/groups/{group_id}/apps/{app_id}/accessList
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 = "75.75.184.203"
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!")
else:
return(f"Error adding IP address: {response.status_code} - {response.text}")