function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

Consume a third party REST Api in salesforce



I have a requirement where I have to call a third party REST Api in my salesforce app.


I have been reading and I see all posts show how to create a REST call for outside world to consume but what I want is something simple call the ouside world's API. How do I proceed about it?

I see that I have to add the external url in Remote site settings and what else code do I need to craete.




Mohith Kumar ShrivastavaMohith Kumar Shrivastava

You need to use HTTP callout


public class AuthCallout {

 public void basicAuthCallout(){
 HttpRequest req = new HttpRequest();

 // Specify the required user name and password to access the endpoint 

 // As well as the header and header information 

 String username = 'myname';
 String password = 'mypwd';

 Blob headerValue = Blob.valueOf(username + ':' + password);
 String authorizationHeader = 'BASIC ' +
 req.setHeader('Authorization', authorizationHeader);

 // Create a new http object to send the request object 

 // A response object is generated as a result of the request   

 Http http = new Http();
 HTTPResponse res = http.send(req);

  An example call for GET


refer the above link i shared for POST request.Also you may need to check authentication you apply

Ramesh Naidu PRamesh Naidu P
Hi Mohith,

above code is not working. it gives error  No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin '' is therefore not allowed access.