PLEASE NOTE: This script is provided to help you get started. Unfortunately, our free support does not include custom scripts. Any competent JS developer should be able to manipulate this script for your needs. Please contact us if you need help to find a developer. Please thoroughly test before use.

BACKGROUND

  • In some cases you may want to send a Webhook/API call in the background.
  • This can be accomplished by using an AJAX request.

Create a node level script to look like this:

Then copy/paste this code:

<script>
var url = "https://webhook.site/1868ac28-8bb7-4062-87b9-047ac59f2c3d";
var params = "first_name={first_name}";
var xhr = new XMLHttpRequest();
xhr.open("POST", url, true);

//Send the proper header information along with the request
xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");

xhr.send(params);
console.log("request sent!");
</script>
  • The ‘url’ variable must be changed to your target server
  • The ‘params’ variable is where you add your body. The same format applies as when using the webhook/api nodes. In this example we specify key/value pairs separated by &. For example: “first_name={first_name}&last_name={last_name}”.
  • The third parameter of the open function declares this request be ‘true’ as an asynchronous request. So that it fires in the background.
  • The setRequestHeader again is the same as the webhook/api node. You can use application/json, application/xml, etc. Just bear in mind that your params format will need to match.

Download Demo here:

Leave a Reply

Your email address will not be published. Required fields are marked *