1

Is there a way to get the Sender info in a Rest WebService?

for example :

Part A - Sender sends this JSON Via POST Request :

Http httpProtocol = new Http();
HttpRequest request = new HttpRequest();
String url = 'https://SomeDomainURL';

request.setEndpoint(url);
request.setMethod('POST');
request.setHeader('Content-Type','application/json');

String body = '[{"Name":"MyName","LastName":"MyLastName","Age":31}]';
request.setBody(body);

HttpResponse response = httpProtocol.send(request);

Part B - The Receiver of the request

//How can I get here some info about the above sender? URL? Domain? etc..

Every info will be good.

The sender is sending the request from Salesforce so I want to get the URL or Domain from the org he sent the request...

I tried to use this :

RestRequest re = RestContext.request;
System.debug(re.requestURI);
System.debug(re.requestBody);
System.debug(re.headers); 
System.debug(re.remoteAddress); //- This is give me the IP..

But none of this gave me the URL\Domain.

The reason I want to check the URL is to whitelist it, instead of using IP.

BTW - When I checked the "remoteAddress" (re.remoteAddress) I got an Ip number that does not appear over this list: https://help.salesforce.com/articleView?id=000321501&type=1&mode=1

Every help will be grateful.

Thanks!

2
  • IPs are very easy to spoof. Hopefully your service performs authentication and authorization with more than just an IP before rendering the response. – identigral Aug 1 '19 at 18:31
  • Actually, I'm the sender. I just wrote it this way to know how it should work for both sides. Thanks! – Salvation Aug 4 '19 at 12:13
4

Callouts happen from IP and not from URL/Domain. Imagine doing a callout from your personal laptop or mobile device using postman or any other tool, it doesn't have a domain. It will have IP.

Similarly, the IP of Salesforce callout server keeps on changing. I have seen it change quite frequently during the day, and hence its recommended to whitelist the range and not specific ip's.

It can happen that the documentation is outdated, in that case, you have to raise a case with SF. They will help you valid IP range for your instance.

1
  • Thanks for the explanation. – Salvation Aug 4 '19 at 12:12

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.