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 

please help me in http callouts

Hi am using following code in  salesforce
to integrate with campaign monitor.
but i am getting errors like
12:47:38.666 (666977000)|CALLOUT_RESPONSE|[51]|System.HttpResponse[Status=Bad Request, StatusCode=400]

12:47:38.667 (667346000)|USER_DEBUG|[55]|DEBUG|********<?xml version="1.0" encoding="utf-8"?><Result><Code>400</Code><Message>Failed to deserialize your request.
Please check the documentation and try again.
Fields in error: client</Message></Result>


Please solve my problem.


public class lll {

public string errormessage;



 public  void Login()
    { 
     Http h = new Http();
        HttpRequest req = new HttpRequest();
        //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://api.createsend.com');
    req.setHeader('Content-length', '1753' );
    req.setHeader('Content-Type', 'text/xml;charset=UTF-8');
    req.setHeader('Authorization',authorizationHeader);
    //req.setHeader('Authorization','Basic 05b88f78dfc4f00ce93553a79be93d04==');
  //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');
     string body1='<?xml version="1.0" encoding="utf-8"?>';
      body1+='<Clients> ';
      /*body1+='<ApiKey>05b88f78dfc4f00ce93553a79be93d04</ApiKey>';
      body1+='<AccessDetails>';
          body1+='<Username>05b88f78dfc4f00ce93553a79be93d04</Username>';
          body1+='<AccessLevel>23</AccessLevel>';
          body1+='</AccessDetails>';*/
          body1+='<Client>';
          body1+='<ClientID></ClientID>';
          body1+='<Name></Name>';
          body1+='</Client>';
         body1+='</Clients>';   
        
        req.setMethod('GET');
        req.setBody(body1);

        //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');
        //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');
           }  
        }
        
        public void detail()
        {
        
        }
        
        
}

 thank you in advance

rajesh

RonHess.ax193RonHess.ax193

 

I think you need POST

 

req.setMethod('POST');



 

rajesh_yrajesh_y

hi 

same response am getting 

 

now the code is like

public class lll {

public string errormessage;



 public  void Login()
    { 
     Http h = new Http();
        HttpRequest req = new HttpRequest();
        //ErrorMessage='';
        final string baseUrl = 'http://dskvapconsultancyservices.createsend.com/'; 
       //final string username = '05b88f78dfc4f00ce93553a79be93d04'; 
        final string username='rajesh_y';
        final string password = 'rajesh12';
       
  string apikey='05b88f78dfc4f00ce93553a79be93d04';
     Blob headerValue = Blob.valueOf(username + ':' + password);
     String authorizationHeader = 'BASIC ' +EncodingUtil.base64Encode(headerValue);
     //EncodingUtil.urlEncode(headerValue);
     
     //req.setHeader('Host','http://api.createsend.com');
    req.setHeader('Content-length', '1753' );
    
    req.setHeader('Connection','keep-alive');
    req.setHeader('Content-Type', 'application/xml;charset=UTF-8');
    req.setHeader('Authorization',authorizationHeader);
    //req.setHeader('Authorization','Basic 05b88f78dfc4f00ce93553a79be93d04==');
  //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');
     string body1='<?xml version="1.0" encoding="utf-8"?>';
     body1+='<jobInfo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.force.com/2009/06/asyncapi/dataload">';  
      body1+='<Clients> ';
      body1+='<ApiKey>05b88f78dfc4f00ce93553a79be93d04</ApiKey>';
      body1+='<AccessDetails>';
          body1+='<Username>rajesh_y</Username>';
               
            body1+='<Password>rajesh12</Password>';
              
          body1+='<AccessLevel>23</AccessLevel>';
          body1+='</AccessDetails>';
          body1+='<Client>';
          body1+='<CompanyName>My Company</CompanyName>';
          body1+='<ContactName>John</ContactName>';
          body1+='<EmailAddress>john@example.com</EmailAddress>';
         body1+='<Country>Australia</Country>';
      body1+='<TimeZone>(GMT+10:00) Canberra, Melbourne, Sydney</TimeZone>';
          body1+='</Client>';
         body1+='</Clients></jobInfo>';   
        
        req.setMethod('GET');
        req.setBody(body1);
          req.setCompressed(true);
        //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');
        //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');
           }  
        
    
        }
        
        public void detail()
        {
        
        }
        
        
}

 the error is |System.HttpResponse[Status=Moved Temporarily, StatusCode=302]

</body></html>

DEBUG|********<html><head><title>Object moved</title></head><body>
<h2>Object moved to <a href="https://api.createsend.com/">here</a>.</h2>

 

i need to get details 

how its possible

please help me 

rajesh_yrajesh_y

hi 

same response am getting 

 

now the code is like

public class lll {

public string errormessage;



 public  void Login()
    { 
     Http h = new Http();
        HttpRequest req = new HttpRequest();
        //ErrorMessage='';
        final string baseUrl = 'http://dskvapconsultancyservices.createsend.com/'; 
       //final string username = '05b88f78dfc4f00ce93553a79be93d04'; 
        final string username='rajesh_y';
        final string password = 'rajesh12';
       
  string apikey='05b88f78dfc4f00ce93553a79be93d04';
     Blob headerValue = Blob.valueOf(username + ':' + password);
     String authorizationHeader = 'BASIC ' +EncodingUtil.base64Encode(headerValue);
     //EncodingUtil.urlEncode(headerValue);
     
     //req.setHeader('Host','http://api.createsend.com');
    req.setHeader('Content-length', '1753' );
    
    req.setHeader('Connection','keep-alive');
    req.setHeader('Content-Type', 'application/xml;charset=UTF-8');
    req.setHeader('Authorization',authorizationHeader);
    //req.setHeader('Authorization','Basic 05b88f78dfc4f00ce93553a79be93d04==');
  //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');
     string body1='<?xml version="1.0" encoding="utf-8"?>';
     body1+='<jobInfo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.force.com/2009/06/asyncapi/dataload">';  
      body1+='<Clients> ';
      body1+='<ApiKey>05b88f78dfc4f00ce93553a79be93d04</ApiKey>';
      body1+='<AccessDetails>';
          body1+='<Username>rajesh_y</Username>';
               
            body1+='<Password>rajesh12</Password>';
              
          body1+='<AccessLevel>23</AccessLevel>';
          body1+='</AccessDetails>';
          body1+='<Client>';
          body1+='<CompanyName>My Company</CompanyName>';
          body1+='<ContactName>John</ContactName>';
          body1+='<EmailAddress>john@example.com</EmailAddress>';
         body1+='<Country>Australia</Country>';
      body1+='<TimeZone>(GMT+10:00) Canberra, Melbourne, Sydney</TimeZone>';
          body1+='</Client>';
         body1+='</Clients></jobInfo>';   
        
        req.setMethod('GET');
        req.setBody(body1);
          req.setCompressed(true);
        //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');
        //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');
           }  
        
    
        }
        
        public void detail()
        {
        
        }
        
        
}
 the error is |System.HttpResponse[Status=Moved Temporarily, StatusCode=302]
</body></html>
DEBUG|********<html><head><title>Object moved</title></head><body>
<h2>Object moved to <a href="https://api.createsend.com/">here</a>.</h2>

 

 

i need to get details 

how its possible

please help me