REST API Part 6
Chapter Topics
- APIs in Salesforce
- Need of API in Salesforce
- Languages Used in creating APIs
- How Communication Happens in APIs
- Types of APIs in Salesforce
- REST API Part 1
- REST API Part 2
- REST API Part 3
- REST API Part 4
- REST API Part 5
- REST API Part 6
- REST API Part 7
- REST API Part 8
- REST API Part 9
- SOAP API Part 1
- SOAP API Part 2
- SOAP API Part 3
- SOAP API Part 4
- SOAP API Part 5
- Metadata API in Salesforce
API Callout In Salesforce
So far you have seen how to create Salesforce API. Now, If we want to call an API of any external Application like Stripe, Hubspot, Google Sheets, or Google Slides from Salesforce.
To call an API in Salesforce, HTTP, HTTPRequest, and HTTPResponse classes are used. Here below is the code sample for API callout of currency conversion.
public static void callAPI() {
// Define the URL before using it
String url = 'https://currency-converter5.p.rapidapi.com/currency/convert?format=json&from=AUD&to=CAD&amount=1';
// Instantiate a new Http object
Http h = new Http();
// Instantiate a new HTTP request, specify the method (GET) as well as the endpoint
HttpRequest req = new HttpRequest();
req.setEndpoint(url); // Set the URL endpoint
req.setMethod('GET'); // Set the HTTP method
// Set headers correctly using separate setHeader calls
req.setHeader('X-RapidAPI-Key', 'Your X-RapidAPI-Key');
req.setHeader('X-RapidAPI-Host', 'currency-converter5.p.rapidapi.com');
// Send the request and get response
HttpResponse res = h.send(req);
// You can process the response here as needed
System.debug(res.getBody());
}

Join our newsletter: Get daily update on Salesforce career insights & news!
Join Now!
Need more support?
Get a head start with our FREE study notes!
Learn more and get all the answers you need at zero cost. Improve your skills using our detailed notes prepared by industry experts to help you excel.