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

# Create Trigger

> Create a new trigger.

Creates a new trigger with the specified configuration. The trigger will be
validated and, if it's a cron trigger, automatically scheduled.

If channel_credentials are provided, they are stored encrypted in the secret
store under key ``channel_cred:{webhook_type}:{trigger_id}``.

Args:
    payload: Trigger creation DTO (single source of truth shared with MCP toolset).
    user_context: Authentication context.
    trigger_service: Injected trigger service.
    secret_manager: Injected secret manager for credential storage.

Returns:
    The created trigger.

Raises:
    HTTPException: If validation fails or creation errors occur.



## OpenAPI

````yaml /api-reference/openapi.json post /v1/triggers/
openapi: 3.1.0
info:
  description: >-
    Modular and extensible framework for building AI agents. This API requires
    JWT Bearer token authentication for most endpoints. Include your JWT token
    in the Authorization header. Public endpoints include /, /health, /docs,
    /redoc, and /openapi.json.
  title: AgentArea API
  version: 0.1.0
servers: []
security:
  - bearer: []
paths:
  /v1/triggers/:
    post:
      tags:
        - v1
        - protected
        - triggers
      summary: Create Trigger
      description: >-
        Create a new trigger.


        Creates a new trigger with the specified configuration. The trigger will
        be

        validated and, if it's a cron trigger, automatically scheduled.


        If channel_credentials are provided, they are stored encrypted in the
        secret

        store under key ``channel_cred:{webhook_type}:{trigger_id}``.


        Args:
            payload: Trigger creation DTO (single source of truth shared with MCP toolset).
            user_context: Authentication context.
            trigger_service: Injected trigger service.
            secret_manager: Injected secret manager for credential storage.

        Returns:
            The created trigger.

        Raises:
            HTTPException: If validation fails or creation errors occur.
      operationId: create_trigger_v1_triggers__post
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/TriggerCreate'
        required: true
      responses:
        '201':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TriggerResponse'
          description: Successful Response
        '422':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
          description: Validation Error
      security:
        - HTTPBearer: []
