Help

Save the date! Join us on October 16 for our Product Ops launch event. Register here.

422 Error with XMLhttprequest

Topic Labels: Base design
1362 1
cancel
Showing results for 
Search instead for 
Did you mean: 
Mohammed_Emun
4 - Data Explorer
4 - Data Explorer

I am trying to use XML to get and update information from my Airtable. I am doing the following for POST to update a value but I keep getting error 422. I am doing a very similar process for GET and it works, but not for POST.

function httpPost(BaseID,tablename, APIKey){
    var xmlHttp = new XMLHttpRequest();
    var url = "https://api.airtable.com/v0/" + BaseID + "/" + tablename +"/";
    var propValue = {
        "id": "recIYykIMqJGcvNNi",
        "fields": {
          "Variables": "Test 1",
          "Value": "136"
        }
      }
  
xmlHttp.open('POST', url, false);
xmlHttp.setRequestHeader('Content-type','application/json');
xmlHttp.setRequestHeader('Authorization',"Bearer " + APIKey);

xmlHttp.onreadystatechange = function() {
if(xmlHttp.readyState == 4 && xmlHttp.status == 200) {
        console.log(xmlHttp.responseText);
    }
console.log(xmlHttp.status)
};
xmlHttp.send(JSON.stringify(propValue));

}

1 Reply 1

According to the API docs, POST is for creating records. When updating records, it should be either PATCH or PUT, depending on the situation. Review the API docs for more details.