Jump to content

POST to an external API

Recommended Posts

  • Replies 1
  • Views 466
  • Created
  • Last Reply
<script>
    var xhttp = new XMLHttpRequest();
        xhttp.onreadystatechange = function () {
                if (this.readyState == 4 && this.status == 200) {
                    alert(this.responseText);
                }
            };
            xhttp.open("POST", "TARGET URL", true);
            xhttp.setRequestHeader("Content-Type", "application/json");
            xhttp.setRequestHeader("Authorization", "AUTHORISATION ID);
              var num =  1;  //send a random number
            xhttp.send('{"number": ' + num + '},{"test": true}');
  
</script>

I managed to figure this out with help. Hope this will help someone. I injected the above code to order confirmation.

Link to comment

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Squarespace Webinars

Free online sessions where you’ll learn the basics and refine your Squarespace skills.

Hire a Designer

Stand out online with the help of an experienced designer or developer.