Forwarding response to separate address

Hi there!

Love the tool, it’s super-useful. I have a usecase that I’ve not been able to create a solution for.

For an api request on a website, I’d like to allow the call to respond to the page, but also forward the response to an external webhook url for logging.

I believe it’s similar to the redirect function, but forwarding instead. Is this something that’s possible?

Thanks!
Rob

2 Likes

Thanks, @rob for creating the ticket, This should be possible with our Modify Response rule. You should choose the Programmatic response option and in the code editor, you can make an AJAX call and forward the response to your desired API endpoint.

Here’s an example of sending a fetch request with POST - javascript - Fetch: POST JSON data - Stack Overflow

function modifyResponse(args) {
  const {method, url, response, responseType, requestHeaders, requestData, responseJSON} = args;

  console.log('++++ API Request Intercepted', args);

  fetch('WEBHOOK_ENDPOINT', {
    method: 'POST',
    headers: {
      'Accept': 'application/json, text/plain, */*',
      'Content-Type': 'application/json'
    },
    body: response
  });
  
  return response;
}

Here’s a sharedList I created for you - Requestly - Lightweight Proxy to Intercept & Modify HTTP(s) requests

You can directly open above link and click on Import button. However, My only question here is that your WEBHOOK endpoint does handle CORS or not.

1 Like

With the above solution, you might get a content-security-policy restriction error. If you get that, then you can use the following rule - Requestly - Lightweight Proxy to Intercept & Modify HTTP(s) requests

Please open the above link and Import the rule.

Thanks Sachin - this worked perfectly, and I really appreciate the quick help in here and the live chat. You’re the man!

1 Like