API: Remove json array

Hey folks, first-time caller, long-time listener. I have an issue with removing a json array in the body of an API call.


Basically, I’m trying to remove the array general_tools when there’s nothing in it within my bubble app. As I understand it, you can’t delete using json, so I am trying to send an empty or null array to remove the array on the remote service.


The rest API that I’m trying to call is a PATCH to an object array, that when empty, should return null, I think :sweat_smile:. This API and the bubble expressions shown work perfectly fine when there’s something to send back, but when all of the things are empty, that’s when problems start.


Here is the API connection UI


I do a search for certain things/objects, and if they come back empty, I move on to the next thing, which works fine. But when they're all empty, I'm stumped as to how to return `null` for the entire array, if that makes any sense.



Formatted Text Bookings

Formatted Text Bookings Availability

Formatted Text Call Transfers



When I add null to the Formatting for no the API errors out saying it’s expecting “property name” or “}”.
Screenshot 2025-01-03 at 3.12.56 PM


If I leave Formatting for no inputs empty it errors that general_tools must be an object.



I have searched high and low on Bubble and other forums for a fix but I’m still stumped. Any help would be tremendously appreciated. :pray: :sweat_smile:

What is expected by your API endpoint? Most of them will accept an empty array.

Actually, your json doesn’t seem to be encoded correctly, but it’s hard to see without the final payload.
Also, let’s say you have a yes for only one part of your array, you will have a missing bracket (open or close one…) with the way you encoded that.

Thanks for responding! :pray: Yes, exactly. I have tried to build it like below as well…

{
  "general_tools": [<generalTools>]
}

versus

{
  <generalTools>
}

With the rest in the expressions, almost the same as previously shown…

But the same issue exists, if all the results are empty it errors out.

I think the issue is that I am sending an empty object, which will not fly. I might have to do this in main API call body…

<general_tools>

The rest, as previously shown, should not send anything at all if the object is empty. This was going to be my next step but not sure if that will solve the problem, seems like it would. Does that make sense?

null is not the same as [ ]that is an empty array.
But actually, it’s vera hard to find the issue without inspecting each part of your settings.

If your goal is to send a list of bookings, you should use Do a search for bookings:formatted as text and format the object correctly. If the search return nothing, this will return an empty array.

Ahhh ok, I wasn’t aware of that re [ ]. The code does find bookings, call transfers, and end calls and adds them properly when it does, and returns the correct results, bypasses when it doesn’t. Sadly, the service doesn’t like empty arrays, apparently. Since general_tools is a function of the LLM model, it looks like I will have to send the entire current LLM model minus the general_tools when the things are empty, which I was really hoping to avoid.

@Jici got it resolved, I just had to resend the LLM contents with general_tools marked as null, thank you for the tips!