+ Start a Discussion
Nagaraj SVNagaraj SV 

Getting Bad request Error .Please Help ?

In the below code i am calling third party API and iam sending request but i am getting error like Bad Request.
This is the URL third party given for reference 
https://lipack.legalintake.com/#outboundHeaders
​Can any one help it's urgent ..
public class LIPOutboundCntr{
    public String apiKey {get;set;}
    public String firstName {get;set;}
    public String lastName { get; set; }
    public String result { get; set; }
    public String email{ get; set; }
    public String phoneNumber{ get; set; }
    public String encryption{ get; set; }
    
    public String RestRequest(String body,String endPoint,String method){
        
        String ReqString = 'YSX28ygFl1UaIqSKx1Sp2w==ApiKey'+apiKey+'FirstName'+firstName+'LastName'+lastName+'Email'+email+'PhoneNumber'+phoneNumber+'Encryption'+encryption;
        System.debug('ReqString============================>'+ReqString);
        Blob Blobedstring = Blob.valueOf(ReqString);
        System.debug('Blobedstring============================>'+Blobedstring);
        String FormHash = EncodingUtil.base64Encode(Blobedstring);
        System.debug('FormHash============================>'+ FormHash);
        String bbody=body.removeEnd('}');
        System.debug('bbody============================>'+bbody);
        
        String hashBody=bbody+',"FormHash"'+':'+'"'+FormHash+'"'+'}';
        System.debug('hashBody============================>'+hashBody);
        
        Http h=new Http();
        HttpRequest req = new HttpRequest();
        req.setMethod(method);
        req.setHeader('content-type','application/json');
         
        req.setEndPoint(endPoint);
        req.setBody(hashBody);
        
        HttpResponse res = h.send(req);
        result = res.getBody();
        System.debug('result================================================>'+result);
        return null;
    }
    public void getTex(){
        String texString = createTexRequestBody();
        RestRequest(texString ,'https://lipack.legalintake.com/qa/api/outbound','POST');
    }        
    public String createTexRequestBody(){
        
        JSONGenerator gen= JSON.createGenerator(true);
        gen.writeStartObject();
        gen.writeStringField('ApiKey',apiKey);
        gen.writeStringField('FirstName',firstName);
        gen.writeStringField('LastName',lastName);
        gen.writeStringField('Email',email);
        gen.writeStringField('Encryption',encryption);
        gen.writeEndObject();
        
        System.debug('gen.getAsString()================================================>'+gen.getAsString());
        return gen.getAsString();  
        
    }
    public class Jsonparsercls{  
        public String totalTax{get;set;}
        
        
    }
}