I am looking to refresh a dashboard via a scheduled job using the Dashboard REST API. Historically, you would set up a Named Credential and Auth Provider, but I assume we can do this with the new External Credentials. This post does it with a JWT + Certificate, but I'd like to avoid the need to create a CA certificate for just this use case. I feel like I should be able to do this with just the Client Credentials with Client Secret Flow, but I am getting the error: System.CalloutException: Unable to fetch the OAuth token.
EDIT - I think I may have solved the issue - per this thread, I set the Enable Client Credentials Flow on the Connected App which I had missed, and then in Manage Connected Apps, and set the Run As to be an Admin. At that point, the callout then worked. (I did also change the Callback and Identity URLs to be the actual domain, but that didn't initially solve it, so not sure if that was required)
Steps I have performed so far:
- Create Connected App
- Enabled oAuth Settings
- Set Callback URL : https://login.salesforce.com/services/oauth2/callback
Then created External Credentials as below
For Principals, there is one entry with ClientId and Client Secret set to the Connected App Id and Secret
Finally, Created Named Credentials and set URL = https://[sfdomainname].my.salesforce.com