# Update Function Trigger

`PATCH /functions/{name}/triggers/{triggerId}` · Core · Compute & Automation

Partially updates an EVENT trigger. Send at least one of `events`, `filter` (an object in the JSON-policy grammar, or `null` to clear it), `enabled` and `logOkInvocations`; an empty body is `400 K9O_INVALID_REQUEST_SHAPE`. The function and the collection are fixed at creation. A scheduled trigger's id is `404 K9O_TRIGGER_NOT_FOUND` here; update schedules with `PATCH /@{projectSlug}/forge/schedules/{trgId}`. Requires `PROJECT_ADMIN`.

## Parameters

| Name | In | Required | Description |
|---|---|---|---|
| `name` | path | yes | The function's name. A module's operation is named `<module>:<operation>`. Example: `"greet"`. |
| `triggerId` | path | yes | The trigger's id, a UUID. Example: `"3f6c1e2a-8b4d-4c7e-9a1f-2d5b6c7e8f90"`. |
| `projectSlug` | path | yes | The project's slug: the path segment after `@`. It is unique within the org. Example: `"storefront"`. |

## Request body

| Field | Type | Required | Description |
|---|---|---|---|
| `events` | object | no | Replaces the events that fire the trigger: record events on a collection trigger, object events on a bucket trigger. |
| _one of_ | | |  |
| _or_ | | |  |
| `filter` | object | no | Replaces the filter; null removes it. A collection trigger takes a record predicate, a bucket trigger the object conditions. Conditions on the object event, all of which must hold: `pathPrefix`, a literal prefix of the object's path (no wildcards); `contentType`, an exact type such as `image/png` or a family such as `image/*`; `sizeBytes`, an inclusive `{ min, max }` range. Null or absent fires on every matching event. |
| _one of_ | | |  |
| _or_ | | |  |
| `enabled` | boolean | no | Turns the trigger on or off. |
| `logOkInvocations` | boolean | no | Whether successful invocations are logged as well as failed ones. |

```json
{
  "filter": {
    "eq": [
      "resource.status",
      "archived"
    ]
  },
  "enabled": true
}
```

## Responses

- **200**: Success

