I receive a 422 error executing a POST request with Google Script to Airtable. Payload works in Postman. Example:
let recordSet = {records: [{fields: {address: 'demo', keyValue: '5678'}}]};
let config = {method: 'post', contentType: 'application/json', payload: JSON.stringify(recordSet)};
UrlFetchApp.fetch('https://api.airtable.com/v0/appID/TableName', config);
What’s wrong?
In my experience working with Airtable and Google Apps Script, a common oversight causing a 422 error is the omission of the proper authorization headers. When I encountered similar issues, adding the API key as a header using the ‘Bearer’ scheme to your configuration was essential. It is also important to verify that your field names exactly match those in your Airtable base. Tweaking these two areas—ensuring the correct authentication and aligning your payload structure—ended up resolving the issue in my setup.
I encountered a similar issue when working with POST requests to Airtable using Google Apps Script. In my case, the error was not in the payload structure itself but in subtle differences between the field names defined in the payload and those actually present in the Airtable base. Additionally, I overlooked fully setting up the necessary headers, especially the Authorization header with the API key. Rigorously matching the field names to your Airtable schema and ensuring that each required header is correctly formatted resolved my issue. Reviewing the API documentation closely for any version-specific requirements also proved quite valuable.