As the title said I'm trying to post data but get the response "status":422,"error":"Unprocessable Entity". My code looks as follows:
var data = {};
var confirmData = {};
confirmData['api_token'] = apikey;
confirmData['absence'] = {};
data['api_token'] = apikey;
data['absence'] = {};
data['absence']['absence_type_external_id'] = csv['absencetype'][i];
if(csv['userid'][i] !== undefined){
data['absence']['user_id'] = csv['userid'][i];
} else {
data['absence']['user_external_id'] = csv["externaluser"][i];
}
data['absence']['starts_at'] = getDate(csv["startdate"][i], "10");
data['absence']['ends_at'] = getDate(csv["enddate"][i], "18");
data['absence']['full_day'] = csv["additionalDate"][i] == "" ? true : false;
$.ajax({
url: "https://app.papershift.com/public_api/v1/absences",
type: 'POST',
dataType: 'application/json',
headers: {
"Accept" : "application/json",
"Content-Type": "application/json"
},
data: JSON.stringify(data),
complete: function (rsp) {
console.log(rsp.responseText);
If I'm trying the same code on My local xampp server everything works completely fine, but for security reasons I have to run it locally on a simple html file. If I do that I get the descibed error. I thought this might have something to do with the cross origin policy of my browser, so I started chrome with "--disable-web-security" and as that didn't work I tried different browsers and even a plugin for chrome that disabled the whole cross origin thing, but nothing really worked. I'm not even sure if that is the problem because I don't get any specific errors about it, just the 422. But I'm guessing the data I try to post isn't the problem because everything works just fine when I use it on My local server.