| Field | Type | Required | Description |
|---|---|---|---|
| `data` | object | yes | A function trigger: the function runs when a matching write lands in the collection, or a matching object event happens in the bucket. |
| `data.id` | string (uuid) | yes | The trigger's id, a UUID. |
| `data.functionName` | string | yes | The function the trigger runs. |
| `data.collection` | object | yes | The collection whose writes fire the trigger; null on a bucket trigger. |
| _one of_ | | |  |
| _or_ | | |  |
| `data.bucket` | object | yes | The bucket whose object events fire the trigger; null on a collection trigger. |
| _one of_ | | |  |
| _or_ | | |  |
| `data.events` | array of object | yes | The events that fire the trigger: `insert`, `update`, `delete` and `upsert` on a collection; on a bucket, `object.created` (an upload, an overwrite included), `object.deleted` (a delete through the API) and `object.expired` (removed by the bucket's `deleteAfterDays`). A function that receives `object.deleted` or `object.expired` can't read the object any more. |
| _one of_ | | |  |
| _or_ | | |  |
| `data.filter` | object | yes | The condition an event must match: a record predicate on a collection trigger, object conditions on a bucket trigger. Null when the trigger fires on every matching event. |
| _one of_ | | |  |
| _or_ | | |  |
| `data.enabled` | boolean | yes | Whether the trigger fires. |
| `data.logOkInvocations` | boolean | yes | Whether successful invocations are logged as well as failed ones. |
| `data.createdAt` | string (date-time) | yes | When the trigger was created. |
| `meta` | object | yes |  |


## Errors

| HTTP | Code | When |
|---|---|---|
| 401 | `K9O_UNAUTHENTICATED` | The caller presented no authenticated session. |
| 400 | `K9O_INVALID_REQUEST_SHAPE` | The body supplies none of events, filter, enabled and logOkInvocations, or does not match the schema. |
| 400 | `K9O_INVALID_FIELD_VALUE` | The project slug, the function name or the trigger id is not a valid identifier. |
| 400 | `K9O_POLICY_UNKNOWN_OPERATOR` | The filter uses an operator outside the JSON-policy grammar. |
| 403 | `K9O_ACCESS_DENIED` | The caller has no access to this project. |
| 403 | `K9O_IAM_POLICY_DENIED` | The bound IAM policy ceiling denies updating function triggers; the default floor is PROJECT_ADMIN. |
| 404 | `K9O_FUNCTION_NOT_FOUND` | No function with that name exists in this project, or it is retired. |
| 404 | `K9O_TRIGGER_NOT_FOUND` | No event trigger with that id is attached to this function (a scheduled trigger's id is not found here). |

## Code samples

### cURL

```bash
curl -X PATCH 'https://<org>.api-<region>.k9o.io/@storefront/functions/<name>/triggers/<triggerId>' \
  -H 'Authorization: Bearer $K9O_TOKEN' \
  -H 'Content-Type: application/json' \
  -d '{
  "filter": {
    "eq": [
      "resource.status",
      "archived"
    ]
  },
  "enabled": true
}'
```

### fetch

```javascript
const res = await fetch('https://<org>.api-<region>.k9o.io/@storefront/functions/<name>/triggers/<triggerId>', {
  method: 'PATCH',
  headers: {
    'Authorization': `Bearer ${process.env.K9O_TOKEN}`,
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
  "filter": {
    "eq": [
      "resource.status",
      "archived"
    ]
  },
  "enabled": true
}),
});
const { data, meta } = await res.json();
```

### k9o CLI

```bash
k9o function trigger update <function> <trigger-id>
```

### @k9o/core

```typescript
// const k9o = new K9o({ orgSlug: 'playground', projectSlug: 'storefront', apiKey: 'k9o_…' })
const { data } = await k9o.functions.triggers.update('greet', '3f6c1e2a-8b4d-4c7e-9a1f-2d5b6c7e8f90', {
  filter: {
    eq: ['resource.status', 'archived']
  },
  enabled: true
})
```

### k9o

```python
# k9o = create_client(org_slug="playground", project_slug="storefront", api_key="k9o_…")
response = k9o.functions.triggers.update("greet", "3f6c1e2a-8b4d-4c7e-9a1f-2d5b6c7e8f90", {
    "filter": {
        "eq": ["resource.status", "archived"]
    },
    "enabled": True
})
```

### sdk-go

```go
// ctx := context.Background()
// client, _ := k9o.NewClient(k9o.ClientOpts{OrgSlug: "playground", ProjectSlug: "storefront", APIKey: "k9o_…"})
data, _, kerr := client.Functions.Triggers.Update(ctx, "greet", "3f6c1e2a-8b4d-4c7e-9a1f-2d5b6c7e8f90", map[string]any{"filter": map[string]any{"eq": []any{"resource.status", "archived"}}, "enabled": true})
```

### k9o

```rust
// let k9o = Client::new(ClientOpts { org_slug: "playground".into(), project_slug: "storefront".into(), api_key: "k9o_…".into() })?;
let resp = k9o.functions.triggers.update("greet", "3f6c1e2a-8b4d-4c7e-9a1f-2d5b6c7e8f90", json!({"filter": json!({"eq": ["resource.status", "archived"]}), "enabled": true})).await?
```

### dev.k9o:core

```java
// K9o k9o = K9o.createClient(K9o.Opts.builder().orgSlug("playground").projectSlug("storefront").apiKey("k9o_…").build());
var response = k9o.functions().triggers().update("greet", "3f6c1e2a-8b4d-4c7e-9a1f-2d5b6c7e8f90", Map.of("filter", Map.of("eq", List.of("resource.status", "archived")), "enabled", true))
```

### K9o.Core

```c#
// var k9o = K9oClient.Create(new K9oOptions { OrgSlug = "playground", ProjectSlug = "storefront", ApiKey = "k9o_…" });
var response = await k9o.Functions.Triggers.UpdateAsync("greet", "3f6c1e2a-8b4d-4c7e-9a1f-2d5b6c7e8f90", new Dictionary<string, object> { ["filter"] = new Dictionary<string, object> { ["eq"] = new object[] { "resource.status", "archived" } }, ["enabled"] = true })
```

### k9o

```ruby
# k9o = K9o.create_client(org_slug: "playground", project_slug: "storefront", api_key: "k9o_…")
response = k9o.functions.triggers.update("greet", "3f6c1e2a-8b4d-4c7e-9a1f-2d5b6c7e8f90", { filter: { eq: ["resource.status", "archived"] }, enabled: true })
```

### k9o/sdk

```php
// $k9o = K9oClient::create(['org_slug' => 'playground', 'project_slug' => 'storefront', 'api_key' => 'k9o_…']);
$response = $k9o->functions->triggers->update('greet', '3f6c1e2a-8b4d-4c7e-9a1f-2d5b6c7e8f90', ['filter' => ['eq' => ['resource.status', 'archived']], 'enabled' => true])
```


Canonical page: https://docs.kilimanjaro.dev/api-playground/core/update-function-trigger
