My configuration keeps failing…
I am trying to implement a simple OAuth2 Client Credentials flow using Python requests to get an access token for Genesys Cloud. According to the documentation, the endpoint is /oauth/token and the method is POST.
Here is my code snippet:
import requests
url = "https://api.mypurecloud.com/oauth/token"
payload = {
"grant_type": "client_credentials",
"client_id": "my_client_id",
"client_secret": "my_client_secret"
}
headers = {
'Content-Type': 'application/x-www-form-urlencoded'
}
response = requests.post(url, data=payload, headers=headers)
print(response.status_code)
print(response.text)
The response I get is 400 Bad Request with the JSON body: {"error":"invalid_client","error_description":"Client authentication failed"}.
The docs state: “The client credentials grant type is used for server-to-server communication…”. I have verified the Client ID and Secret in the Developer Console multiple times. They are correct. I am using data=payload to ensure it is form-encoded, not JSON. Why is it failing?
Thank you for the help.