> For the complete documentation index, see [llms.txt](https://manual.bubble.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://manual.bubble.io/~/changes/oSsRRFoN6bhUP7nqCRaz/help-guides/maintaining-an-application/database-maintenance/bulk-operations.md).

# Bulk Operations

This section covers bulk operations, which lets you run API Workflows on a list of things directly from the Bubble database editor

Bulk operations let you execute workflows on a large set of data within the Editor. By scheduling a pre-defined [API Workflow](#user-content-fn-1)[^1] on the provided list, you can perform the same wide array of actions on a list of things[^2] that you can do in your app.

{% hint style="warning" %}
**Note:** Bulk operations run client-side, so they depend on your browser window staying open and active. In other words, you need to keep the popup open for them to continue. If you are looking to modify a large amount of data, the most effective and reliable solution is to use [recursive scheduled workflows](/~/changes/oSsRRFoN6bhUP7nqCRaz/help-guides/integrations/api/the-bubble-api/the-workflow-api/api-workflows/recursive-api-workflows.md) instead.
{% endhint %}

## Defining an API workflow <a href="#defining-an-api-endpoint" id="defining-an-api-endpoint"></a>

Before you can perform bulk workflows on your data, you need to define the API Workflows that you are going to call.

{% hint style="info" %}
If you are not familiar with Bubble's Workflow API and how to set up API Workflows, we recommend you first get to know how they work. The first link below gives an introductory guide to the Workflow API in general, and the second shows you how to set up API Workflows that can be used with bulk operations.

Article: [The Workflow API](/~/changes/oSsRRFoN6bhUP7nqCRaz/help-guides/integrations/api/the-bubble-api/the-workflow-api.md)

Article [API Workflows](/~/changes/oSsRRFoN6bhUP7nqCRaz/help-guides/integrations/api/the-bubble-api/the-workflow-api/api-workflows.md)
{% endhint %}

### Valid API Workflow parameters

To be valid for scheduling by the Bulk operation feature, API Workflows must have a few properties in place:

**A thing parameter:** the workflow must include a parameter that requires a 'thing' of the same data type as the one you intend to perform the bulk operation on

<figure><img src="https://34394582-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M5sbzwG7CljeZdkntrL%2Fuploads%2FMqxFRDoE2ow9QloL5LpO%2Fbulk-operation-parameters.png?alt=media&amp;token=590e9c61-6b0c-407c-92ff-d82c04712d3b" alt=""><figcaption><p>The API Workflow must have a parameter that lets you specify a thing to run the workflow on. In the example above we're instructing Bubble to request a thing of the type <em>Product</em>.</p></figcaption></figure>

**Only set up one parameter:** when a bulk operation is called, Bubble will only fill one parameter: the thing it's currently scheduling the operation on. In other words, do not set up any other parameters.

**The thing cannot be a list:** bulk operations are scheduled one-by-one on a list of things. In other words, the parameter that asks for which thing to perform the operation on should ask for a *single* think, not a list/array.

**It does not need to be exposed as a public API Workflow:** while it will still work if you expose it, it's better to uncheck the [*Expose as a public API Workflow*](#user-content-fn-3)[^3] checkbox to make sure that it cannot be triggered from outside of your app.

### Adding actions

Now we have an API Workflow that accepts a single parameter: the thing that we want to run the operation on. In our example we set that thing to a custom data type called *Product*, so let's make a change to that thing. We have a  [yes/no field](#user-content-fn-4)[^4] on the product called *Published* that we want to set to yes.

In our API Workflow, this is a very simple [*Make changes to a thing*](#user-content-fn-5)[^5] operation:

<figure><img src="https://34394582-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M5sbzwG7CljeZdkntrL%2Fuploads%2FbneIHbv03iyTltU6VCHi%2Fbulk-make-changes-to-a-thing.png?alt=media&amp;token=6a1d882b-9fa9-48f9-a0cb-d4f80754ca18" alt=""><figcaption></figcaption></figure>

1. First, we add the *Make changes to a thing* action to the API Workflow
2. Then, we choose *product* as the thing we want to change. This is the parameter we set up earlier.
3. Finally, we set the *Published* field on the product to yes

## Running the bulk operation

Now that we have the workflow we want to run the bulk operation on, let's see how we trigger it to run.

<figure><img src="https://34394582-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M5sbzwG7CljeZdkntrL%2Fuploads%2FJxF9H5eQ2ZsBlekBjdWA%2Fbulk-operation.png?alt=media&amp;token=90088d4a-e22f-47c7-a687-10c8e1fe0919" alt=""><figcaption></figcaption></figure>

1. First, we select the data type that we want to run the bulk operation on. In this case, we want to work with *Products*
2. Next, select the Products that you want to run the operation on. *Trucker cap* and *Baseball cap* are ready to be published, but *Product 1* still needs some work, so let's just check to two top ones.
3. Then, we click the *Bulk* button, where we'll select with API Workflow to run on the selected things.

{% hint style="danger" %}
Keep in mind that bulk operations spend your app's server capacity just like every other operation. If you run bulk operations on thousands of entries, they can take some time to finish, and can use a noticeable chunk of your capacity.
{% endhint %}

{% hint style="info" %}
Bulk operations typically make changes to a list of records. If you make a mistake when running a bulk operation, you can restore the data type to what it looked like before the operation by using the [*Copy and restore database*](#user-content-fn-6)[^6] feature.
{% endhint %}

<figure><img src="https://34394582-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M5sbzwG7CljeZdkntrL%2Fuploads%2FlcCYFfywjLKxEbCWBjWZ%2Frun-bulk-operation.png?alt=media&amp;token=084082fe-12de-44b2-b62a-e20174f77b66" alt=""><figcaption><p>Click the image to enlarge.</p></figcaption></figure>

1. In the first dropdown, we choose what list to run the operation on. You can choose to run it on the entire current view, or the selected entries – in our case we specifically selected two entries, to let's go with that
2. In the second dropdown you will find the list of compatible API Workflows. If the Workflow does not accept the same data type as a parameter, it will not be selectable
3. The text next to point three confirms that the workflow will in this case be run on 2 entries, which is what we selected
4. Finally, we can click *Run workflow* and the operation will start. Since we are only making a small change on two entries, it should finish very quickly.

Looking again at the data in our database, we can see that the two data types we selected now have their *Published* field set to *yes*.

<figure><img src="https://34394582-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M5sbzwG7CljeZdkntrL%2Fuploads%2Fqx99ARnMiLt7sUoQ8Faf%2Fdata-modified.png?alt=media&amp;token=38e513a8-1b5b-4996-ab0f-fc7d74a715a6" alt=""><figcaption><p>Click the image to enlarge.</p></figcaption></figure>

## Combining bulk operations with views

*Views* let you filter the data displayed in the database editor by specific constraints, just like the *Do a search for* data source. Since bulk operations let you run the operation on all records in the current view, you can combine these features to flexibly run bulk operations on things that match specific criteria, instead of manually selecting the things in the list.

To set up a new view, click the *New view* button or the pencil icon next to the data type you want to run an operation on.

## Additional resources

<details>

<summary>Recursive Workflows - used to process large amounts of data</summary>

For bulk operations on larger record sets, consider using the recursive workflow method. Recursive workflows are API Workflows that schedule just one task at a time, rescheduling themselves upon completion. This method allows operations on a list of things while providing greater control over capacity usage. By spacing out workflows, you can reduce the overall server capacity spent by that operation.

Note that recursive workflows must be triggered from your app, not using the *Bulk* feature.

Article: [Recursive workflows](/~/changes/oSsRRFoN6bhUP7nqCRaz/help-guides/integrations/api/the-bubble-api/the-workflow-api/api-workflows/recursive-api-workflows.md)

</details>

<details>

<summary>Schedule API Workflow on a list – used to trigger bulk operations in your app</summary>

The *Bulk* feature is triggered from inside the Bubble editor, but technically does the same thing as the *Schedule API Workflow on a list* feature. To run bulk operations in your app instead, use that action to trigger the workflow.

Reference: [Schedule API Workflow on a list](/~/changes/oSsRRFoN6bhUP7nqCRaz/core-resources/actions/custom.md#schedule-api-workflow-on-a-list)

</details>

[^1]: API Workflows are workflows that can be scheduled to run internally or can be opened up to be triggered by an external application. They run server-side, which means that they run independently of any page.

    Article: [The Bubble API](/~/changes/oSsRRFoN6bhUP7nqCRaz/help-guides/integrations/api/the-bubble-api.md)

    Article: [The Workflow API](/~/changes/oSsRRFoN6bhUP7nqCRaz/help-guides/integrations/api/the-bubble-api/the-workflow-api.md)

    Article: [API Workflows](/~/changes/oSsRRFoN6bhUP7nqCRaz/help-guides/integrations/api/the-bubble-api/the-workflow-api/api-workflows.md)

[^2]: *Things* are database records of a specific type. For example, if you have a data type called *products*, then one record of that product is known as a thing.

    Article: [The Bubble database](/~/changes/oSsRRFoN6bhUP7nqCRaz/help-guides/data/the-database.md)

[^3]: *Expose as a public API Workflow* means that you are opening up that workflow to be triggered by an external application through an API request. If you plan to use an API Workflow only internally in your app, keep this box unchecked.

    Article: [The Workflow API](/~/changes/oSsRRFoN6bhUP7nqCRaz/help-guides/integrations/api/the-bubble-api/the-workflow-api.md)

[^4]: On each data type you set up custom fields that can contain different kinds of data. A *yes/no* field is a field that simply contains a *yes* or a *no.* This is also known as a boolean.

    Article: [Data types and fields](/~/changes/oSsRRFoN6bhUP7nqCRaz/help-guides/data/the-database/data-types-and-fields.md)

[^5]: The *Make changes to a thing* action lets you save changes to one or more fields on a specific thing (database record).\
    \
    Reference: [Make changes to a thing](https://manual.bubble.io/~/changes/oSsRRFoN6bhUP7nqCRaz/help-guides/maintaining-an-application/database-maintenance/pages/-MTujs88N9W-2FUmQGag#make-changes-to-thing...)

[^6]: The *Copy and restore database* feature lets you copy the content of your database across the Development and Live environment, as well as restore the Development or Live database to a previous state.

    Article: [Database Copy and Backups](/~/changes/oSsRRFoN6bhUP7nqCRaz/help-guides/maintaining-an-application/database-maintenance/database-backups.md)
