Management API returns 400/Connection refused

I’m trying to use the management API to trigger an automatic update of all users upon first login after signup. I’m trying to do that from my own API (rather than via hooks or rules) because there are a number of things I need to do after signup, so I’ve been trying to use the Management API.

My app uses Flask for its backend and Angular 9 for the frontend. When I try to send the request from my API (using the template from this guide), Flask returns ConnectionRefusedError: [Errno 61] Connection refused. I thought I might’ve made a mistake so I tried curl (with the format copied from the same guide), but when I tried it, I got, {"statusCode":400,"error":"Bad Request","message":"Invalid request payload JSON format"}.

I’m not sure what I’m doing wrong, especially since I’ve literally copied the template from the guide and it still seems to be in the wrong format. Can anybody help, please?

Thank you so much in advance!

Check the tenant logs for errors.

If nothing is available there, copy and paste your curl command here.

John

Thanks for the response!

So curl seems to be going through okay now, but requests from my Python backend still return ‘connection refused.’ Since the connection is refused, there’s nothing in the logs, either. I’m not entirely sure what the issue is.

This is my script:

connection = http.client.HTTPSConnection("")
create_payload = "{ \"roles\": [ \"rol_BhidDxUqlXDx8qIr\" ] }"
auth_header = "Bearer " + os.environ.get('MGMT_API_TOKEN')
headers = {
    'content-type': "application/json",
    'authorization': auth_header,
    'cache-control': "no-cache"
}
connection.request("POST", "https://" + AUTH0_DOMAIN + "/api/v2/users/" + user_data['id'] + "/roles", create_payload, headers)
create_response = connection.getresponse()
create_response_data = create_response.read()
print(create_response_data)

As said before, it’s basically copied from the guide, so I’m not sure sharing it would make a difference, but if there’s any error in it…