Trying to get an access token via Client Credentials Grant using the standard Python requests library. The docs state: “To obtain an access token, send a POST request to the OAuth token endpoint with the client_id and client_secret.”
I’m running this locally in Amsterdam, targeting https://api.mypurecloud.com/oauth/token.
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)
Status code is 401. Body says "error": "invalid_client".
I’ve verified the ID and secret in the Developer Console. They are correct. I tried adding Authorization: Basic base64(client_id:client_secret) header instead of sending in the body, but got the same 401. Also tried setting Content-Type: application/x-www-form-urlencoded explicitly.
What am I missing?