Feb 05, 2023 08:08 AM
Hi everyone! I've recently started using Airtable and absolutely love it ❤️
However, I'm getting an error while trying to use the PATCH request to update a field in my table.
My code is shown below:
UrlFetchApp.fetch('https://api.airtable.com/v0/' + baseID + '/' + tableID + '/' + recordID, {
method: 'PATCH',
headers: {
'Authorization': 'Bearer ' + api_key,
'Content-Type': 'application/json'
},
body: JSON.stringify({
"fields": {
"OpenAI_key": userApiKey
}
})
});
Error message:
Exception: Request failed for https://api.airtable.com returned code 422. Truncated server response: {"error":{"type":"INVALID_REQUEST_MISSING_FIELDS","message":"Could not find field \"fields\" in the request body"}} (use muteHttpExceptions option to examine full response)
Any help will be appreciated
Thanks!
Feb 05, 2023 09:55 PM
Hm, I don't think I've done a PATCH like that before, actually
I usually do it with something like:
UrlFetchApp.fetch('https://api.airtable.com/v0/' + baseID + '/' + tableID + '/', {
method: 'PATCH',
headers: {
'Authorization': 'Bearer ' + api_key,
'Content-Type': 'application/json'
},
body: JSON.stringify({
"records": [
{
"id": recordID,
"fields": {
"OpenAI_key": userApiKey
}
}
]
});
Feb 06, 2023 04:35 AM
Hey @TheTimeSavingCo !
Thanks for the reply. I used this format you suggested but am getting the following error
Exception: Request failed for https://api.airtable.com returned code 422. Truncated server response: {"error":{"type":"INVALID_REQUEST_UNKNOWN","message":"Invalid request: parameter validation failed. Check your request data."}} (use muteHttpExceptions option to examine full response)
Feb 06, 2023 06:27 PM
Hm, if you've verified that the data in the request is fine via Postman or something, then it might be down to something UrlFetchApp is doing?