• Wai Ming Fong 33
  • 10 Points
  • Member since 2016

  • Chatter
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
  • 0

Is there a way to view the raw REST API request sent from Salesforce?

I am making a GET request to an external system. I have properly formed the request and successfully connected using the HTTPRequester Firefox addon. The raw request in HTTPRequester looks like this:

GET https://apius.uniprix.com/2_0_1/service/account/?t=6f592bf589bdcb361c8c13224182e75103736e67331a7f4774fe97f577f1d743
Apikey: <apikey>
ip: <ip>
Content-Type: application/json

I have recreated this request in APEX, but I do not get the same response. My APEX code looks like this:

     HttpRequest req = new HttpRequest();
     req.setEndpoint('https://apius.uniprix.com/2_0_1/service/account/?t=' + <token>);
     String API_KEY = <apikey>;
     String API_ADDRESS = <ip>;
     req.setHeader('Apikey', API_KEY);  
     req.setHeader('ip', API_ADDRESS);  
     req.setHeader('Content-Type', 'application/json');  

     System.debug('{ "account":{"username":"'+ <username> +'","token":"'+ <token>+'"}}');
     req.setBody('{ "account":{"username":"'+ <username> +'","token":"'+ <token> +'"}}');
     Http http = new Http();
     HTTPResponse res = http.send(req);

The request does provide a valid response (so the token seems valid). Instead of the 200 code that HTTPRequester returns though, I am getting a 417 code with the message: "Missing data : account->serviceId"

This leads me to think that the request is being processed as a "POST" instead of a "GET" so I would like to see the raw REST request being sent out from Salesforce.

Open to any ideas.