Jump to content

POST to an external API

Recommended Posts

I would like to calculate number of trees to be planted per transaction and POST to https://offset.earth/ API. Would also like to show to customers in the order confirmation how many trees they planted for this transaction.

would anyone know how to achieve this in squarespace?

Thanks in advance

Edited by eranga
Link to comment
  • Replies 1
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

<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

Create an account or sign in to comment

You need to be a member in order to leave a comment

×
×
  • 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.