Help

Re: Checkbox and REST API

2670 0
cancel
Showing results for 
Search instead for 
Did you mean: 
jamesha100
4 - Data Explorer
4 - Data Explorer

Hello,

I am assessing Airtable as a method to store data that will be used to control a contact centre system.

This system will use REST API calls to retrieve data in JSON format.

This works ok but I am a bit confused about the Checkbox record type, which seems to be a boolean type, does not act as such for API queries.

If the Checkbox is ticked the JSON response contains the filed name and a value of true. If the Checkbox is not ticked the JSON response does not contain the field name. My expectation would be that the JSON response should contain the field name and a value of false.

Not having this will cause the parsing of the JSON response to be more complex than I would like. I will have to code for the key:value pair being missing rather than a simple true/false situation.

Is there any reason for this working the way it does? How have others coped with this design quirk? 

3 Replies 3

This is standard procedure for a REST API. If a value is empty/blank, it is not included in the response in order to reduce network traffic.

Workarounds depend on the language/system you are using to parse the data. For example, in JavaScript, if you check for the value of a missing key, you get a result of undefined, which is falsy.

Another workaround is to use a formula field that converts the checkbox to a different value type, such as a number. Then have your system ask for the formula field instead.

Thank you for the response. What you state makes sense but my thoughts are is a boolean false really a blank value? Omitting this may save some network bandwidth but the tradeoff would seem to be increased complexity in processing the response.

I am sure that you are correct and that Airtable follows the correct standard/convention. Is there a reference that you can point me to that confirms this? - I am keen to learn best practice.

I have found an interesting article that suggests avoiding booleans as they can reduce extensibility - it includes an example of Github originally using a boolean for whether a repository was private which had to be changed to allow multiple values for repository status (private, public, internal).

https://medium.com/geekculture/why-you-shouldnt-use-booleans-in-rest-apis-2747b187876c 

pdxbug
5 - Automation Enthusiast
5 - Automation Enthusiast

I have been able to get null to work for removing a checkbox. Perl doesn't do boolean do true or false boolean. It would be nice to be able to use the standard operators that also work such as:
True|1|"true"
False|0|null|""
etc.