Re: [API] Error requesting a single field

6095 0
Showing results for 
Search instead for 
Did you mean: 
5 - Automation Enthusiast
5 - Automation Enthusiast

The following request works as expected:

But this one fails with status 422 Unprocessable Entity:

The response is:

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

Ahh nice @CH3V4L13R, yeah the record specific portion is working for me now. thanks

Now I’m stuck with the field id portion. Manipulation using the field names works fine, but I can’t manipulate using the field id. Have you used the Field IDs instead of the Field Names? The reason for this being so that if/when the field name is changed, it doesn’t break the code

Or alternatively, if that url can be modified to pull only a specific field (which I’ll do with the field id), that should work too. Do you know how to modify that url to add that query? That’s where I hit the issues I did above with the field query formatting

Makes sense, but I’m using the field name so I don’t think I can help you with that.
How do you retrieve the field ID in the first place?
If you check the Airtable API usages doc, it only explain to retrieve data by record level. I guess trying to be more specific and try to get at a field level is not possible but I may be wrong.

5 - Automation Enthusiast
5 - Automation Enthusiast

The field IDs are kind of annoying to get right now - I used the script here: Field ID instead of Field Name?

The API docs do mention very briefly how to query by field (under the “List Records” portion), but I can’t translate the javascript or @EvanHahn’s response above into Python haha

I read here: Referencing Field IDs using the API for Code Maintainability that its possible to use the field IDs in place of field names, but I think thats 1) in the query only and 2) not sure if the data is returned keyed to the ID (which would be more useful) or the name (which I think is more likely). I reached out to AT to find out on both points.

Thanks for the help!

5 - Automation Enthusiast
5 - Automation Enthusiast

Oh interesting wrinkle is that this works:[]=FIELD_TO_FILTER_TO but only if I don’t include the record in the endpoint.

Bummer is that using the field_id in the field query doesn’t return the results by field id, only field name. So looks like I’ll have to do some mapping…

Thanks too! That’s interesting. Please follow up by sharing AT answers or any others solutions you may find out. Will certainly help others too.

5 - Automation Enthusiast
5 - Automation Enthusiast

So it turns out what I was attempting isn’t possible, but the AT support team had a suggestion that works the same way:

The fields parameter will only work with the “List records” call (which doesn’t include a record ID in the url) – if you’re just retrieving a single record by including that record ID in the url, then all non-empty fields will be returned and it’s not possible to specify particular fields. A potential workaround here: rather than querying the record directly by adding the record ID to the url, you can instead use the general “List records” endpoint with the filterByFormula parameter to select the desired record, and then you can use the fields parameter to specify the fields. filterByFormula takes an Airtable formula, which in this case would be something like RECORD_ID()='recXXXXXXXXX' ​. Then you can use the fields param with field IDs, like so: ​fields[]=fldXXXXXXX&fields[]=fldXXXXXXX ​. You can use this site to generate (and encode) the proper URL for your request, and you can read more about these params in the “List records” section of your API documentation.

They also confirmed that the API only returns fields keyed by field name, not by field ID. I was able to workaround this by essentially passing the field names dynamically into my code from an AT Automation and then using that as my “map” to call and read the fields from.