1

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:

Selected Scopes as below enter image description here

Then created External Credentials as below enter image description here

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

2
  • so - is there still a question here? I used a similar approach where the connected app provides the OAuth token for the external credential
    – cropredy
    Commented Apr 13 at 2:59
  • No - I think I have it all working now, so I will add an answer outlining the setup I used Commented Apr 13 at 14:21

1 Answer 1

1

For anyone else trying this, here is what I set up in my Dev Org to make this work: The key piece was checking the box for Enable Client Credential Flow.

Connected App

And then in the External Credential, you can just use the Client Credentials with Client Secret Flow and set the Client Id and Secret to be the Connected App details:

External Credential

I also realized I could avoid a scheduled job by just using the new option to delay a Queueable job by x mins - so it just keeps chaining itself to run every 5 minutes after each run.

2
  • We have a problem, where we run the job only during business hours and the token expires and refresh token flow does not work :( I guess running a a job every five minutes to keep token alive is a workaround.
    – Kacper A
    Commented May 20 at 8:39
  • This flow should handle that I think - does the scope include Perform Requests at any time? Commented May 20 at 13:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .