Help

Upcoming database upgrades. Airtable functionality will be reduced for ~15 minutes at 06:00 UTC on Feb. 4 / 10:00 pm PT on Feb. 3. Learn more here

422 Error with XMLhttprequest

Topic Labels: Base design
625 1
cancel
Showing results for 
Search instead for 
Did you mean: 

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.