You need to sign in to do that
Don't have an account?
Wai Ming Fong 33
REST callout - Raw Request
Hi,
Is there a way to view the raw REST API request sent from Salesforce?
Background:
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
{"account":{"username":"<username>","token":"6f592bf589bdcb361c8c13224182e75103736e67331a7f4774fe97f577f1d743"}}
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.setMethod('GET');
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();
System.debug(req);
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.
Thanks,
Ming
Is there a way to view the raw REST API request sent from Salesforce?
Background:
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
{"account":{"username":"<username>","token":"6f592bf589bdcb361c8c13224182e75103736e67331a7f4774fe97f577f1d743"}}
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.setMethod('GET');
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();
System.debug(req);
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.
Thanks,
Ming
Are you sure you don't actually want a POST request so that the body you have defined is sent as well?
If you look in the debug logs you will see the CALLOUT_REQUEST event. The message for this will tell you the Endpoint and Method (GET/POST) that were used.
All Answers
Are you sure you don't actually want a POST request so that the body you have defined is sent as well?
If you look in the debug logs you will see the CALLOUT_REQUEST event. The message for this will tell you the Endpoint and Method (GET/POST) that were used.