---
title: "Create function triggers"
method: POST
path: "/v1/functions/{functionId}/triggers"
tags: ["Functions"]
---

# Create function triggers

`POST /v1/functions/{functionId}/triggers`

Subscribe a function to one or more event types, optionally scoped to specific senders. Provide eventTypes and senderIds (use null in senderIds for all senders); a trigger is created for each event type and sender combination.

The special event type `cron` runs the function on a schedule instead of a messaging event: include a `cron` field with a 5-field UTC cron expression (minimum granularity one minute). A cron trigger ignores the sender axis, and a function may hold several cron triggers with different expressions. The function receives an event with `type: "cron"` and `data.cron`.

## Path parameters

- `functionId` string, required

## Request body

- object
  - `eventTypes` string[], required — Event types to subscribe to.
  - `senderIds` string[], required — Senders to scope the triggers to. Use null for all senders.
  - `cron` string — Required when eventTypes includes `cron`: a 5-field cron expression (minute hour day-of-month month day-of-week), evaluated in UTC.

## Response `201`

Triggers created.

- object
  - `added` integer, required
  - `skipped` integer, required — Number of triggers that already existed.
  - `triggers` FunctionTrigger[], required
    - `id` string, required
    - `functionId` string, required
    - `eventType` string, required — Event type that fires the function. See GET /v1/functions/event-types for the supported list. The special type `cron` fires on a schedule instead of a messaging event and carries a `cron` expression.
    - `senderId` string, nullable — Restrict the trigger to a single sender. Null means all senders in the project.
    - `active` boolean, required
    - `createdAt` string, date-time, required
    - `updatedAt` string, date-time, required
    - `cron` string, nullable — 5-field cron expression (minute hour day-of-month month day-of-week), evaluated in UTC. Present only on `cron` triggers.
    - `nextRunAt` string, date-time, nullable — Next scheduled fire time. Present only on `cron` triggers.
    - `lastRunAt` string, date-time, nullable — Last time the schedule fired. Null until the first fire.

## Other responses

- `400` — Invalid request.
- `401` — Unauthorized.
- `404` — Function not found.

---

[API](https://skmtc.net/zavudev/apis/zavu-unified-messaging-layer-api.md) · [All operations](https://skmtc.net/zavudev/apis/zavu-unified-messaging-layer-api/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/zavudev/zavu-unified-messaging-layer-api/versions/07b87b6ae707/schema)
