function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Rathna DeshmukhRathna Deshmukh 

REST API:Session expired or Invalid error

Hi,

Please help me in understanding,Is OU Auth 2.0 the only way to interact with salesforce using rest API'S or does is support the session Id(I,e the session Id we get as part of login menthod in SOAP API).

I am trying to call Query method of REST API by passing the session Id as Authorization header, I get from login method of SOAP API.I am getting below error:
<errorCode>INVALID_SESSION_ID</errorCode>
      <message>Session expired or invalid</message>

below is the url I am calling by passing Authorization header with the value of session Id I am getting from login method form SOAP API.
https://cs2.salesforce.com/services/data/v31.0/query/?q=SELECT ID,name from Contact

Please help.Are there any SOAP UI test cases or samples to refer.I am trying to test from SOAP UI.

Thanks,
Rathna
ShashForceShashForce
Hi Rathna,

You can authenticate using the session ID as well for the REST API. However, you need to add a word "Bearer " infront of the session Id.

e.g.: req.setHeader('Authorization',  'Bearer sessionid_here');

This page has some more details: http://www.salesforce.com/us/developer/docs/api_rest/index_Left.htm#CSHID=quickstart_oauth.htm|StartTopic=Content%2Fquickstart_oauth.htm|SkinName=webhelp

If this answers your question, please mark this as the Best Answer for this post, so that others can benefit from this post.

Thanks,
Shashank


Rathna DeshmukhRathna Deshmukh
Hi Shashank,

Thanks for the reply and details.How to get the session Id using REST API?,Please let me know,Right now I am able to get the session Id only using login method of SOAP API.

Please share if you have any useful links and the information on how to get session Id using REST API.

I just found that I am able to call RESt API using setHeader('Authorization", 'OuAuth Session Id value');