fbpx

Free Salesforce Developers Tutorials >

Chapter 13 - API >

REST API Part 6

REST API Part 6

What You’ll Learn


S2 Labs

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() {
    // 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();
     // Setting endpoint
    req.setEndpoint(url);
     // Setting Endpoint
    req.setMethod('GET');
     // Setting URL
    String url = 'https://currency-converter5.p.rapidapi.com/currency/convert?format=json&from=AUD&to=CAD&amount=1);
     // Setting Headers
    req.setHeader('X-RapidAPI-Key', 'Your X-RapidAPI-Key');
    req.setHeader('X-RapidAPI-Host': 'Your X-RapidAPI-Host');
    // Send the request, and return a response
    HttpResponse res = h.send(req);
}
salesforce-developer

Download Study Material

Get access to exclusive study material for Salesforce Certification and ace your exams!

Download Now

Our Salesforce Certification Courses

Hey there! Glad you made it through our Salesforce Developer Training for beginners . But wait! We've got some high-in-demand Salesforce courses for you to take your Salesforce skills to the next level, making you a desired professional in the Salesforce job market.

Post a Comment

Your email address will not be published. Required fields are marked *