I have a flow and this flow calls an invokable method (where callout = true) that calls the Org REST API to update a Slack ViewDefinition.

The method works perfectly when called from an Anonymous Window. However, when called from a Flow, the HttpResponse Code and message are, respectively, 401 and "Unauthorized Error".

This is the code where I set the Http Request:

            URL.getSalesforceBaseUrl().toExternalForm() +
                '/services/data/v56.0/tooling/sobjects/ViewDefinition/' +
request.setHeader('Authorization', 'OAuth ' + UserInfo.getSessionId());
request.setHeader('Content-Type', 'application/json');

You can notice I'm using the user session Id to authenticate. As I said the InvokableMethod notation has callout = true.

Does anybody know what am I doing wrong?

1 Answer 1


It's entirely possible that you don't have a valid API session. Sessions that you obtain from the Lightning Experience do not have full API access, as a security measure. Try running the Flow from a Visualforce page, and it will most likely work, assuming you run it as a user with sufficient permissions.

  • Man ... you're Brilliant! It worked. Thank you!
    – Saulo
    Apr 13, 2023 at 13:10

You must log in to answer this question.

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