+ Start a Discussion
satheeshrsksatheeshrsk 

Salesforce.com connection to Hoover's API through Http Callouts

Hi,

I am trying to make a callout from APEX to an HTTP endpoint(Hoover's API)  but am receiving the following error:

 
 500, internal server error'.

Here is my Apex class :



global public with sharing class HttpCallout_CLS {

    Public static void sendRequest(){
   
    String API_KEY = 'XXX';
   
    String env;
    env =  '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sch="http://applications.dnb.com/webservice/schema/">'+
             '<soapenv:Header>'+
                '<sch:API-KEY>XXX</sch:API-KEY>'+
             '</soapenv:Header>'+
             '<soapenv:Body>'+
               '<sch:FindCompanyByKeywordRequest>'+
                 '<sch:sortDirection>Ascending</sch:sortDirection>'+

                 '<sch:keyword>xyz</sch:keyword>'+

- Hide quoted text -

                 '<sch:searchBy>companyName</sch:searchBy>'+
                 '<sch:returnSearchNavigation>false</sch:returnSearchNavigation>'+
                 '<sch:orderBy xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>'+
                 '<sch:searchNavigation>'+
                   '<sch:employeeSearchNavigation>'+
                   '</sch:employeeSearchNavigation>'+
                   '<sch:ownershipTypeSearchNavigation>'+
                   '</sch:ownershipTypeSearchNavigation>'+
                   '<sch:locationTypeSearchNavigation>'+
                   '</sch:locationTypeSearchNavigation>'+
                   '<sch:salesSearchNavigation>'+
                   '</sch:salesSearchNavigation>'+
                   '<sch:locationSearchNavigation>'+
                     '<sch:countryNavigation>'+
                       '<sch:countryNavigationValue>${#Project#countryNavigationValue}</sch:countryNavigationValue>'+
                       '<sch:stateNavigation>'+
                        '<sch:stateNavigationValue>${#Project#stateNavigationValue}</sch:stateNavigationValue>'+
                        '<sch:cityNavigation>'+
                          '<sch:cityNavigationValue>${#Project#cityNavigationValue}</sch:cityNavigationValue>'+
                        '</sch:cityNavigation>'+
                      '</sch:stateNavigation>'+
                    '</sch:countryNavigation>'+
                  '</sch:locationSearchNavigation>'+
                  '<sch:industrySearchNavigation>'+
                  '</sch:industrySearchNavigation>'+
                '</sch:searchNavigation>'+
              '</sch:FindCompanyByKeywordRequest>'+
            '</soapenv:Body>'+
          '</soapenv:Envelope>';
 
   Http h = new Http();
    HttpRequest req = new HttpRequest();
    req.setEndpoint('http://hapi.hoovers.com/HooversAPI-32');
    req.setMethod('POST');
    req.setBody(env);
    req.setTimeout(12000);
   
    Blob headerValue = Blob.valueOf(API_KEY);

    String authorizationHeader = 'BASIC ' + EncodingUtil.base64Encode(headerValue);
    req.setHeader('Authorization',authorizationHeader);

       
    HTTPResponse res = h.send(req);
    System.debug(res.getBody());
    }
}




  I tried with username and password also, even though i'm facing the same issue. Has anyone experienced anything similar to this?.   Any help must be appreciated.

Thanks Inadvance,
Satheesh
SFDC_dreamforce2010SFDC_dreamforce2010

Hi Satheesh,

 

Were you able to get this to work. Could you please share how were you able to integrate with Hoovers for real time callouts.

 

Thanks!

RSKRSK

Hi,

Here im connected to hoovers by passing account name as input and got the duns and other fields as per my requirements. See the below code

 

 

global with sharing class HttpCallout_CLS{

String Accid = apexPages.currentPage().getParameters().get('id');

Public void sendRequest(){
    String env;
    integer j,k;
    HttpRequest req = new HttpRequest();
    req.setMethod('GET');
    req.setHeader('content-type','text/xml');

    req.setEndpoint('http://hapi.hoovers.com/HooversAPI-32');
    String API_KEY = 'XXXX'; // Use Api Key
    Blob headerValue = Blob.valueOf(API_KEY);
    String authorizationHeader = 'BASIC ' + EncodingUtil.base64Encode(headerValue);
    req.setHeader('Authorization', authorizationHeader);
    String CName = apexPages.currentPage().getParameters().get('Name');

  

              // **** removing special characters from a account name*****
    
    List<String> spl= New List<String>{'@','#','$','%','^','&','*','(',')','!','.','"','<','>','?'};
    List<String> li = New List<String>();
    String CompName='';
    for(j=0;j<CName.length();j++){
      li.add(CName.substring(j,j+1));
     }
    for(j=0;j<CName.length();j++){
        for(k=0;k<spl.size();k++){
            if(li[j]==spl[k]){
                 li[j]=' ';
                 break;           
            }
        }
    }  
   for(Integer l=0;l<li.size();l++){
       CompName = CompName + li[l];
    }

//constucting request body

 env = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sch="http://applications.dnb.com/webservice/schema/">'+
            '<soapenv:Header>'+
              '<sch:API-KEY>xxxx</sch:API-KEY>'+
            '</soapenv:Header>'+
            '<soapenv:Body>'+
              '<sch:FindCompanyByKeywordRequest>'+
              '<sch:maxRecords>100</sch:maxRecords>'+
              '<sch:sortDirection>Ascending</sch:sortDirection>'+
              '<sch:keyword>'+CompName+'</sch:keyword>'+  // search keyword
              '<sch:searchBy>companyName</sch:searchBy>'+
              '<sch:returnSearchNavigation>true</sch:returnSearchNavigation>'+
              '<sch:orderBy>CompanyName</sch:orderBy>'+
              '<sch:searchNavigation>'+
                '<sch:employeeSearchNavigation>'+
                '</sch:employeeSearchNavigation>'+
                '<sch:ownershipTypeSearchNavigation>'+
                '</sch:ownershipTypeSearchNavigation>'+
                '<sch:locationTypeSearchNavigation>'+
                '</sch:locationTypeSearchNavigation>'+
                  '<sch:salesSearchNavigation>'+
                  '</sch:salesSearchNavigation>'+
                  '<sch:industrySearchNavigation>'+
                 '</sch:industrySearchNavigation>'+
                '</sch:searchNavigation>'+
               '</sch:FindCompanyByKeywordRequest>'+
              '</soapenv:Body>'+
             '</soapenv:Envelope>';      

 

     req.setBody(env);  // sending request to the API
    System.debug(req.getBody());     
   Http http = new Http();

   HTTPResponse res = http.send(req);  // getting response from the API

 System.debug(res);

 

Use parsing classes/techniques (XMLNode...) to parse the response

 

Hope this will helps you.

 

 

 

 

VansVans

Hi everyone,

 

I am looking for a salesforce.com support. Please let me know if anyone can provide. my email id is kumar_7191@yahoo.com