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
suji srinivasansuji srinivasan 

Hi, I got space error as response in org to org integration callout using REST API?

sourceorg:
public class LeadInfoRestAPI {
    public static void getLeadInfo(){
        HttpRequest req = new  HttpRequest();
        req.setEndpoint('https://abccom703-dev-ed.my.salesforce.com/services/oauth2/token?grant_type=password&client_id=3MVG9fe4g9fhX0E6mT.C7abEpUyc09UVggmNHPjPmuN6B93fDcKaryyx5Ro5MvBzm.XrNRa7un0kxRV0Xo2.S&client_secret=74A03DB8307235BDC86113B9130E9F6CBBE0C3B24D60A91B7D169EDBE07BD277&username=test@abc.com&password=Test3@');
        req.setMethod('POST');
        Http http = new Http();
        HttpResponse res = new HttpResponse();
        res = http.send(req);
        system.debug('response--------'+res.getBody());
        Oauth objAuthInfo = (Oauth)JSON.deserialize(res.getBody(),Oauth.class);
        system.debug('objAuthInfo--------'+objAuthInfo);
        if(objAuthInfo.access_token !=null){
             HttpRequest req1= new  HttpRequest();
             req1.setEndpoint('https://abccom703-dev-ed.my.salesforce.com/services/apexrest/LeadInfo/00Q5g000008TNrGEAW?Content-Type=application/json&Authorization=Bearer 00D5g00000DguX0!ARkAQE3pNrJvOeLrIVw7ym0QDquIRUuHtnZ8.WEujlQ1iF.PRwrrZO_8PeWKxB7wNKi3M9YVGGe2SsvxHH6ra6KpWWmMevzK');
             req1.setMethod('GET');
             req1.setHeader('Content-Type', 'application/json');
             req1.setHeader('Authorization','Bearer '+objAuthInfo.access_token);
             Http http1 = new Http();
             HttpResponse res1= new HttpResponse();
             res1 = http.send(req1);
             
             system.debug('LeadInfo--------'+res1.getBody());
        }}
    
    public class Oauth{
         public string access_token{get;set;}
         public string instance_url{get;set;}
         public string id{get;set;}
         public string token_type{get;set;}
         public string issued_at{get;set;}
         public string signature{get;set;}
    }

ERROR:


|DEBUG|LeadInfo--------<h1>Bad Message 400</h1><pre>reason: Illegal character SPACE=' '</pre>

can anyone guide me where i missed out ?

Thanks in advance.

SwethaSwetha (Salesforce Developers) 
HI Suji,
Can you replace setheader line as below and see if that helps?

req1.setHeader('Authorization', 'Bearer ' + objAuthInfo.access_token);

Related: https://salesforce.stackexchange.com/questions/175691/http-1-1-400-illegal-character-0x20-for-the-bulk-api-request

If this information helps, please mark the answer as best. Thank you
suji srinivasansuji srinivasan
Hi swetha ,
I am getting response in postman, In apex callout ,   Iam getting the same error  .