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
punnoosepunnoose 

cant connect to hoover s Api (Urgent)

i am having trouble getting connection Hoovers Api, i have given accesss to http://hapi.hoovers.com

In this i am getting exception-------------------  System.HttpResponse[Status=Forbidden, StatusCode=403]

 

Please do respond urgently

 

Heres my code i got it fromlink::::

http://boards.developerforce.com/t5/forums/forumtopicprintpage/board-id/apex/message-id/77643/print-single-message/true/page/1

 

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);

 

 

 

 

Regards

Punnoose

Anup JadhavAnup Jadhav

Error Code 403 indicates that access to the intended resource is not allowed.

 

According to wikipedia:

 

"n the HTTP used on the World Wide Web, 403 Forbidden is an HTTP status code returned by a web server when a user requests a web page or media that the server does not allow them to access. In other words, the server can be reached, but the server declined to allow access to the page. This response is returned by the Apache web server when directory listings have been disabled. Microsoft IIS responds in the same way when directory listings are denied."

 

There are several reasons for this error code:

1. You are successfully authenticated but are not authorized to access the resource.

2. There was a temporary problem on the server, and might work after some time.

 

Most likely it's 1. I'd double check the API key, and also check your access rights(read/write) for the resource.

 

Regards,

Anup

 

punnoosepunnoose

Hi i double checked the api key it correct. How do i check the acess right of the resource

Regards

Punnoose

Nick00000Nick00000

any reason for making SOAP request by hand, instead of genrating Apex from the WSDL?

punnoosepunnoose

 

Initially  when i parsed hoovers wsdl i had problems with <group> ,i fixed that. After that I was getting schema exceptions while i tried to generate classes form wsdl. Started to work in salesforce this month only.Bit stuck up. not much help from internet. If do u know any link which gives the the wsdl which does not have any errors in hoovers schema.

Punnoose