Update entity records by filter

<Info>This API is in beta. Endpoints, fields, and behavior may still change, so avoid depending on it in production.</Info>

Applies the same change to up to 500 records in one of the app's entities that match a filter, and returns how many changed.

Send query, a filter written the same way as the q parameter of List entity records, and data, the change written as MongoDB update operators on the entity's field names. For example, {"query": {"status": "draft"}, "data": {"$set": {"status": "sent"}}} marks every draft as sent. A field can appear in only one operator per call, and the operators you can use are:

  • $set, $unset, and $rename
  • $inc, $mul, $min, and $max
  • $currentDate
  • $addToSet, $push, and $pull

The values aren't checked against the entity's schema, so a field the schema doesn't declare, or a value of another type, is stored as sent.

Row-level security applies. The filter only reaches records the entity's rls update rule lets you change, and the rest are left alone rather than failing the call. If a field-level rule refuses the change on any matching record, the call is rejected and no records change.

When more than 500 records match, 500 of them change and has_more is true. Call again to change the rest, with a filter that no longer matches the records you've already changed, as the draft filter in the example does. A filter that still matches them changes the same records again.

Repeating $set, $unset, $rename, $min, $max, $addToSet, or $pull leaves the records as the first call did, so it's safe to retry. Repeating $inc, $mul, $push, or $currentDate applies the change a second time.

Unlike Update entity record, this doesn't trigger the app's webhooks, automations, or workflows.

<Note>This endpoint accepts a personal API key belonging to a user with access to the app. A read-only key is refused, and workspace API keys are not accepted.</Note>

patch/api/apps/{app_id}/entities/{entity_name}/update-many

Path parameters

app_idstring required

ID of the app that owns the entity.

ID of the app that owns the entity.

entity_namestring required

Name of the entity, exactly as List entity schemas reports it. Don't pass User here. It doesn't fail, but it reads and writes a separate, disconnected set of records stored under that name, not the app's real user accounts, which are managed through their own endpoints.

Name of the entity, exactly as List entity schemas reports it. Don't pass User here. It doesn't fail, but it reads and writes a separate, disconnected set of records stored under that name, not the app's real user accounts, which are managed through their own endpoints.

Request body

queryobject required

Filter selecting the records to change, in the same form as q. Send {} to match every record.

dataobject required

The change, as one or more update operators, each mapping field names to values.

Example request

{
  "query": {
    "status": "draft"
  },
  "data": {
    "$set": {
      "status": "sent"
    }
  }
}

Response

How many records changed.

successboolean required

Always true. An update that doesn't happen returns an error instead.

updatedinteger required

Number of matching records the call changed. A record that already held the new values still counts, because its updated_date changes, and 0 means no record matched.

has_moreboolean required

Whether more than 500 records matched, so only 500 of them were changed and more may be left.

Example response

{
  "success": true,
  "updated": 42
}

Changes

Changed in 1 of the 33 revisions of this API.1