Salesforce REST API communicates using JSON (JavaScript Object Notation), making it simple and lightweight for data exchange between Salesforce and external applications. JSON is easy to read, platform-independent, and widely used in modern integrations.
In this article, you’ll learn how to:
- Send JSON data to Salesforce (create records).
- Receive JSON responses from Salesforce (query records)
- Use simple HTML + JavaScript to test API calls
📤 Send JSON Data to Salesforce
When creating a record in Salesforce, you send JSON in the request body:
{"Name": "API Created Account",
"Phone": "123-456-7890"
}
💻 HTML + JavaScript Example (Send & Receive JSON)
<!DOCTYPE html>
<html>
<head>
<title>Salesforce JSON API Demo</title>
</head>
<body>
<h2>Send & Receive JSON WITH Salesforce</h2>
<button onclick="createAccount()">CREATE Account</button>
<button onclick="getAccounts()">GET Accounts</button>
<div id="output"></div>
<script>
const accessToken = "YOUR_ACCESS_TOKEN";
const instanceUrl = "https://yourInstance.salesforce.com";
async FUNCTION createAccount() {
const response = await fetch(`${instanceUrl}/services/data/v59.0/sobjects/Account`, {
method: "POST",
headers: {"Authorization": `Bearer ${accessToken}`,
"Content-Type": "application/json"
},
body: JSON.stringify({ Name: "API Created Account", Phone: "123-456-7890" })
});
const RESULT = await response.json();
document.getElementById("output").textContent = JSON.stringify(RESULT, NULL, 2);
}async FUNCTION getAccounts() {
const response = await fetch(`${instanceUrl}/services/data/v59.0/query?q=SELECT+Id,Name,Phone+FROM+Account+LIMIT+5`, {
method: "GET",
headers: {"Authorization": `Bearer ${accessToken}`
}});
const RESULT = await response.json();
document.getElementById("output").textContent = JSON.stringify(RESULT, NULL, 2);
}</script>
</body>
</html>
With Salesforce REST API, sending and receiving JSON data is simple and efficient. You can create records by sending JSON payloads and retrieve data in JSON format for easy processing in your applications.
In the next article, we’ll cover using Named Credentials in Salesforce for secure REST API calls.
What is a send HTTP request?
Send HTTP Request is an asynchronous activity that sends an HTTP request and waits for a response from the web server. This activity sends a request to a server that is compliant with either the HTTP 1.0, 1.1, or 2.0 specification.
How to send an HTTP request to API?
After you specify the request protocol, method, and URL, add any other details required by the API you're sending the request to: Specify any parameters and body data or request headers you need to send with the request. Set up any required authentication and authorization.
What is a send request?
The Send Request operation sends an HTTP request to a specified URL using a specified HTTP request method.
Related Topics | You May Also Like
|
👉 Get Free Course →
📌 Salesforce Administrators 📌 Salesforce Lightning Flow Builder 📌 Salesforce Record Trigger Flow Builder |
👉 Get Free Course → |
