How to get session id in Salesforce?

How to get session id in Salesforce?

1. Use POST method.

2. Set the end point.

Sandbox – https://test.salesforce.com/services/Soap/u/35.0
Production – https://login.salesforce.com/services/Soap/u/35.0

Use custom domain URL if my domain is enabled and prevent login from test or login.salesforce.com is enabled.

3. Set your headers as below.

SOAPAction = “”
Content-Type = text/xml

4. Use the following as body.

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:partner.soap.sforce.com"> 
   <soapenv:Body>
      <urn:login>    
         <urn:username>Login ID</urn:username>
         <urn:password>Password</urn:password>
      </urn:login>    
   </soapenv:Body>    
</soapenv:Envelope>

5. Get the SessionId.

Leave a Reply