Apex REST API Integration with Third party application

Apex REST API Integration with Third party application

In this Example, We are going to see how to integrate Fullcontact API with salesforce through REST webservice

As we are going ahead with Apex REST webservice, response from fullcontact API will be in JSON format.

prerequisite :-

  • You need to sign up in fullcontact.com in order to get API key which we needed during making a webservice call from salesforce.
  • Important thing is we are going ahead with person method with an email parameter to lookup information about a specific person by email from fullcontact API.
  • Person API developer guide overview :- https://www.fullcontact.com/developer/docs/person/
  • Then you need to create a remote site settings in salesforce for that fullcontact.com as shown belowsfdcpanda, salesforce tutorial, salesforce basic integration, salesforce integration, salesforce rest api integration, salesforce rest api
  • When we try to deserialize the specified JSON string, it needs to be deserialized into Apex object of the specified type.
  • In this case, Json data will be coming as List which contains primitive types, so we need to define a wrapper class in salesforce to handle those primitive data types during deserialization and the variables should match during conversion from JSON into Apex understandable format.
  • For managing apex variables in wrapper class, we can use this Json2Apex herokuapp where we can parse Json structure and we can get strongly typed Apex code to handle json primitive data types during deserialization.

Click me to View JSON format for Person API from fullcontact site


Working code


Once you we done with prerequisite, then we need to create two apex class, one to make callout and other apex class to deserialize received JSON from fullcontact site.


Apex class 1:-

public class EmailCallout

    public String requestEndpoint ='https://api.fullcontact.com/v2/person.json?email=din2262@gmail.com';
    public  String requestMethod = 'GET';
    public String requestBody {get;set;}
    public String responseStatus {get;set;}
    public Integer responseStatusCode {get;set;}
    public String responseBody {get;set;}
    public FullContactAPI.responseResource response {get;set;}
    public List<FullContactAPI.SocialProfiles> pd {get;set;}

    public EmailCallout(ApexPages.StandardController controller) {
        httpResponse res = FullContactAPI.callout(requestMethod, requestEndpoint, requestBody);
        responseStatus = res.getStatus();
        responseStatusCode = res.getStatusCode();
        responseBody = res.getBody();
        system.debug('after condition chck deserialize'+ responseBody);


    public void deserializedJSON(){
        if ( string.isNotBlank(responseBody) ){
           response= (FullContactAPI.responseResource)JSON.deserialize(responseBody,FullContactAPI.responseResource.class);
           system.debug('Response.socialprofiles'+ response.SocialProfiles);
           pd = response.SocialProfiles;
              system.debug('condition chck deserialize'+ pd );



Apex class 2 :-

public class FullContactAPI

public static httpResponse callout(String httpMethod, String endpoint, String body)

        httpRequest req = new httpRequest();
        httpResponse res = new http().send(req);
        return res;


    public class responseResource {
    public Integer status {get;set;} 
    public String requestId {get;set;} 
    public Double likelihood {get;set;}  
    public List<SocialProfiles> socialProfiles {get;set;} 
    public class SocialProfiles {
        public Integer followers {get;set;} 
        public String type_Z {get;set;} // in json: type
        public String typeId {get;set;} 
        public String typeName {get;set;} 
        public String url {get;set;} 
        public String username {get;set;} 
        public String id {get;set;} 
        public String bio {get;set;} 
        public Integer following {get;set;} 

Visualforce page :-

<apex:page standardController="Account" extensions="EmailCallout">
<apex:form id="form1">
<apex:sectionHeader title="RESTFUL Email Callout " />
 <apex:pageMessages id="pageMessages" />
 <apex:pageBlock >
 <apex:pageBlockButtons location="bottom" >
 <apex:commandButton value="click me to Deserialize Json" action="{!deserializedJSON}" rendered="{!$CurrentPage.parameters.offline!='1'}"/>


<apex:pageBlockSection title="Raw JSON data from external site" > 
<apex:outputText value="{!responseBody}"></apex:outputText>

<apex:pageBlockSection columns="1" title="Deserialized JSON" rendered="{!pd!= null}" collapsible="false" >
 <apex:pageBlockTable value="{!pd}" var="i" >
 <apex:column headerValue="Social Network User Name" style="width:75px;">
 <apex:outputText value="{!i.username}"/>
 <apex:column headerValue="Social Network User URL" style="width:75px;" >
 <apex:outputLink value="{!i.url}" target="_blank" style="width:100px;">
 <apex:outputText value="{!i.url}" /> 
 <apex:column headerValue="Social Network" style="width:75px;">
 <apex:outputText value="{!i.typeId}"/>




After deserialization:-

apex rest api, salesforce rest api, salesforce integration, rest api integration, salesforce rest api salesforce apex rest,salesforce webservice


  1. Hi, Thankyou so much for your time.
    I tried the above code as per your instructions.
    I have changed my mail id.

    I am getting when I click on Preview ?

    { System.CalloutException: Unauthorized endpoint, please check Setup->Security->Remote site settings. endpoint = https://api.fullcontact.com/v2/person.json?email=s2r6e***@gmail.com
    Class.FullContactAPI.callout: line 10, column 1
    Class.EmailCallout.: line 13, column 1


    Please let me know what wrong i have done.

  2. Hi Dinesh,
    I am not able to understand the fullcontact. Can you give suggestions?
    I am getting like this
    { “status” : 404, “message” : “Searched within last 24 hours. No results found for this Id.”, “requestId” : “5d2da212-bf39-4d60-a29f-1d636d74f6f0” }

Leave a Reply

Your email address will not be published.