Not understanding why I am getting this error if I check this URL in Soap UI it is working perfectly. Getting this error after setting body 'Input is not valid JSON at character 1 of '

public static void request(String S,String cd) {
        string customer_code=cd; 
        String SalesOrganization=s;   
        String username ='****';
        String password ='*****';
        string payload='[{"SalesOrganization"  : "solidealusa","customer_code"  : "CS000023"}]';
        Blob headerValue = Blob.valueOf(username+':'+password);
        String authorizationHeader ='BASIC'+EncodingUtil.base64Encode(headerValue);    

        HttpRequest req = new HttpRequest();    
        req.setHeader('Authorization', authorizationHeader);
        req.setCompressed(false); // otherwise we hit a limit of 32000    
         HttpResponse res = new Http().send(req);     
         system.debug('Response' +res.getBody());          
        } catch(System.CalloutException e) {
        System.debug('Callout error: '+ e);        

Some keywords in web services (SOAP or REST) are case sensitive. For example, Basic, Bearer, Hybrid all should be camel cased (First letter capital and remaining small). Also there should be space between the type of authorization (Basic, Bearer, Hybrid) and the encoded authorization value. So change this

String authorizationHeader ='BASIC'+EncodingUtil.base64Encode(headerValue);


String authorizationHeader ='Basic '+EncodingUtil.base64Encode(headerValue);

Hope it helps.

  • Awesome it worked ! But now I am getting this error "Input is not valid JSON at character 17 of SalesOrganization=solidealusa&customer_code=CS000023"" when i am testing from anonymous block – Salesforce Learner Apr 4 '16 at 14:37
  • I guess you need to formulate JSON and then set it to body of the request. The way you are setting the body now it like passing encoded parameter values which your receiver rejects. I would suggest you to post it as a separate question to attract more quality answers. – Vigneshwaran G Apr 4 '16 at 14:42
  • Thanks I have updated the question ..followed same process but still I could get the error. – Salesforce Learner Apr 4 '16 at 14:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.