{"code":8022,"message":"Missing 'application-id' header"}

I have a set of hosted html pages and associated scripts. I copied the files to a new directory structure . After copying the files when trying to run one of the scripts I am getting a Bad Request: 400 error with detail of

{“code”:8022,“message”:“Missing ‘application-id’ header”}.

Here is the script from the html file that requests a separate script file and is producing the error. The same set of pages worked fine before I copied them to the new directory structure. I have made all the necessary updates in the files to reflect the new directory paths. I don’t see why I am getting the missing application-is error when the app id is in the URL for the request and I have not changed the app id.

uploadChallenges = function() {

var resultDiv = $("#resUploadChallenges");
resultDiv.html("");
var challenge_file_name = document.getElementById('challenge_file_name').value;
console.log (challenge_file_name);

$.ajax({
    url: window.location.protocol + "//api.backendless.com/B75DC8E3-A4F2-255C-FF29-BE5B2377B400/v1/files/web/FuTr/scripts/upload_challenges.js",
    type: "POST",
    data: '{"fileName":"' + challenge_file_name + '"}',
    contentType: "application/json",
    success: function (result) {
        resultDiv.html("<strong>Response:</strong><br>"+JSON.stringify(result));
    },
    error: function (xhr, ajaxOptions, thrownError) {
        alert(xhr.status);
        alert(thrownError);
    }
});

}

Here is the request from the browser console:
POST /B75DC8E3-A4F2-255C-FF29-BE5B2377B400/v1/files/web/FuTr/scripts/upload_challenges.js HTTP/1.1
Host: api.backendless.com
Connection: keep-alive
Content-Length: 38
Accept: /
Origin: https://api.backendless.com
X-Requested-With: XMLHttpRequest
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.85 Safari/537.36
Content-Type: application/json
Referer: https://api.backendless.com/B75DC8E3-A4F2-255C-FF29-BE5B2377B400/v1/files/web/FuTr/index.html
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.8

It says it is missing the application-id HTP header.

You could try something like this:

$.ajax({
// all your other code here....
beforeSend: function (request)
{
request.setRequestHeader("application-id", app_id_value);
}
});

Regards,
Mark

Hi Mark I added what you suggested. I still get a bad request error but this time with the detail of:

{“code”:6010,“message”:“Corrupted multipart request. Header Content-Type must be set to value multipart/form-data”}

I updated the request to have the multipart/form-data content-type but am still receiving the same error. Here is what the request looks like now:

$.ajax({
url: window.location.protocol + “//api.backendless.com/B75DC8E3-A4F2-255C-FF29-BE5B2377B400/v1/files/web/FuTr/scripts/upload_challenges.js”,
type: “POST”,
data: ‘{“fileName”:"’ + challenge_file_name + ‘"}’,
contentType: “multipart/form-data”,
success: function (result) {
resultDiv.html("<strong>Response:</strong><br>"+JSON.stringify(result));
},
error: function (xhr, ajaxOptions, thrownError) {
alert(xhr.status);
alert(thrownError);
},
beforeSend: function (request) {
request.setRequestHeader(“application-id”,“B75DC8E3-A4F2-255C-FF29-BE5B2377B400”);
}
});

Your “data” field is not properly formatted. Perhaps these will help:

http://stackoverflow.com/questions/20795449/jquery-ajax-form-submission-enctype-multipart-form-data-why-does-contentthttp://stackoverflow.com/questions/5392344/sending-multipart-formdata-with-jquery-ajax

Still struggling to get this working. But while I continue to work on it I would like to understand why creating a new copy of my pages/script in a new directory would cause these issues? As mentioned in the initial post the pages & script were working in their original location, when I created new copies in new directories I updated any path references in the new files and at that point I would expect them to just work. Why would moving the files to a new location start to cause these issues with the request format? it seems totally unrelated.

Hi, Greg,
Are you trying to invoke hosted node.js script?

Hi Greg!
We think that new location was not correctly specified:
nodejs scripts works only in web/scripts/… location.
In other folders nodejs scripts will not be executed.
Regards,
Kate.

Thank you Kate. I did not realize that. The new directory structure I created was outside of web/scripts. I will create a new structure back under web scripts and see if things start working again.