Filtering on Custom Fields

Apicbase allows you to define custom fields for recipes, ingredients, and menus to store additional information beyond their built-in fields. You can use the custom_fields query parameter while querying the list endpoints for these items to filter based on the contents of these fields. However, it's important to note that this filter works differently compared to the standard filtering options.

This parameter uses a dictionary structure similar to JSON, which allows for filtering on multiple custom fields simultaneously. To filter, provide the names and values of the fields you want to target as keys and values, respectively. In this page, we provide some examples based on the different formats of custom fields.

It's important to note that the custom fields filters only work on exact matches.

Filter on Single Value

Let's use a single choice custom field for recipes defined like this as an example:

To filter the results of the recipe list endpoint to only include those that have "Option 1" selected as the choice for a custom field, you can include the following query parameter in your request:

?custom_fields={"custom single": "Option 1"}

The full URL will therefore look something like this:

https://app.apicbase.com/api/v1/products/recipes/?custom_fields={"Custom Single": "Option 1"}

Filter on Multiple Values

Multi choice fields allow the user to select multiple values from a list of choices. We can filter on a specific combination of values. Using this multi choice custom field as an example:

If we would like to look for recipes with Value 1 or Value 2 selected, we would apply this query parameter to the request:

?custom_fields={"custom multi": ["Value 1", "Value 2"]}

Note that this will return recipes with Value 1 or Value 2.

Please note that these filters may return recipes with additional values beyond those queried. For example, if a recipe has all of Value 1, Value 2, and Value 3 selected, it would be included in the result set for all of these queries

Applying Multiple Filters

It is possible to filter on multiple custom fields at the same time. For example, if we would like to combine both filters used as examples, we could include this query parameter in the URL:

?custom_fields={"custom single": "Option 1", "custom multi": ["Value 1", "Value 2"]}

In this case, the returned items will have both custom single: Option 1 and custom multi: Value 1 or Value 2.