Client Credentials vs Auth Code for headless reporting script

Writing a cron job to pull /api/v2/analytics/reporting/conversations. Docs say: “Use client credentials for server-to-server communication.”

Trying auth code flow:
POST /oauth/token
grant_type=authorization_code

Getting 401. Should I just switch to client credentials since there’s no user session?

Switch to client credentials. It’s the only sane way for headless scripts. You don’t need a user context for analytics. Just grab the token with your app’s ID and secret. Watch out for scope creep though. If you request admin:analytics:read but forget read:reports, the call will fail silently or throw a 403.

curl -X POST "https://api.mypurecloud.com/oauth/token" \
 -H "Authorization: Basic base64(client_id:client_secret)" \
 -H "Content-Type: application/x-www-form-urlencoded" \
 -d "grant_type=client_credentials&scope=analytics:report:read"