GOAL: Use Insomnia REST Client to get data from Salesforce (REST API), in order to implement a server to server solution where I get data (programmatically) from Salesforce without interactively login.

What I have done:

  • configure an App in Salesforce to get a client_id and client_secret
  • Reset security token to use with the username password. password = PASSWORD + SECURITY TOKEN, see below

enter image description here

I am able to get an access_token with 200 OK

enter image description here

Then I use the access_token above to get data by setting Authorization bearer as a header. It fails with Session expired or invalid 401 Unauthorized

Any pointers on what I am doing wrong? or on how to use Insomnia REST client?

enter image description here

  • 2
    Try disabling "Lock sessions to the IP address from which they originated" per this article - help.salesforce.com/s/articleView?id=000335524&type=1 Aug 9, 2021 at 12:50
  • 3
    Also, as a side note, the Username-Password flow is not recommended for anything but testing. The JWT Bearer flow is the suggested one for non-interactive (server-server) authentication.
    – Derek F
    Aug 9, 2021 at 13:00

2 Answers 2


Make sure to use the same domain as that is returned in your instance url (my.salesforce.com is what I see from your screenshot) field when you obtained the token.

If you try to use lightning domain it will be unauthorized request.

  • Following your pointers, I was able to resolve my issue. See what resolved my issue in my Answer below.
    – zabumba
    Aug 25, 2021 at 8:31

The URLs I was using were not correct.

On step 1, to get the token, I used https://test.salesforce.com/services/oauth2/token instead of p****v.lightning.force.com/services/oauth2/token.

That wasn't the issue, and I get a proper access_token too

enter image description here

On step 2, to fetch data, I used https://p*****v.my.salesforce.com/services/data/v52.0. It is .my.salesforce.com instead of .lightning.force.com. That was my issue.

enter image description here

You must log in to answer this question.

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