components:
  schemas:
    TriggerCreate:
      additionalProperties: false
      description: >-
        Payload for creating a trigger.


        A trigger fires an agent — either on a cron schedule
        (``trigger_type='cron'``)

        or in response to an inbound webhook (``trigger_type='webhook'``). For
        poll-based

        channels (e.g. email inbox), use ``trigger_type='polling'`` plus a

        ``data_extractor`` configuration.
      properties:
        agent_id:
          description: UUID of the agent to invoke when the trigger fires.
          format: uuid
          title: Agent Id
          type: string
        allowed_methods:
          description: HTTP methods accepted on the webhook endpoint.
          items:
            type: string
          title: Allowed Methods
          type: array
        channel_credentials:
          anyOf:
            - additionalProperties: true
              type: object
            - type: 'null'
          description: >-
            Channel credentials (bot_token, SMTP password, etc). Stored
            encrypted in the secret store. Never returned in responses.
          title: Channel Credentials
        conditions:
          additionalProperties: true
          description: Optional conditions evaluated against event data before firing.
          title: Conditions
          type: object
        cron_expression:
          anyOf:
            - type: string
            - type: 'null'
          description: 5- or 6-field cron expression (required when trigger_type='cron').
          title: Cron Expression
        data_extractor:
          anyOf:
            - type: string
            - type: 'null'
          description: Polling extractor identifier (e.g. 'imap', 'rss').
          title: Data Extractor
        data_extractor_config:
          anyOf:
            - additionalProperties: true
              type: object
            - type: 'null'
          description: Connection/auth details for the polling extractor.
          title: Data Extractor Config
        description:
          default: ''
          description: Short summary of what this trigger does.
          maxLength: 1000
          title: Description
          type: string
        enabled:
          default: true
          description: Whether the trigger is active immediately on creation.
          title: Enabled
          type: boolean
        event_types:
          description: Event types to filter on (empty list = accept all events).
          items:
            type: string
          title: Event Types
          type: array
        failure_threshold:
          default: 5
          description: Auto-disable after this many consecutive failed executions.
          maximum: 100
          minimum: 1
          title: Failure Threshold
          type: integer
        name:
          description: Human-readable trigger name.
          maxLength: 255
          minLength: 1
          title: Name
          type: string
        task_parameters:
          additionalProperties: true
          description: Parameters merged into the task created when the trigger fires.
          title: Task Parameters
          type: object
        timezone:
          default: UTC
          description: IANA timezone for cron evaluation (e.g. 'UTC', 'America/New_York').
          title: Timezone
          type: string
        trigger_type:
          description: >-
            'cron' for scheduled, 'webhook' for inbound HTTP, 'polling' for
            extractor-driven.
          enum:
            - cron
            - webhook
            - polling
          title: Trigger Type
          type: string
        validation_rules:
          additionalProperties: true
          description: >-
            Per-channel validation rules (signature secrets, allowed senders,
            etc).
          title: Validation Rules
          type: object
        webhook_config:
          anyOf:
            - additionalProperties: true
              type: object
            - type: 'null'
          description: Channel-specific configuration (bot tokens, signing keys, etc).
          title: Webhook Config
        webhook_id:
          anyOf:
            - type: string
            - type: 'null'
          description: >-
            Public webhook path segment. Auto-generated if omitted for webhook
            triggers.
          title: Webhook Id
        webhook_type:
          default: generic
          description: 'Channel type: ''generic'', ''telegram'', ''slack'', ''discord'', etc.'
          title: Webhook Type
          type: string
      required:
        - name
        - agent_id
        - trigger_type
      title: TriggerCreate
      type: object
    TriggerResponse:
      description: Response model for trigger data.
      properties:
        agent_id:
          format: uuid
          title: Agent Id
          type: string
        allowed_methods:
          anyOf:
            - items:
                type: string
              type: array
            - type: 'null'
          title: Allowed Methods
        conditions:
          additionalProperties: true
          title: Conditions
          type: object
        consecutive_failures:
          title: Consecutive Failures
          type: integer
        created_at:
          title: Created At
          type: string
        created_by:
          title: Created By
          type: string
        cron_expression:
          anyOf:
            - type: string
            - type: 'null'
          title: Cron Expression
        data_extractor:
          anyOf:
            - type: string
            - type: 'null'
          title: Data Extractor
        description:
          title: Description
          type: string
        event_types:
          items:
            type: string
          title: Event Types
          type: array
        failure_threshold:
          title: Failure Threshold
          type: integer
        has_channel_credentials:
          default: false
          title: Has Channel Credentials
          type: boolean
        id:
          format: uuid
          title: Id
          type: string
        is_active:
          title: Is Active
          type: boolean
        last_execution_at:
          anyOf:
            - type: string
            - type: 'null'
          title: Last Execution At
        name:
          title: Name
          type: string
        next_run_time:
          anyOf:
            - type: string
            - type: 'null'
          title: Next Run Time
        task_parameters:
          additionalProperties: true
          title: Task Parameters
          type: object
        timezone:
          anyOf:
            - type: string
            - type: 'null'
          title: Timezone
        trigger_type:
          title: Trigger Type
          type: string
        updated_at:
          title: Updated At
          type: string
        validation_rules:
          anyOf:
            - additionalProperties: true
              type: object
            - type: 'null'
          title: Validation Rules
        webhook_config:
          anyOf:
            - additionalProperties: true
              type: object
            - type: 'null'
          title: Webhook Config
        webhook_id:
          anyOf:
            - type: string
            - type: 'null'
          title: Webhook Id
        webhook_type:
          anyOf:
            - type: string
            - type: 'null'
          title: Webhook Type
      required:
        - id
        - name
        - description
        - agent_id
        - trigger_type
        - is_active
        - task_parameters
        - conditions
        - created_at
        - updated_at
        - created_by
        - failure_threshold
        - consecutive_failures
      title: TriggerResponse
      type: object
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          title: Detail
          type: array
      title: HTTPValidationError
      type: object
    ValidationError:
      properties:
        ctx:
          title: Context
          type: object
        input:
          title: Input
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          title: Location
          type: array
        msg:
          title: Message
          type: string
        type:
          title: Error Type
          type: string
      required:
        - loc
        - msg
        - type
      title: ValidationError
      type: object
  securitySchemes:
    bearer:
      bearerFormat: JWT
      description: JWT Bearer token for authentication
      scheme: bearer
      type: http
    HTTPBearer:
      scheme: bearer
      type: http

````