Running into a snag with the OAuth2 token endpoint. I’m trying to get an access token using client credentials in a Python script to feed into our OTel data action pipeline. The setup looks correct on paper, but I keep hitting a 401.
Here’s the code:
import requests
url = "https://api.mypurecloud.com/oauth/token"
payload = {
"grant_type": "client_credentials",
"client_id": "my_client_id",
"client_secret": "my_client_secret"
}
response = requests.post(url, data=payload)
print(response.status_code)
print(response.text)
The response is straight up {"error":"invalid_client"}. I’ve double checked the ID and secret. They work in Postman with the exact same body. Curl works too. It’s just the Python requests library that’s failing.
I tried adding Content-Type: application/json headers but that didn’t help. Also tried passing json=payload instead of data=payload. Same result.
Is there something specific about how Genesys Cloud parses the request body that requests is missing? Or am I missing a header requirement that Postman adds by default?