Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
Advanced Search
  • 0
eranga

POST to an external API

Question

Posted (edited)

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

Share this post


Link to post

1 answer to this question

Recommended Posts

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

Share this post


Link to post

Create an account or sign in to comment

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


×
×
  • Create New...