Well, first am all new into the REST API's. I am not getting what I am doing wrong. Below are the steps I am following:

  1. Created a Lightning Connected App and got CONSUMER_KEY and SECRET_KEY.
  2. Hitting the below URL in my Browser to get AUTH_KEY: https://login.salesforce.com/services/oauth2/authorize? response_type=code&client_id=CONSUMER_KEY&redirect_uri=REDIRECT_URL
  3. Hitting below URL to get ACCESS_TOKEN and REFRESH_TOKEN: login.salesforce.com/services/oauth2/token?grant_type=authorization_code&redirect_uri=REDIRECT_URL&client_id=CONSUMER_KEY&client_secret=SECRET_KEY&code=AUTH_KEY.
  4. After getting the ACCESS_TOKEN and REFRESH_TOKEN, using Postman Tool or Hitting the below URL to Access data from Salesforce Org: https://MY_INSTANCE.my.salesforce.com/services/data/v43.0/query?q=SELECT+name+from+Account?Bearer=ACCESS_TOKEN

After hitting this URL either in Postman or Browser URL I am getting this below error:

[ { "message": "Session expired or invalid", "errorCode": "INVALID_SESSION_ID" } ]

  • I think what I did wrong here is that the parameters will go in Headers, not in URL. – Kamal Thakur Sep 29 '18 at 13:19

Your problem is indeed in step 4. The ACCESS_TOKEN must go in the Authorizatipn header. In Postman, for example, you would click on the headers section and add a new header with the key of Authorization, and the value of Bearer ACCESS_TOKEN. You would need to remove that from the URL in order for the query to work correctly as well, so the URL would be https://MY_INSTANCE.my.salesforce.com/services/data/v43.0/query?q=SELECT+name+from+Account.


Please follow the steps which are mentioned here http://www.v2force.com/blog/connected-apps/. It may help you to get Salesforce data using REST API.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.