SOAP APIs are developed as the intermediate language. In simple words, we can say that if you built an app in different languages and you want to interact with some other language then you can use SOAP because it gives you less development effort. You can use SOAP APIs to perform the CRUD (create, retrieve, update and delete records) operations or any searches you want or many more.
Let’s take an example to understand the SOAP API. Suppose we have two different platforms such as Java and the .NET platform. If both platforms want to communicate with each other or send data then both platforms need a common language like XML to interact with each other.
We all know that there are two ways to send data between two applications. You can either send data in JSON format or XML format. But if we are talking about the SOAP API then it only works with XML but in the Rest API you can use JSON format as well as XML format to send the data.
Let’s Discuss Some Important Features of JSON:
- It takes less memory. If we talk about XML, It takes more memory as compared to JSON.
- Easy to use and faster than XML because it takes less memory space.
- It's a free tool that means the JSON library is open source and available on the web browser.
- It provides a default mapping.
- The processing JSON library doesn’t require any other libraries that means you don’t have any dependency while using it.
Let’s Discuss the Important Features of XML:
- XML tags are not predefined so you can define your customized tags.
- It is designed to carry data that means you can only get the data from one app to another.
- We can easily understand the XML code or, we can say that XML is self-explanatory code.
- You can easily read and write XML similar to HTML markup language.
Don't forget to check out: Salesforce REST API | HTTP and Callout Basics | All You Need to Know
XML is used for data exchange. It makes the document transportable across the system and by using XML you can exchange data quickly between two platforms.
If you want to make a SOAP request then you have to follow the below steps. Let’s start the first SOAP API call using Postman. This API call is used to authenticate Salesforce org using SOAP from the Postman. Before following the below steps first you have to log in to the Salesforce org.
Step 1: You have to provide an EndPoint URL and Method Name.
EndPoint url: https://login.salesforce.com/services/Soap/c/49.0. (this endpoint URL is used to log in to the Salesforce org so you have to provide its Username and Password. Here, you need to send this username & password in your request body).
Method Name: You have to choose your method type such as Get, Post etc.
Step 2: You need to set the Headers.
Header includes the Content-Type and SOAPAction.
SOAPAction: It can be used to indicate the intent of the SOAPAction HTTP request. If you have not provided this header then you will not be able to make the SOAP call.
Step 3: You need to set the Body.
The general form of SOAP body:
<soap:Envelope …..> //Soap Header code here <soap:Header> </soap:Header> //Soap body code here <soap:Body> // you can write message body here </soap:Body> </soap:Envelope>
SOAP body used for authentication:
<?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:enterprise.soap.sforce.com"> <n1:username> Your Salesforce UserName here</n1:username> <n1:password>Your Password and TokenId here</n1:password> </n1:login> </env:Body> </env:Envelope>
Add the above code in your request body and in place of “Your Salesforce UserName here” put your Salesforce username. And in the place of “Your Password and TokenId here” you can put your password and security token id. Follow the below steps to get your token id:
Go to my personal information → Enter Reset in quick find box → Select Reset My Security Token.
Click on the Reset Security Token button.
You can get your Security Token id in your mail.
Step 4: You have to send the Message.
After setting up the endpoint URL, header, body and request type. Now, Click on Send button then you can see ServerUrl and SessionId in the response. By using ServerUrl and SessionIdm, we can make any call to Salesforce. If you send this session id in the header that means Salesforce knows that you are the right user to talk to me. Basically used for authentication purposes. For making an Apis call you don’t have to send a username and password every time to get data.