> ## 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.

# Create a trigger

> Create a trigger with an activation type of `event`, `schedule`, or `custom`. Each type requires its own fields (e.g. `eventType` and optional `conditions` for events, `scheduleRule` and `timezone` for schedules, `customPayloadSchema` for custom triggers); mismatched fields are rejected.

Supports an optional `Idempotency-Key` header (1-255 printable ASCII characters). Replays with the same key and an identical body return the original 201; a changed body under the same key returns 422 `idempotency_key_reused`.



## OpenAPI

````yaml /api-reference/workflows/triggers.yaml post /triggers
openapi: 3.1.0
info:
  title: Triggers
  version: v1
servers:
  - description: Droidrun Cloud API
    url: https://api.mobilerun.ai/v1
security:
  - bearerAuth: []
paths:
  /triggers:
    post:
      tags:
        - Triggers
      summary: Create a trigger
      description: >-
        Create a trigger with an activation type of `event`, `schedule`, or
        `custom`. Each type requires its own fields (e.g. `eventType` and
        optional `conditions` for events, `scheduleRule` and `timezone` for
        schedules, `customPayloadSchema` for custom triggers); mismatched fields
        are rejected.


        Supports an optional `Idempotency-Key` header (1-255 printable ASCII
        characters). Replays with the same key and an identical body return the
        original 201; a changed body under the same key returns 422
        `idempotency_key_reused`.
      operationId: createTrigger
      parameters:
        - description: >-
            Idempotency-Key: 1-255 printable ASCII characters. Same key with a
            different request body is a 422 idempotency_key_reused. A retryable
            in-flight duplicate is a 409 with Retry-After and x-should-retry:
            true; a terminal duplicate is a 409 with x-should-retry: false. A
            replay returns the current resource state with Idempotent-Replayed:
            true.
          in: header
          name: idempotency-key
          required: false
          schema:
            description: >-
              Idempotency-Key: 1-255 printable ASCII characters. Same key with a
              different request body is a 422 idempotency_key_reused. A
              retryable in-flight duplicate is a 409 with Retry-After and
              x-should-retry: true; a terminal duplicate is a 409 with
              x-should-retry: false. A replay returns the current resource state
              with Idempotent-Replayed: true.
            example: b3f6a9f0-6f1a-4e9a-9e7a-9c9b6b6a5a3f
            maxLength: 255
            minLength: 1
            pattern: ^[\x21-\x7E]{1,255}$
            type: string
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateTriggerBody'
      responses:
        '201':
          content:
            application/json:
              schema:
                properties:
                  data:
                    $ref: '#/components/schemas/Trigger'
                required:
                  - data
                type: object
          description: Trigger created
        '404':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiErrorEnvelope'
          description: Not Found
      x-codeSamples:
        - lang: JavaScript
          source: >-
            import Mobilerun from '@mobilerun/sdk';


            const client = new Mobilerun({
              apiKey: process.env['MOBILERUN_CLOUD_API_KEY'], // This is the default and can be omitted
            });


            const trigger = await client.workflows.triggers.create({ activation:
            'event', name: 'x' });


            console.log(trigger.data);
        - lang: Python
          source: |-
            import os
            from mobilerun_sdk import Mobilerun

            client = Mobilerun(
                api_key=os.environ.get("MOBILERUN_CLOUD_API_KEY"),  # This is the default and can be omitted
            )
            trigger = client.workflows.triggers.create(
                activation="event",
                name="x",
            )
            print(trigger.data)
components:
  schemas:
    CreateTriggerBody:
      properties:
        activation:
          enum:
            - event
            - schedule
            - custom
          type: string
        conditions:
          properties:
            all:
              items:
                type: object
              type: array
            any:
              items:
                type: object
              type: array
          type: object
        customPayloadSchema:
          $ref: '#/components/schemas/CustomPayloadSchema'
        description:
          maxLength: 2048
          type: string
        eventType:
          maxLength: 256
          type: string
        name:
          maxLength: 256
          minLength: 1
          type: string
        scheduleRule:
          properties:
            dateTime:
              description: ISO 8601 datetime (for type=once)
              type: string
            expression:
              description: Cron expression (for type=cron)
              type: string
            jitter:
              description: >-
                Optional per-occurrence random window around the nominal
                schedule time
              properties:
                afterMinutes:
                  default: 0
                  maximum: 1440
                  minimum: 0
                  type: integer
                beforeMinutes:
                  default: 0
                  maximum: 1440
                  minimum: 0
                  type: integer
              type: object
            rrule:
              description: RRULE string (for type=recurring)
              type: string
            type:
              enum:
                - once
                - cron
                - recurring
              type: string
          required:
            - type
          type: object
        timezone:
          type: string
      required:
        - name
        - activation
      type: object
    Trigger:
      properties:
        activation:
          enum:
            - event
            - schedule
            - custom
          type: string
        conditions: {}
        createdAt:
          format: date-time
          type:
            - string
            - 'null'
        createdBy:
          format: uuid
          type:
            - string
            - 'null'
        customPayloadSchema:
          additionalProperties: {}
          type:
            - object
            - 'null'
        description:
          type:
            - string
            - 'null'
        eventType:
          type:
            - string
            - 'null'
        id:
          format: uuid
          type: string
        name:
          type: string
        nextFireTime:
          type:
            - string
            - 'null'
        ownerId:
          format: uuid
          type: string
        scheduleRule:
          $ref: '#/components/schemas/ScheduleRule'
        timezone:
          type:
            - string
            - 'null'
        updatedAt:
          format: date-time
          type:
            - string
            - 'null'
        userId:
          deprecated: true
          description: 'Deprecated: use ownerId (tenancy) / createdBy (actor).'
          format: uuid
          type: string
      required:
        - id
        - userId
        - ownerId
        - createdBy
        - name
        - description
        - activation
        - scheduleRule
        - timezone
        - eventType
        - customPayloadSchema
        - createdAt
        - updatedAt
      type: object
    ApiErrorEnvelope:
      properties:
        code:
          type: string
        details: {}
        message:
          type: string
        retryAfterSeconds:
          type: number
        traceId:
          type: string
      required:
        - code
        - message
      type: object
    CustomPayloadSchema:
      additionalProperties: true
      description: Optional JSON Schema for validating payloads sent to this custom trigger
      type: object
    ScheduleRule:
      properties:
        dateTime:
          description: ISO 8601 datetime (for type=once)
          type: string
        expression:
          description: Cron expression (for type=cron)
          type: string
        jitter:
          description: >-
            Optional per-occurrence random window around the nominal schedule
            time
          properties:
            afterMinutes:
              default: 0
              maximum: 1440
              minimum: 0
              type: integer
            beforeMinutes:
              default: 0
              maximum: 1440
              minimum: 0
              type: integer
          type: object
        rrule:
          description: RRULE string (for type=recurring)
          type: string
        type:
          enum:
            - once
            - cron
            - recurring
          type: string
      required:
        - type
      type: object
  securitySchemes:
    bearerAuth:
      bearerFormat: Opaque
      description: Bearer token via Authorization header
      scheme: bearer
      type: http

````

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