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

# Execute a workflow for a SendGrid inbound email

> Internal service endpoint that runs a workflow against an inbound SendGrid email payload. Authenticated via the INTERNAL_SERVICE_TOKEN bearer (not user auth). Validates the email payload (from / to / subject required) and rejects unauthorized requests with 403.



## OpenAPI

````yaml /api-reference/openapi.yaml post /api/workflows/{id}/execute/sendgrid-inbound
openapi: 3.0.3
info:
  title: Tether Relay and Tether API
  version: 1.0.0
  description: >-
    Route-derived OpenAPI contract generated from tether-relay backend sources.
    Regenerate with scripts/sync-openapi-from-backend.mjs.
servers:
  - url: https://your-instance.example.com
    description: Production
  - url: http://localhost:2212
    description: Local API service
security: []
tags:
  - name: AI
  - name: Applications
  - name: Approval
  - name: Auth
  - name: Automations
  - name: Calls
  - name: Campaigns
  - name: Contact Analytics
  - name: Contact Metrics
  - name: Contact Notes
  - name: Contacts
  - name: Conversation Monitor
  - name: Conversations
  - name: Departments
  - name: Email
  - name: Escalation Dashboard
  - name: Event Logs
  - name: Google Sheets
  - name: Marketplace
  - name: Messages
  - name: Notification Sounds
  - name: Notifications
  - name: Org Snapshots
  - name: Organizations
  - name: Outreach
  - name: Outreach Metrics
  - name: Outreach Sources
  - name: Pipelines
  - name: Processes
  - name: Prompts
  - name: Reminders
  - name: Sms
  - name: Templates
  - name: Traces
  - name: Training
  - name: Upload
  - name: User Snapshots
  - name: Users
  - name: Vertical
  - name: Webchats
  - name: Webhook
paths:
  /api/workflows/{id}/execute/sendgrid-inbound:
    post:
      tags:
        - Workflows
      summary: Execute a workflow for a SendGrid inbound email
      description: >-
        Internal service endpoint that runs a workflow against an inbound
        SendGrid email payload. Authenticated via the INTERNAL_SERVICE_TOKEN
        bearer (not user auth). Validates the email payload (from / to / subject
        required) and rejects unauthorized requests with 403.
      operationId: post_workflows_execute_sendgrid_inbound
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/WorkflowSendGridInboundRequest'
      responses:
        '200':
          description: Workflow executed successfully
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/WorkflowExecuteSendGridInboundResponse'
        '400':
          description: Missing or invalid email data
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/WorkflowsErrorResponse'
        '403':
          description: Unauthorized internal service request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/WorkflowsErrorResponse'
        '404':
          description: Workflow not found or not enabled
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/WorkflowsErrorResponse'
        '500':
          description: Error executing workflow
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/WorkflowsErrorResponse'
components:
  schemas:
    WorkflowSendGridInboundRequest:
      type: object
      description: >-
        Internal service payload forwarded by an inbound-email adapter (e.g.
        `services/sendgrid-inbound`). The workflow is run against the supplied
        email under the specified organization.
      properties:
        organizationId:
          type: string
          description: >-
            Owning organization for the run — must match the workflow's
            `organizationId`.
        userId:
          type: string
          description: >-
            Optional User `_id` to attribute the run to. Falls back to the
            workflow's creator when omitted.
        emailData:
          type: object
          description: >-
            Parsed inbound email payload. Either supply the flat fields
            (`from`/`to`/`subject`/…) or a nested `email` object — `from`, `to`,
            and `subject` are required.
          properties:
            email:
              $ref: '#/components/schemas/SendGridInboundEmailPayload'
              description: >-
                Nested form of the parsed email payload (alternative to the flat
                sibling fields).
            from:
              type: string
              description: RFC-5322 sender address of the inbound email.
            to:
              description: >-
                Recipient address(es) the email was delivered to — string or
                array of strings.
              oneOf:
                - type: string
                - type: array
                  items:
                    type: string
            subject:
              type: string
              description: >-
                Email subject line — used by `InboxDropTrigger` subject-match
                filters.
            body:
              type: string
              description: Plain-text body of the email.
            bodyHtml:
              type: string
              description: HTML body of the email when provided by the upstream parser.
            headers:
              type: object
              description: Raw email headers map (e.g. `Message-ID`, `In-Reply-To`).
              additionalProperties: true
            attachments:
              type: array
              description: >-
                Parsed attachment descriptors — typically `{ filename, url }`
                references to provider-hosted blobs.
              items:
                type: object
                additionalProperties: true
            metadata:
              type: object
              description: >-
                Adapter-supplied context (e.g. `receivedAt`, `source`,
                `leadManagementId`) forwarded to the trigger.
              additionalProperties: true
          additionalProperties: true
      required:
        - organizationId
        - emailData
      additionalProperties: true
      example:
        organizationId: 64a1b2c3d4e5f60012345678
        userId: 64a1b2c3d4e5f60012345679
        emailData:
          email:
            from: alex.nguyen@example.com
            to: inbound+org-64a1b@inbound.tetherai.ca
            subject: Question about Maple Court
            body: Hi — could you confirm the unit availability for next month?
          metadata:
            messageId: sg_msg_1234567890
    WorkflowExecuteSendGridInboundResponse:
      type: object
      description: >-
        Returned by `POST /api/workflows/{id}/execute/sendgrid-inbound` after
        the internal service hands off the email payload to the workflow engine.
      properties:
        success:
          type: boolean
          enum:
            - true
        message:
          type: string
      required:
        - success
        - message
      additionalProperties: true
      example:
        success: true
        message: Workflow executed successfully
    WorkflowsErrorResponse:
      type: object
      description: Standard error envelope for Workflows endpoints.
      properties:
        success:
          type: boolean
          enum:
            - false
        message:
          type: string
      required:
        - success
      additionalProperties: true
      example:
        success: false
        message: Workflow not found
    SendGridInboundEmailPayload:
      type: object
      properties:
        from:
          type: string
        to:
          oneOf:
            - type: string
            - type: array
              items:
                type: string
        subject:
          type: string
        body:
          type: string
        bodyHtml:
          type: string
        headers:
          type: object
          additionalProperties: true
        attachments:
          type: array
          items:
            type: object
            additionalProperties: true
      required:
        - from
        - to
        - subject
      additionalProperties: true
      example:
        from: alex.nguyen@example.com
        to:
          - inbound+org-64a1b@inbound.tetherai.ca
        subject: Question about Maple Court
        body: Hi — could you confirm the unit availability for next month?
        bodyHtml: <p>Hi — could you confirm the unit availability for next month?</p>
        headers:
          Message-ID: <abc123@mail.example.com>
        attachments: []

````