May 30, 2023
In this blog we will learn about How to use Bulk API with Postman tool in salesforce. But before starting, let’s see some statements on the Bulk API in salesforce.
After completing this unit, you'll be able to:
1. What is Bulk API in Salesforce?
2. Set Up Cross-Origin Resource Sharing in Salesforce
3. Connect the Salesforce with Postman
4. Create a Bulk Job
5. Add Data to the Job
6. Close the Job
7. Check the Status of the Job
8. Get the Job Results
The Bulk API in Salesforce is a RESTful API that allows you to efficiently load or retrieve large volumes of data in Salesforce. It is specifically designed for handling large data sets, such as importing or exporting large amounts of data into or out of Salesforce. The Bulk API provides a way to process data in batches rather than individually, which significantly improves performance and reduces processing time. It is especially useful when you need to work with thousands or millions of records.
Here are some key features and benefits of the Bulk API:
1. In the Quick Find Box, write cors and then select the CORS.
2. Click on the New button at the front of the Allowed Origins List.
3. Fill the Origin URL Pattern field with https://*.postman.com
4. Click Save button.
5. Select CORS and click on the New Button again.
6. Fill the Origin URL Pattern field with https://*.postman.co (The domain extension is .co)
7. After follow the above the steps, you will see the Allowed Origins List as the below figure:
Signup and create workspace:
1. First of all, sign in to your postman or sign up to the postman. (Install Postman tool if you haven't already done.)
2. Select the Workspace menu and select Create Workspace.
3. Give the name as SalesforceCollection.
4. Set visibility to the Personal and then click on the Create Workspace button.
Fork the Salesforce Collection:
1. Open Salesforce Developer using Open Developer to create a fork of the Salesforce APIs Collection.
2. Click on the Salesforce Platform APIs to expand it.
3. Click fork icon to create a fork collection.
4. Give the name as MySalesforceAPIFork and keep the SalesforceCollection as it is in the Workspace.
5. Click on the Fork Collection button like the below figure.
Authorize the Salesforce Org:
1. To authorize your org, please make sure you have logged into salesforce org in your browser.
2. In the postman tool Salesforce Platform APIs should be selected.
3. Make sure No Environment is selected.
4. Click on the Authorize tab.
5. Type should be OAuth 2.0.
6. Click on the Get New Access Token.
7. Click on the Allow button so that the Salesforce Platform APIs Collection accesses your salesforce playground.
8. You will be redirected on the Mange Access Token dialog.
9. Please verify that instance_url matches with your salesforce org’s instance url.
10. Copy this instance_url. We will use this in the next step.
11. Click on the Use Token button and open the Variable tab.
12. In the _endpoint row, paste the instance url in the CURRENT VALUE column and then click Save button.
A Quick Connection Test:
Let’s verify that the postman and salesforce org are connected together or not? In the Salesforce Platform APIs, click on the REST to expand it and then click on the Get Limits as shown in the below figure:
Now Click on the Send button to get the result. Make sure the Status is 200 (OK), it means we successfully connected the postman and salesforce org.
Hurrey! We have connected the Postman and the Salesforce org together.
1. Open the Bulk v2 folder in Salesforce Platform APIs.
2. Click POST Create job.
We are using /services/data, which is the same endpoint used for the REST API. Bulk API uses the same framework that the REST API uses, which means that Bulk API supports many of the same features, such as OAuth authentication.
/jobs/ingest indicates that we are accessing the resource for creating Bulk API jobs.
3. Let’s create the request body. Copy and paste the following text into the Body field in Postman. Note: The lineEnding differs based on the OS you are using. For Windows, use CRLF. For Unix systems, including macOS, use LF.
{
"operation" : "insert",
"object" : "Account",
"contentType" : "CSV",
"lineEnding" : "CRLF"
}
4. Click Save and Send button then check out the response.
Now we can insert account data to the job. Data for the job is sent to the server as a set of records in a PUT request. To do this, follow the below steps:
1. Create a new request in Postman. In your fork of the Salesforce APIs Collection, in the Bulk v2 folder, click PUT Upload Job Data. Note that the HTTP method is PUT.
2. Click the Body tab and select Raw from the dropdown.
Copy the following text into a text editor to clear any extra formatting, then copy it from the text file into the request body field:
"Name"
"Test Account 1"
"Test Account 2"
"Test Account 3"
"Test Account 4"
3. Click Headers. Notice that Content Type says text/csv. That’s because we specified the content type in our first request.
4. Click Save and Click Send.
5. The response contains just a status code of 201 Created, which indicates that Salesforce successfully received the job data.
We have submitted our data. Now, we need to process the data.
1. In your Salesforce API fork, Bulk v2, Query folder click PATCH Close or Abort a Job.
2. Click the Body tab and notice that "state": is already populated with "UploadComplete".
3. Click the Headers tab and notice that the Content-Type is set to application/json.
4. Click Send.
Here's how to check the status of the job in the Trailhead playground:
1. From Setup, enter Bulk Data Load Jobs in the Quick Find box.
2. Select Bulk Data Load Jobs.
Here's how to check the status of the job in Postman from the Bulk v2 folder.
1. Select GET Job Info. Notice that the http method used for this type of request is GET.
2. Click Send button.
Once a job is in the JobComplete state or Failed state, we can get results information in the form of successfully and unsuccessfully processed records. Let’s have a look at the successfully processed records in the Bulk v2 folder.
1. Click the GET Get Job Successful Record Results resource.
2. Click Send button. The response should looks like this.
I hope this blog helped you!