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
priyanka m 8priyanka m 8 

I am trying to call api of salesforce but I am getting an error as Invalid session id


When I call the api like this, https://xx.salesforce.com/services/data/v36.0/sobject/ I am getting an error like this
Please see the image for reference
User-added image
 
Best Answer chosen by priyanka m 8
SKolakanSKolakan
@priyanka
Here is a way to get session Id

Make a call using
URL: https://test.salesforce.com/services/Soap/u/36.0

Headers:
Content-Type:text/xml; charset=UTF-8
SOAPAction:""

Method: Post

Request body:
<?xml version="1.0" encoding="utf-8" ?><env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"><env:Body><n1:login xmlns:n1="urn:partner.soap.sforce.com"><n1:username>yourusername@username.com</n1:username><n1:password>YourPasswordYourSecurityKey</n1:password></n1:login></env:Body></env:Envelope>

User-added image

The response will have Session Id. Use the session ID in your request like this

URL: https://xx.salesforce.com/services/data/v36.0/sobject
Headers:
Content-Type:text/xml; charset=UTF-8
Authorization:Bearer YourSessionId

Method: GET
User-added image


 

All Answers

Srinivas SSrinivas S
If you are accessing from the external tool, you have to supply the sessionId in header to authenticate with salesforce.

------------
Thanks,
Srinivas
- Please mark as solution if your problem is resolved.
priyanka m 8priyanka m 8
How to get the session id?
SKolakanSKolakan
@priyanka
Here is a way to get session Id

Make a call using
URL: https://test.salesforce.com/services/Soap/u/36.0

Headers:
Content-Type:text/xml; charset=UTF-8
SOAPAction:""

Method: Post

Request body:
<?xml version="1.0" encoding="utf-8" ?><env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"><env:Body><n1:login xmlns:n1="urn:partner.soap.sforce.com"><n1:username>yourusername@username.com</n1:username><n1:password>YourPasswordYourSecurityKey</n1:password></n1:login></env:Body></env:Envelope>

User-added image

The response will have Session Id. Use the session ID in your request like this

URL: https://xx.salesforce.com/services/data/v36.0/sobject
Headers:
Content-Type:text/xml; charset=UTF-8
Authorization:Bearer YourSessionId

Method: GET
User-added image


 
This was selected as the best answer
priyanka m 8priyanka m 8
Thank you @Sreeni