> ## Documentation Index
> Fetch the complete documentation index at: https://docs.pocketflows.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Let businesses build segments from your data

> Define filters on your customer properties so businesses can build segments in the embed

Businesses build segments in the embed by filtering on customer properties. A
property only shows up as a filter once you have defined it. This guide takes
one property, a customer's membership plan, from your system to a working
filter. For the model behind this, see
[How segments and filter definitions work](https://docs.pocketflows.com/concepts/segments-and-filters.md).

## Prerequisites

* A business with customers. See
  [Sync businesses and customers](https://docs.pocketflows.com/how-to/sync-businesses-and-customers.md).
* Your `project_id` and `secret_key`. See
  [Authentication](https://docs.pocketflows.com/reference/authentication.md).

## 1. Sync the property into customer metadata

Put the value on each customer's `metadata` as part of your normal customer
sync. Pick a key made of letters, numbers and underscores.

```
POST /sync/businesses/:business_id/customers

Body
{
  "external_id": "your_customer_id",
  "email_address": "customer@example.com",
  "metadata": {
    "plan": "gold"
  }
}
```

> [!NOTE]
>
> A sync replaces the whole customer, including `metadata`. Keep sending every metadata key on every
> sync request, or the ones you leave out are removed.

## 2. Define the filter

Choose where the filter should apply:

* **Every business in your project**: define it once in the dashboard.
* **One business**: define it with the API.

### For every business, in the dashboard

1. Open
   [Resources > Customer Filters](https://dashboard.pocketflows.com/resources/customer_filters)
   and select **Create a new customer filter**.
2. Enter the metadata key as the **Variable Name** (`plan`), a **Display Text**
   that businesses will see ("Membership plan"), and a **Filter Type**
   (`select`). For `select`, add one option per possible value.
3. Save, then turn the filter on in the list. A new project-level filter is
   disabled until you enable it.

### For one business, with the API

The `variable_name` is `customer.` followed by the metadata key.

```
POST /businesses/:id/filter_definitions

Body
{
  "variable_name": "customer.plan",
  "label": "Membership plan",
  "type": "select",
  "options": [
    { "label": "Gold", "value": "gold" },
    { "label": "Silver", "value": "silver" }
  ]
}
```

The response is the filter definition, including its `id`. A filter created for
a business is enabled immediately.

`options` is required in this request for every type. For types other than
`select` and `array_of_known`, pass an empty array:

```
POST /businesses/:id/filter_definitions

Body
{
  "variable_name": "customer.lifetime_spend",
  "label": "Lifetime spend",
  "type": "currency",
  "options": []
}
```

Sending the same `variable_name` again for the same business updates the
existing filter definition instead of creating a second one, so you can run this
step every time you onboard or update a business.

## 3. Check the filter in the embed

[Create an embed](https://docs.pocketflows.com/how-to/render-an-embed.md) for the business and open the segment
builder. "Membership plan" is offered as a filter, with a dropdown of the
options you defined. Build a segment with it and confirm the customers you
expect are included.

If the customers you expect are missing, check that the value in `metadata`
matches the filter's type and, for `select`, one of the option values exactly.
See [Filter definitions](https://docs.pocketflows.com/reference/filter-definitions.md#types).

## Change or remove a filter

* To change the label, type or options, send only the properties you want to
  change to `POST /filter_definitions/:id`. If you send `options`, the list you
  send replaces the existing options.
* To hide a filter without deleting it, call
  `POST /filter_definitions/:id/disable`. Bring it back with
  `POST /filter_definitions/:id/enable`.
* To delete it, call `DELETE /filter_definitions/:id`.

## Related

* [Filter definitions](https://docs.pocketflows.com/reference/filter-definitions.md) for every type and the
  value it expects.
* [How segments and filter definitions work](https://docs.pocketflows.com/concepts/segments-and-filters.md) for
  how project-level and business-level definitions combine.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.