Management API returns 400/Connection refused

Hi @john.gateley,

It took a bit more testing (of other URLs) and digging into the Python documentation, but I finally figured out the issue: it’s your (Auth0’s) guide. It seems to be outdated. The correct code snippet would be (note the location of the Auth0 domain):

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

I’d recommend fixing the Python snippet in the guide, though, to prevent further issues.

3 Likes