I’m trying to send data to my Airtable base using Google Apps Script but keep getting a 422 error. The same request works perfectly in Postman but fails in my script.
Here’s my current code:
var recordData = {
"records": [
{
"fields": {
"Wallet Address": "sample_value",
"0x1a2b3c4d5e6f7890abcdef1234567890abcdef12": "5678"
}
}
]
};
var requestOptions = {
"method": "post",
"Content-Type": "application/json",
"muteHttpExceptions": true,
"payload": JSON.stringify(recordData)
};
function sendToAirtable() {
var apiUrl = "https://api.airtable.com/v0/appxxxxxxxxxx/Token%20Records?api_key=keyxxxxxxxxxx";
var result = UrlFetchApp.fetch(apiUrl, requestOptions);
console.log(result.getResponseCode());
}
The response code I get is 422 and no data appears in my Airtable. When I test the exact same payload in Postman it works fine. What could be causing this issue with my Google Apps Script implementation? I’ve tried both stringifying the payload and sending it as an object but neither approach works.
I’ve hit this exact problem before. You’re setting headers wrong in Google Apps Script.
Don’t put Content-Type directly in the options object - it needs to go inside a headers object:
var requestOptions = {
"method": "post",
"headers": {
"Content-Type": "application/json",
"Authorization": "Bearer YOUR_API_KEY"
},
"muteHttpExceptions": true,
"payload": JSON.stringify(recordData)
};
Also, don’t put your API key in the URL. Move it to the Authorization header. Your URL should just be:
var apiUrl = "https://api.airtable.com/v0/appxxxxxxxxxx/Token%20Records";
Wasted hours debugging this same mistake last year. Google Apps Script is picky about header format and Airtable prefers Bearer tokens over URL parameters.
This should fix your 422 error.
The 422 error means there’s a validation issue with your field names or data types. The hex string you’re using as a field name is likely causing problems, as Airtable is strict about field naming. First, double-check that long hex field name actually exists in your base exactly as written, considering that field names are case-sensitive. If you just created or renamed fields, there might be a mismatch. Secondly, ensure the data types you’re sending match what Airtable expects. If Airtable needs a number but you send a string, you’ll encounter a 422 error. Try converting ‘5678’ to an integer if that field expects numeric data. Additionally, log the full error response by changing your console.log to console.log(result.getContentText());. This will show you the specific rejection message from Airtable, making debugging easier than only seeing the 422 code.
Double-check your Airtable base ID and table name in the URL. When you copy from the browser, it sometimes grabs the wrong base ID. Also verify your field names match exactly - spaces and caps matter. I ran into the same thing and it turned out to be a typo in the field name that worked fine in Postman but broke in GAS.
Had the same issue moving from Postman to Google Apps Script. Your problem is likely URL encoding - “Token%20Records” might be getting double-encoded since you’re manually encoding the space but Google Apps Script does it automatically. Try the unencoded version: “https://api.airtable.com/v0/appxxxxxxxxxx/Token Records”. Also check your Airtable base permissions for API access. Postman and scripts sometimes handle authentication differently, so what works in one might fail in the other. Add some error logging to capture the actual response body, not just the status code - you’ll get way more useful info about what Airtable’s actually rejecting.