[API] Error requesting a single field

#1

The following request works as expected:

https://api.airtable.com/v0/appD1JKW7PlQhRMrF/Docentes?fields=Email&fields=Status

But this one fails with status 422 Unprocessable Entity:

https://api.airtable.com/v0/appD1JKW7PlQhRMrF/Docentes?fields=Email

The response is:

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

#2

Also, what does “array of strings” actually mean in the context of an URL-encoded parameter?

0 Likes

#3

Funny thing, repeating the field works:

https://api.airtable.com/v0/appD1JKW7PlQhRMrF/Docentes?fields=Curso&fields=Curso

Clearly there’s a problem with the “array” when it has only one element.

1 Like

#4

Yes, I don’t understand the “array of elements” when it doesn’t work for one element. Airtable should explain it better in the doc

0 Likes

#5

You’re right—this is a little confusing.

If you want to pass a single value, such as maxRecords, you’ll supply it as a normal query parameter. For example:

?maxRecords=5

However, if you want to pass an array, you’ll need to append [] to the end of each key.

For example, imagine you want to list records and only include two fields: “My First Field” and “My Other Field”. You’d send query parameters like this:

?fields%5B%5D=My%20First%20Field&fields%5B%5D=My%20Second%20Field

If you only wanted one field, you’d still append the [].

Our query parsing is somewhat lenient, which is why supplying the parameter multiple times works. We recommend appending the [] in all cases so that it works when you just want to supply an array with one value.

If you can, we recommend using a client library to avoid some of this. Airtable.js is our official offering, but our API docs mention a few unofficial libraries for other languages. You can use the Airtable API URL Encoder to put together a properly-formatted request if you’re not using a library.

In any case, we’ll plan to update our docs here, because this isn’t clear.

0 Likes