Search code examples
javascripthtmlrestoutlookribbon

REST API call from html not working


I am trying call a REST API post function from a script embedded into my html file. The button isn't working for some reason and no online resources have helped me thus far. This html code will be sent via email, and person using outlook with open the email and click the link to call the rest api.

Here is the html code:

<a href="#" onclick="markAsDone();" target="_blank" style="font-size: 16px; font-family: Helvetica, Arial, sans-serif; font-weight: normal; color: #ffffff;    text-decoration: none; display: inline-block;">I am done. &rarr;</a>
<script type="text/javascript">
function markAsDone() {
    var xhttp = new XMLHttpRequest();
    xhttp.open("POST", "http://localhost:1337/UserDone", false);
    xhttp.sendRequestHeader("Content-type", "application/json");
    xhttp.send();
}
</script>

Am I doing something wrong or is outlook not compatible for emails containing html with links like this?


Solution

  • I think email clients do not support the use of Javascript. I suggest you to create a normal link in the email, e.g. to http://example.com/email/index.php, and make the API call there.