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
rajesh_yrajesh_y 

webservice call out

 
 
public class lll {
public string errormessage;
 public void Login()
    {
        
        ErrorMessage='';
       final string baseUrl = 'http://dskvapconsultancyservices.createsend.com/'; 
        final string username = '05b88f78dfc4f00ce93553a79be93d04'; 
        final string password = 'rajesh12';
       
  string apikey='05b88f78dfc4f00ce93553a79be93d04';
     Blob headerValue = Blob.valueOf(username + ':' + password);
     String authorizationHeader = 'BASIC ' +
     EncodingUtil.base64Encode(headerValue);
     req.setHeader('Host','http://dskvapconsultancyservices.createsend.com/');

    req.setHeader('Authorization',authorizationHeader);
  //req.setHeader('content-type', 'text/xml;charset=utf-8');
  //req.setHeader('Content-Length','1024');
  //req.setHeader('Host','http://dskvapconsultancyservices.createsend.com/');
  //req.setHeader('Connection','keep-alive');
        
        Http h = new Http();
        HttpRequest req = new HttpRequest();
        req.setMethod('GET');
        //req.setEndpoint(baseUrl + '?loginType=&un='+username+'&pw='+password);
       //req.setEndpoint('http://api.createsend.com/05b88f78dfc4f00ce93553a79be93d04/v3/clients/clients.xml');
        req.setEndPoint('http://api.createsend.com/api/v3/clients.xml?='+apikey);
        //req.setbody('http://api.createsend.com/api/v3/clients.xml');
    
        
        HttpResponse res = h.send(req);
         //req.setEndpoint(baseUrl + 'apex/UploadFile_DifferentOrg');
           
           res = h.send(req);
           system.debug('********'+res.getbody());
           if (res.getBody().indexOf('success=true')>-1)
           {
              system.debug('Success');
           }  
        }
}

 HI I am using this code to connect campaign monitor 

bit i am getting error  that null pointer defference

please let me know the actual way to headers and endpoint and body 

please expain how to set and what to set in headers for basic authorization

 

 

 

thank you in advance


 

 

Shashikant SharmaShashikant Sharma

I think you are not getting response

res = h.send(req);//res is null so in next statement it gives attempt to deref a null error
system.debug('********'+res.getbody());
           

 See this for more : http://www.forcetree.com/2010/06/http-callout-from-apex-class-simple.html

 

 

SuperfellSuperfell

On which line? you seem to be trying to set the header before you've created the req object.

rajesh_yrajesh_y

Hi thank you for your interest 

 

i am getting following area..

 

 

req.setHeader('Authorization',authorizationHeader);

 

  req.setHeader('Host','http://dskvapconsultancyservices.createsend.com/');
 req.setHeader('Authorization',authorizationHeader);

 

final string username = '05b88f78dfc4f00ce93553a79be93d04'; 
        final string password = 'rajesh12';
       
  string apikey='05b88f78dfc4f00ce93553a79be93d04';
     Blob headerValue = Blob.valueOf(username + ':' + password);
     String authorizationHeader = 'BASIC ' +
     EncodingUtil.base64Encode(headerValue);
     req.setHeader('Host','http://dskvapconsultancyservices.createsend.com/');