• Xavier Roig
  • NEWBIE
  • 0 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies

Apex Rest Callout GET Method with parameters 

I need to call a GET web service method that contains parameters to be passed along.
When I m calling that from POSTMAN with the access token,etc.. I m getting response
Postman Call

https://apiabcdef.test.abcdexyz.com/api/tcUser?Query=UserCode = 'USER_0706'

But when I m calling this from Apex it is giving a bad request error. code below
 

public static HttpResponse getUserIDFromTCheck(String token, string userCode) {       
    //JSONParser parser = JSON.createParser(token); 
        HttpRequest httpReq = new HttpRequest();                                               
        httpReq.setEndpoint( 'https://apibibforceapi.test.tyrecheck.com/api/tcUser?Query=UserCode = \''+userCode+ '\' ');               
        httpReq.setMethod('GET');
        httpReq.setHeader( 'Content-Type', 'application/json' );    
        httpReq.setHeader( 'Authorization', 'Bearer ' + token );        
        Http http = new Http();         
        HttpResponse httpRes = http.send( httpReq );
     //System.debug('#test2 The status code returned from second service : ' + httpRes.getStatusCode() + ' :  ' + httpRes.getStatus());
return httpRes;  
}

this code gives error as  :
getStatusCode  : 400
getStatus : Bad Request

Please let me know is this the right way to call a GET third party webservice.