DEV Community

Marko Kolombo
Marko Kolombo

Posted on

Airtable POST/PATCH errors solved

After a frustrating evening I finally found out WHY the Airtable API was always rejecting my humble POST/PATCH requests, a.k.a. requests that needed parameters to be sent as body.

I was stuck at some errors:

{“type”:“INVALID_REQUEST_MISSING_FIELDS”,“message”:“Could not find field “fields” in the request body”}}.`

{"error":{"type":"INVALID_REQUEST_UNKNOWN","message":"Invalid request: parameter validation failed. Check your request data."}}

{“error”:{“type”:“INVALID_REQUEST_BODY”,“message”:“Could not parse request body”}}

THE SOLUTION WAS...just to add this to the json: "typecast:true".
Yes, everything else was ok.

From the Airtable's API documentation:
"The Airtable API will perform best-effort automatic data conversion from string values if the typecast parameter is passed in (click to show example). Automatic conversion is disabled by default to ensure data integrity, but it may be helpful for integrating with 3rd party data sources."

To be honest this was a bit hidden, but hey, I'm writing this post specially for you, struggling for the win (read: for myself when I'll forget).

An example json

`javascript
{
"fields": {
"customer": [
"recMmE0pTasdGqkEw"
],
"date": "2019-07-15",
"from": "2019-06-15",
"to": "2019-06-30",
"currency": "USD"
},
typecast:true

}
`

edit:
I just found out that after I sent the request with typecast:true, now all the requests are passed smoothly without an error!

Top comments (4)

Collapse
 
carriere4 profile image
Charles Carriere

Thanks for posting this! I was trying to do the same thing with python and couldn't figure out what the issue was. I passed my payload with json= instead of params= and it worked like a charm! Thanks again!

Collapse
 
gootecks profile image
gootecks

I ran into the same issue just now and had to adapt for python as well.

I'm still very new to coding, so I created a "records" dictionary with column and record data, then inserted them as follows:

airtable.insert(records, typecast=True)

I'm sure there was a cleaner or easier way to do it, and it only took like an hour (lol) to figure it out, but the upside is I found dev.to and now I'm a member! Had no idea this site even existed!

Collapse
 
dmatt profile image
Danny • Edited

I have one suggested edit: typecast:true should be "typecast":true instead because the property needs to be a string in JSON. Thanks.

Collapse
 
jameshubert_com profile image
James Hubert

Thank you! Exactly what I needed.