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

# Triggers

> Choose when a routine runs: manually, on a schedule, or through an authenticated custom trigger.

A routine binds one trigger to its [ordered steps](https://docs.mobilerun.ai/routines/functions.md). Open **When** to configure how it starts.

## Manually

Choose **Manually** for on-demand work. **Run now** starts a live run with the input you supply; see [Run now](https://docs.mobilerun.ai/routines/runs.md#run-now) for API examples and execution results.

In a [routine document](https://docs.mobilerun.ai/routines/documents.md), manual runs use `on.custom`:

```yaml theme={null}
on:
  custom: {}
```

[Use this template](https://docs.mobilerun.ai/routines/documents.md#run-manually).

## On a schedule

Choose **On a schedule** and set a timezone. The API uses `activation: "schedule"`, `scheduleRule`, and an IANA `timezone`, such as `Europe/Amsterdam`.

| Rule | Configuration |
| - | - |
| Once | `{"type":"once","dateTime":"2027-01-15T09:00:00+01:00"}` |
| Cron | `{"type":"cron","expression":"0 9 * * *"}` for daily 09:00. |
| Recurring | `{"type":"recurring","rrule":"FREQ=DAILY;INTERVAL=1"}` for RRULE recurrence. |

Document schedules use `cron`, `once`, or `rrule` directly, rather than the resource API’s `scheduleRule` wrapper.

```yaml Cron theme={null}
on:
  schedule:
    cron: "0 9 * * *"
    timezone: Europe/Amsterdam
    jitter:
      beforeMinutes: 5
      afterMinutes: 10
```

```yaml Once theme={null}
on:
  schedule:
    once: "2027-01-15T09:00:00Z"
```

```yaml RRULE theme={null}
on:
  schedule:
    rrule: FREQ=DAILY;INTERVAL=1
    timezone: Europe/Amsterdam
```

[Use the cron template](https://docs.mobilerun.ai/routines/documents.md#schedule-with-cron) or [once template](https://docs.mobilerun.ai/routines/documents.md#schedule-once). For RRULE, copy the cron template and replace `cron` with `rrule` as above.

Add `jitter` to the rule for a randomized window around each scheduled time, for example `{"beforeMinutes":5,"afterMinutes":10}`. Scheduled runs use the trigger's stored `payload`; request payload overrides are ignored. Stored inputs require a matching `customPayloadSchema` and are available as `event.payload`.

This example creates a daily trigger with stored inputs. Bind its returned ID as `triggerId` when [creating a routine](https://docs.mobilerun.ai/routines#through-the-api-or-sdk). All requests use your [API key](https://docs.mobilerun.ai/api-keys.md).

```typescript TypeScript theme={null}
import { MobilerunSDK } from '@mobilerun/sdk';

const mobilerun = new MobilerunSDK();

const trigger = await mobilerun.workflows.triggers.create({
  name: 'Daily app check',
  activation: 'schedule',
  scheduleRule: { type: 'cron', expression: '0 9 * * *' },
  timezone: 'Europe/Amsterdam',
  customPayloadSchema: {
    type: 'object', properties: { query: { type: 'string' } }, required: ['query'],
  },
  payload: { query: 'Daily report' },
}, { headers: { 'Idempotency-Key': crypto.randomUUID() } });
console.log(trigger.id);
```

```python Python theme={null}
from uuid import uuid4
from mobilerun_sdk import MobilerunSDK

mobilerun = MobilerunSDK()

trigger = mobilerun.workflows.triggers.create(
    name="Daily app check", activation="schedule",
    schedule_rule={"type": "cron", "expression": "0 9 * * *"},
    timezone="Europe/Amsterdam",
    custom_payload_schema={
        "type": "object", "properties": {"query": {"type": "string"}},
        "required": ["query"],
    },
    payload={"query": "Daily report"}, idempotency_key=str(uuid4()),
)
print(trigger.id)
```

```bash cURL theme={null}
curl --fail-with-body https://api.mobilerun.ai/v1/triggers \
  -H "Authorization: Bearer $MOBILERUN_API_KEY" \
  -H 'Content-Type: application/json' \
  -H "Idempotency-Key: $(uuidgen)" \
  -d '{"name":"Daily app check","activation":"schedule",
    "scheduleRule":{"type":"cron","expression":"0 9 * * *"},
    "timezone":"Europe/Amsterdam",
    "customPayloadSchema":{"type":"object","properties":{"query":{"type":"string"}},"required":["query"]},
    "payload":{"query":"Daily report"}}'
```

## Custom trigger

Create a trigger through `POST /v1/triggers` with `{"name":"On demand","activation":"custom"}` and bind it to a routine. To fire it, send a JSON `payload` to `POST /v1/triggers/{triggerId}/fire`.

In a [routine document](https://docs.mobilerun.ai/routines/documents.md):

```yaml theme={null}
on:
  custom:
    inputs:
      type: object
      properties:
        text:
          type: string
      required: [text]
```

[Use this template](https://docs.mobilerun.ai/routines/documents.md#custom-trigger-via-api). The fire call’s payload must match `inputs`.

**This is an authenticated API call, not an unauthenticated inbound webhook URL.** Use your API key from a trusted server. Only custom triggers can be fired this way; schedule and event triggers return `409`.

```typescript TypeScript theme={null}
import { MobilerunSDK } from '@mobilerun/sdk';

const mobilerun = new MobilerunSDK();

const trigger = mobilerun.workflows.triggers.fromId('TRIGGER_ID');
const fired = await trigger.fire({ payload: { query: 'Daily report' } }, {
  headers: { 'Idempotency-Key': crypto.randomUUID() },
});
console.log(fired.invocationId, fired.enqueuedCount);
```

```python Python theme={null}
from uuid import uuid4
from mobilerun_sdk import MobilerunSDK

mobilerun = MobilerunSDK()

trigger = mobilerun.workflows.triggers.from_id("TRIGGER_ID")
fired = trigger.fire(payload={"query": "Daily report"}, idempotency_key=str(uuid4()))
print(fired.invocation_id, fired.enqueued_count)
```

```bash cURL theme={null}
curl --fail-with-body "https://api.mobilerun.ai/v1/triggers/$TRIGGER_ID/fire" \
  -H "Authorization: Bearer $MOBILERUN_API_KEY" \
  -H 'Content-Type: application/json' \
  -H "Idempotency-Key: $(uuidgen)" \
  -d '{"payload":{"query":"Daily report"}}'
```

The `202` response contains `invocationId`, `enqueuedCount`, and `deduplicated` directly, without a `data` envelope. One trigger can start multiple enabled routines. A zero count can mean no attached routine is eligible. If configured, `customPayloadSchema` validates the payload. Keep the same idempotency key and payload when retrying the same fire; use a new key for a new invocation.

## On an event

&#x20;Soon&#x20;

App, device, and platform event triggers will start routines when an event happens. **On an event** is not yet available to customers; use a schedule or authenticated custom trigger for now.

The document shape below is reserved for event triggers; availability remains **Soon**. `EVENT_TYPE` is a placeholder, not a currently supported customer event.

```yaml theme={null}
on:
  event:
    type: EVENT_TYPE
```

Use a [manual template](https://docs.mobilerun.ai/routines/documents.md#run-manually) or [schedule template](https://docs.mobilerun.ai/routines/documents.md#schedule-with-cron) today.


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