I’m trying to send data to Airtable using Google Apps Script but keep getting a 422 error. The same request works fine when I test it in Postman, so I think there’s something wrong with how I’m setting up the request in my script.
Here’s what I have so far:
var payload = {
"records": [
{
"fields": {
"Project Name": "demo",
"0x9af2c8d12b95e78dc456ff23bc987654321abcde": "5678"
}
}
]
};
var requestOptions = {
"method": "post",
"Content-Type": "application/json",
"muteHttpExceptions": true,
"payload": JSON.stringify(payload)
};
function sendDataToAirtable() {
var apiUrl = "https://api.airtable.com/v0/xxxxxxxxxxxxx/Data%20Storage?api_key=keyxxxxxxxxxx";
var result = UrlFetchApp.fetch(apiUrl, requestOptions);
console.log(result.getResponseCode());
}
The console shows 422 as the response code and nothing gets added to my Airtable base. When I use the exact same payload in Postman it works perfectly. I’m pretty sure the API key and base ID are correct since other GET requests work fine.
Any ideas what could be causing this issue with the POST request?