REST API call to Octopus using Javascript


I was trying to create a web page for my company which requires me to get some data from Octopus. I tried to use JavaScript to make REST API calls. But I get an error “Failed to load resource: the server responded with a status of 404 (Not Found)”. The same API call works in postman, but returns an error in the browser. Below is the sample JavaScript code for reference. Please let me know if there is something I need to add or change to get the data.

var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
};“GET”, “”, true);
xhttp.setRequestHeader(“X-Octopus-ApiKey”, “API-ABCD123EFG”);

Thank you for looking into this.

Hi Monuica,

Sorry to see you are having this issue.

The error was telling you:

Missing required request header. Must specify one of origin, x-requested-with.

By adding this into the SetRequestHeader, you will be able to get the API results.

var xhttp = new XMLHttpRequest();
    xhttp.onreadystatechange = function() {
    if (this.readyState == 4 && this.status == 200) {
    };"GET", "", true)
    xhttp.setRequestHeader("X-Octopus-ApiKey", "API-abc123456789", "origin", "x-requested-with");

I would look at this guide here for further information. I found it very useful to understand how the calls are made :

By looking at the Documentation for Cors-Anywhere, it will give you a better understanding of how these calls are made:

I hope this information has been useful to you.

If you require any further assistance, please feel free to reach out.

Kind regards,

Hi Ziaul,

I still get the same error “Missing required request header. Must specify one of: origin,x-requested-with” even after changing the SetRequestHeader to xhttp.setRequestHeader(“X-Octopus-ApiKey”, “API-abc123456789”, “origin”, “x-requested-with”); please let me know how to proceed.


Hi Mounica,

Sorry to see the issue is persisting,

Could you tell me which browser you are using to run this on?

I’ve done some further testing for this issue here.

The first thing that comes to my mind when I look at the code you have sent to me I’m not sure if this was done inside this forum, but the quote marks which are typically associated with java-script do not look like:


but rather look like this:


it’s a subtle difference which could cause an error.

Could you please confirm if the quote marks around within the java-script code are correct?

I look forward to your response.

Kind regards,

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.