Forum Academy Marketplace Showcase Pricing Features

Detect whether or not optional parameter was used

I’m looking for a way to detect whether or not an api call to an endpoint in Bubble included an optional parameter. I know that absent optional parameters are considered empty, but not sending a parameter and sending a parameter with an empty value are not the same thing.

So basically, for a parameter called “contact_fname” I’m looking for a conditional like this “contact_fname was included in call is yes: formatted as text”

The specific use case/ need for this is outlined below:

I have a bubble endpoint set up for editing contacts in PowrLine. Our users can set up API calls to this endpoint (from Zapier for example) to edit contacts in PowrLine based on triggers from other platforms (like their CRM or a form on their website).

The user identifies which company and contact to create/edit using the required parameters (company id, api key, and phone number) and then has 16 other optional parameters they can include in the call for first name, last name, email etc.

Here’s a series of actions that illustrate my issue.

Action 1: A user’s zapier send a new call to PowrLine’s add/edit contact endpoint (triggered by their CRM) with following parameters. This creates a new contact in their company with the information included in the call.

company_id = xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

api_key = xxxxxxxxxxxxxxxxxxxxxxxxx

phone = 7702380000

first_name = John

last_name = Do

email = [email protected]

organization = powerline

Since the user’s CRM does not have matching information for them. The following parameters were not used in the above call.

notes

custom_field_1

custom_field_2

custom_field_3

Action 2: User manually adds text to the notes section of the contact in PowrLine, as well as one of the custom fields of the contact. This text is important to the user.

Action 3: The user changes the organization field of the contact in their CRM to “PowrLine” from “powerline”. This triggers another API call that sends information back to PowrLine (via the same endpoint it was created with). This call uses the same parameters as before (leaving out all the parameters that aren’t being used).

company_id = xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

api_key = xxxxxxxxxxxxxxxxxxxxxxxxx

phone = 7702380000

first_name = John

last_name = Do

email = [email protected]

organization = PowrLine

This API call triggers the workflow to edit the contact that was created earlier. Since the notes and custom_field_1 parameters were not included in the call, Bubble reads them as being “empty” and changes these fields on the PowrLine contact to “empty”, aka deleting the manually entered text in these fields that the user didn’t want changed.

I would like to be able to add something to this effect on the “Make changes to contact” action of the workflow: “notes was included in call is no: formatted as text” Then if notes were not included it just uses the existing text in the field rather than replacing it with nothing.

Is there a way to do this that I’m just missing?

@aj11 You should be able to do this with the ‘defaulting to’ operator. When that is used, Bubble will default to the default value if the previous value is empty.

Using your notes example above that would look like:

‘notes = notes:defaulting to this Contact’s notes’

Hey Eli, thanks for the suggestion.

Unfortunately I’ve tested this and it’s the same as the “is empty” condition, so it doesn’t solve my problem.

Both “is empty” or “defaulting to” makes it impossible to intentionally include an optional parameter in the call with an empty value in order to clear the field on the contact in my app.

I need to be able to detect not whether the value of the parameter is empty, but whether the parameter itself was used in the call including when its value is empty.

@aj11

If I understood it right, the goal is to update the field only if you received a new value. If the value received from your request is empty, nothing should be updated in these fields. Please, is that right?

If it is the case, you could try to create aditional actions to update only these 3 fields and insert the condition in the action instead of the field.

I hope it helps you!

That is not correct.

There are three possible situations I’m trying to filter for:

  1. Parameter was included in call with a new value → Updates corresponding field.

  2. Parameter was included in call with an empty value → Deletes everything in the corresponding field.

  3. Parameter was not included in the call at all → Leaves corresponding field unaffected.

The issue I’m trying to solve here is filtering between 2 & 3. My current workaround is to check to see if the field’s value is “[EXCLUDE]” and if it is then leave the corresponding field unaffected. This works I just don’t love it because it will force our users to update all their calls if we ever add additional parameters to the endpoint.

This is apparently not possible with Bubble. However, I’ve also found that many webhook/api services (like Zapier) do not send parameters that are empty, so this functionality wouldn’t be very useful anyway.

I’ve resigned to just using “defaulting to” and changing the field to what was already in the field if there was no provided value. This cover 99% of use cases.

1 Like