HTTP requests in salesforce REST integrations

Salesforce provides powerful APIs that allow developers to interact with Salesforce data programmatically. These APIs rely heavily on HTTP requests, which are the foundation of communication between a client (e.g., Postman or a web application) and the Salesforce server.

In this article, we’ll break down the different types of HTTP requests, data-passing mechanisms, and authentication methods, and show you how to test Salesforce Standard APIs using Postman. This guide is beginner-friendly and SEO-optimized for the keyword HTTP requests and Usage (Salesforce Standard API).


What Are HTTP Requests?

HTTP requests are messages sent from a client (like Postman) to a server (like Salesforce) to perform actions like retrieving, creating, updating, or deleting data. Salesforce’s Standard APIs use these requests to enable seamless interaction between applications.


Types of HTTP Requests and Their Usage in Salesforce

1. GET
  • Purpose: Retrieve data from Salesforce without modifying it.
  • Example: Fetching a list of accounts from Salesforce.
  • Usage in Salesforce API: GET https://yourInstance.salesforce.com/services/data/v57.0/sobjects/Account
  • Response: Returns a list of accounts in JSON format.

2. POST
  • Purpose: Send data to create a new resource in Salesforce.
  • Example: Adding a new account.
  • Usage in Salesforce API: POST https://yourInstance.salesforce.com/services/data/v57.0/sobjects/Account
  • Request Body Example (JSON format): { "Name": "New Account", "Industry": "Technology" }

3. PUT
  • Purpose: Replace an existing resource with new data.
  • Example: Updating an account entirely.
  • Usage in Salesforce API:PUT https://yourInstance.salesforce.com/services/data/v57.0/sobjects/Account/001xx000003DGbTAAW
  • Request Body Example (JSON format):{ "Name": "Updated Account", "Industry": "Education" }

4. PATCH
  • Purpose: Update only specific fields of an existing resource.
  • Example: Modifying the industry of an account.
  • Usage in Salesforce API:PATCH https://yourInstance.salesforce.com/services/data/v57.0/sobjects/Account/001xx000003DGbTAAW
  • Request Body Example (JSON format):{ "Industry": "Healthcare" }

5. DELETE
  • Purpose: Remove a resource from Salesforce.
  • Example: Deleting an account.
  • Usage in Salesforce API: DELETE https://yourInstance.salesforce.com/services/data/v57.0/sobjects/Account/001xx000003DGbTAAW
  • Response: Returns a success message if the deletion is successful.

Data-Passing Mechanisms in HTTP Requests

1. Query Parameters
  • Passed in the URL after a ?.
  • Example: Fetch active accounts. GET https://yourInstance.salesforce.com/services/data/v57.0/sobjects/Account?Industry=Technology

2. Path Parameters
  • Embedded directly in the URL to specify a resource.
  • Example: Access a specific account. GET https://yourInstance.salesforce.com/services/data/v57.0/sobjects/Account/001xx000003DGbTAAW

3. Request Body
  • Data sent in the body of the HTTP request, typically with POST, PUT, or PATCH.
  • Common formats:
    • JSON: Most popular and user-friendly format. { "Name": "Sample Account" }
    • Text: Simple unstructured text.
    • XML: Structured but less commonly used format. <Account><Name>Sample Account</Name></Account>
    • Form-URL-Encoded: Encodes key-value pairs in the format of query strings. Name=Sample+Account&Industry=Technology
Query Parameters and Path Parameters in HTTP requests

Common Authentication Mechanisms Used

Salesforce APIs require authentication to ensure secure data access. Here are common methods:

1. Basic Authentication
  • Username and password are encoded in the request header.
  • Example: Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ=
  • Note here the string after Basic is encoded username and password. We will see in upcoming posts how to generate these authentication headers in Apex.

2. OAuth 2.0
  • Most secure and commonly used method for Salesforce APIs.
  • Example Header: Authorization: Bearer <access_token>

3. API Key
  • A unique key included in the request to authenticate.
  • Example:GET https://api.com?api_key=12345

Using Postman to Test Salesforce API Requests

Postman is an excellent tool for testing and debugging Salesforce API requests. Here’s how you can test the requests:

  1. Install Postman: Download Postman from postman.com.
  2. Set Up Authentication:
    • Use the Authorization tab to configure OAuth 2.0.
    • Enter your Access Token for Salesforce.
  3. Create a New Request:
    • Select the HTTP method (GET, POST, etc.).
    • Enter the Salesforce API endpoint.
  4. Add Headers:
    • Include required headers, such as: Authorization: Bearer <access_token> Content-Type: application/json
  5. Add Body (If Needed):
    • For POST, PUT, or PATCH, enter the request payload in JSON format under the Body tab.
  6. Send the Request:
    • Click Send and view the response from Salesforce.

Summary

Mastering HTTP requests and their usage in Salesforce Standard API is essential for building robust Salesforce integrations. Here’s a quick recap:

  • Use HTTP methods like GET, POST, PUT, PATCH, and DELETE for specific actions.
  • Understand data-passing mechanisms such as query parameters, path parameters, and request bodies.
  • Choose secure authentication mechanisms like OAuth 2.0.
  • Leverage Postman to test and debug your Salesforce API requests.

By following these steps, you’ll gain a strong foundation in working with Salesforce APIs, making you confident in handling real-world projects.