I have implemented a web service in salesforce and generated the WSDL for the web service and provided it to the external system. However while invoking a call, we need to pass the session id in teh request. How can the external system get the session Id? Can we create a connected app and provide them the required details to get the session id?
1 Answer
First you need to set your endpoint
of your server.
- Endpoint URL (Sandbox)->
https://test.salesforce.com/services/Soap/u/35.0
- Endpoint URL (Production)->
https://login.salesforce.com/services/Soap/u/35.0
Set your headers
as below:
- SOAPAction-> ""
- Content-Type-> text/xml
And finally Body
. Replace Login Id and Password with actual credentials:
<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>
In response, you will get SessionId
.
Once you've SessionId
, set your endpoint URL as follows:
https://domain_name.my.salesforce.com/services/apexrest/YourWebServiceName
Again set Headers
as follows:
- Authorization-> Bearer
- Content-Type-> application/json
And Body
:
{
"name":"ABC"
}
-
Thanks Rohit. However I am using a custom web service and the endpoint will contain the apex web service name. Should this call be included in the same request to the web service Or should this call be made first to retrieve the session details and then use it to call the web service Oct 4, 2017 at 9:55
-
@SFDCLearner You will need 2 request. 1st to get
sessionId
and 2nd, use thatsessionId
to call your webservice. Refer Updated the answer. Oct 4, 2017 at 10:01 -
Thanks Rohit! the second actual request can be made in xml as well i guess right? Let me try this and come back! Oct 4, 2017 at 10:04
-