My team is working on a web app using FlutterFlow, and I encountered an issue when sending a GET request to the Tape API to retrieve record information using a specific record ID.
When an optional field in a record is empty, it does not appear in the JSON response. This causes problems in my web app because the fields’ indexes get misaligned. For example, if some field is empty, its index is skipped in the response, and the next field takes its place, leading to incorrect data being displayed.
Could you advise on how to handle this situation or whether there’s a way to ensure empty fields are included in the response?
To get around this, I use hidden calculation fields referencing the fields I need. Then, I put them before all other fields and in the order I need them. Since some fields might be empty, you must add a condition in the calculation to put a default value even if empty (that way, it will be forced to appear in the JSON response). The code looks something like his:
const fieldlength = @FieldName && @FieldName.length > 0;
const result = fieldlength ? @FieldName : "No value";
result
It is not the most glamorous solution, but at least it will keep the order of the field the same in the JSON response.
I have to second @Jason 's recommendation to use an intermediate database rather than pulling data via the Tape API directly. Not only would a database be significantly faster (nothing’s faster than SQL, especially if you set up views) but you will inevitably run into API rate limits at scale. You should consider SQL a cache of Tape data, and your app reads off the cache, making everything faster and removing the need for rate limits.
This has always been my strategy for being able to deliver lightning fast companion applications to low code solutions and it relies on having an API to catch webhooks from Tape, process them into SQL data, and store it in the database. There’s a number of ways to make this happen, but it’s always been my preferred route.
thanks for sharing your issue and thoughts. Also thanks to @Luis, @Jason and @andrew.cranston for your input. While all of the information is correct, I’d like to clarify some of the API design decisions.
From a consumer perspective I do see the benefit of always including all fields in the response, even if there are no values. While this “shallow” approach improves consumer friendly-ness, it introduces additional payload and data being sent over the wire that has no information in it - at least no field value.
When looking at a single record, that is not a big problem. Think of fetching a large amount of records - e.g. 500 via the API, and an app with a high number of fields, let’s say 100. If 50% of the fields are empty on average, we would still send ~50*500 * 25.000 empty fields with the response, slowing down both the server side response time and the transmission time over the wire. Plus, requiring more resources on the consumer end to process the response.
For single records, I would not rule out that we might introduce an option in the API in the future that allows to opt-in for returning empty fields as well. Until then, I suggest using the app endpoints instead, retrieving the structure via those endpoints and then using e.g. the field IDs to look up your proper values from the fields arrays in the Tape API responses.
We hope this can shed some light into why things are this way currently. Let me know if you have additional questions!