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
Tom SimmonsTom Simmons 

Consume a third party REST Api in salesforce

Dear all, I`m new to Apex REST/SOAP web services world and I`m struggling with a project of integration. What I have a API documentation from client which contains cURL examples, fields and sample JSON response. My questions,
1) How should I start and how can I call this API data inside Salesforce? I need ability to pull and push the data into Salesforce.
2) Are there any changes that need to do in external API system or can I call web services directly in Salesforce if I have login ID and Password of API?
3) In integration projects like this, what should be first step? What information will I need from client to start the integration?
 
I have read few articles online on REST but none of the article provide real time examples. Can you Apex Gurus please help? Any help is much appreciated.
 
Prateek Singh SengarPrateek Singh Sengar
Hi Tom,
The first thing we need to do is to create a remote site settings in salesforce for your external services. Once the remote site setting is created you can use apex HTTP Services to make the callouts to the external system.

The below link describes the steps in details:
https://developer.salesforce.com/page/Apex_Web_Services_and_Callouts
Naveen V 1Naveen V 1
Hi Everyone,

I am new to Salesforce. Planning to integrate third party REST API (http://www.thomas-bayer.com/sqlrest/CUSTOMER/) into Salesforce.
What are steps invovled, can you please explain to me.

I wrote below code in Apex class.

public class AuthCallout {
    public void basicAuthCallout()
    {
    HttpRequest req = new HttpRequest();
    HttpResponse res = new HttpResponse();
    Http http = new Http();

    req.setEndpoint('http://www.thomas-bayer.com/sqlrest/CUSTOMER/');
    req.setMethod('POST');

//these parts of the POST you may want to customize
    req.setCompressed(false);
    req.setBody('key1=value1&key2=value2');
    req.setHeader('Content-Type', 'application/x-www-form-urlencoded');  

    try {
        res = http.send(req);
        } catch(System.CalloutException e) 
        {
        System.debug('Callout error: '+ e);
        }
    System.debug(res.getBody());
}
}

No errors found. But i need to display the third party details into salesforce using VF page. I created Custom object page and field. After that i dont know to how to call those methods and write the code in VF page. Can you please send me the code to display the data in VF Page whatever in the REST API.
how can i write the code. 

Thanks in Advance,
Naveen
Manish Verma 47Manish Verma 47
Hi Everyone,

I have create APEX class where I have described my web API logic. Please see below for the Web API code.

@RestResource(urlMapping='/API_Code/*')
global with sharing class API_Code {
        
    public List<Widget__c> widgets {get;set;}
    
    public API_Code(ApexPages.StandardController stdController)
    {        
    }
    
    @HttpGet
    global static List<Widget__c> getWidgets() 
    {
        List<Widget__c> widgets = [SELECT Name from Widget__c];
        
        system.debug('widgets :- ' + widgets);
        
        return widgets;
    } 

    @HttpPost 
    global static String createNewWidget(String Name) 
    {
        Widget__c w = new Widget__c();
        w.Name = Name;
        insert w;

        return 'Done';
   }

    @HttpDelete
    global static String deleteWidgetById() 
    {
        String Id = RestContext.request.params.get('Id');
        List<Widget__c> w = [ Select ID from Widget__c where Id= :Id];

        delete w;

        return 'Deleted Widget';
    }

    @HttpPut
    global static String updateWidget(String Id, String NewName) 
    {
        Widget__c w = [ Select ID, Name from Widget__c where Id= :Id];

        w.Name = NewName;
        update w;

        return 'Widget Updated';
    }
}

I need to call  above Web API method in to my another Apex Class. Can some one described how i can call this.

I Just need to call web api method from Another Apex Class.

Like Web API class is  : global with sharing class API_Code.
and call from the another class : global with sharing class API.

I have tried by its showing me error like :
Return type of an Apex action method must be a PageReference. Found: visualforce.el.VisualforceArrayList .
Ankit Arora 29Ankit Arora 29
@Tom Simmons
Hi Tom,

I have the same scenario as you.

I need some help. I want to integrate Salesforce with some other company. They have provided me documentation with the following details:

Server URL,
Test API page URL,
API for create, read, delete and update.

I have API Create in JSON format. I don't have any endpoint URL that I can use in the Apex code. I am not sure what I need to do with these APIs. I am this integration for the first time.

Let's say once I create a user who will attend this event, I want to display this user in salesforce on some vf page that this person attended the event.

I checked online but everyone is using endpoint URL and I have only server URL.

Please help me.
Thank you

Regards,
Ankit