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

# Update automation rule

> Update an existing automation rule. Only provided fields will be updated.



## OpenAPI

````yaml /openapi.json patch /api/public/v1/automation/{id}
openapi: 3.0.3
info:
  title: MSPortal Public API
  version: 1.0.0
  description: >-
    Public API for MSPortal - provides programmatic access to tenant data.


    ## Authentication


    All endpoints require authentication via API key passed as a Bearer token:


    ```

    Authorization: Bearer <your-api-key>

    ```


    API keys can be created in the MSPortal dashboard under Settings →
    Integrations → API Access.


    **Important:** Do not include cookies in API requests. The public API uses
    stateless authentication only.


    ## Scopes


    API keys are granted specific scopes that determine what operations they can
    perform. Each endpoint documents its required scope(s).


    ## Rate Limiting


    API calls are rate limited per API key. Rate limit information is returned
    in response headers:


    - `X-RateLimit-Limit`: Maximum requests per minute

    - `X-RateLimit-Remaining`: Remaining requests in current window

    - `X-RateLimit-Reset`: When the rate limit resets (ISO 8601)


    ## Request ID


    All responses include an `X-Request-Id` header for debugging and support.
    You can also pass your own `X-Request-Id` header to correlate requests.
  contact:
    name: MSPortal Support
    email: support@msportal.ai
  license:
    name: Proprietary
servers:
  - url: https://app.msportal.ai
    description: Production environment
security:
  - BearerAuth: []
tags:
  - name: Budgets
    description: >-
      Budget management - create, track, and forecast budgets with line items,
      categories, and products
  - name: Calendar
    description: Calendar and meeting management - events, participants, and meeting types
  - name: Companies
    description: Company management endpoints
  - name: Company Users
    description: Company user management - client portal contacts (read-only, paginated)
  - name: Compliance
    description: Compliance check management - runs, assigned checks, and status updates
  - name: Dashboards
    description: Dashboard management - external iframe resources and internal dashboards
  - name: Devices
    description: Device management - inventory, types, and locations
  - name: Goals
    description: Goal management - create, track, and manage goals with tasks and updates
  - name: NPS Surveys
    description: >-
      NPS survey management - Net Promoter Score surveys, responses, and
      analytics
  - name: Reports
    description: >-
      Report management - create, manage, and schedule reports with templates
      and types
  - name: Planner
    description: >-
      Planner item management - tasks, roadmap items, and project planning with
      linked goals, compliance, and projects
  - name: Surveys
    description: >-
      General survey management - multi-question surveys, responses, and
      statistics
  - name: Tickets
    description: Ticket management - view and filter tickets from PSA integrations
  - name: Training
    description: >-
      Training management - courses, enrollments, certificates, and progress
      tracking
  - name: Users
    description: Tenant user management - internal staff and team members (read-only)
  - name: Automation Rules
    description: >-
      Automation rule management - create, configure, and monitor automation
      rules with triggers, conditions, and actions
  - name: Analytics
    description: >-
      Analytics and reporting - company audit data, training analytics, user
      activity, and portfolio metrics
paths:
  /api/public/v1/automation/{id}:
    patch:
      tags:
        - Automation Rules
      summary: Update automation rule
      description: >-
        Update an existing automation rule. Only provided fields will be
        updated.
      parameters:
        - schema:
            type: string
            format: uuid
            description: Rule ID
          required: true
          description: Rule ID
          name: id
          in: path
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/UpdateAutomationRuleRequest'
      responses:
        '200':
          description: Rule updated successfully
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AutomationRuleSingleResponse'
        '400':
          description: Validation error or duplicate name
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '403':
          description: Forbidden - Missing required scope (automation.write)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '404':
          description: Rule not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
      security:
        - BearerAuth: []
components:
  schemas:
    UpdateAutomationRuleRequest:
      type: object
      properties:
        name:
          type: string
          minLength: 1
          maxLength: 200
          description: Rule name
        description:
          type: string
          nullable: true
          maxLength: 1000
          description: Rule description
        isActive:
          type: boolean
          description: Whether the rule is active
        priority:
          type: integer
          minimum: 0
          maximum: 100
          description: Rule priority
        scopeType:
          type: string
          enum:
            - tenant
            - company
          description: Rule scope
        companyIds:
          type: array
          nullable: true
          items:
            type: string
            format: uuid
          description: Company IDs
        triggerType:
          type: string
          enum:
            - date_threshold
            - scheduled
            - field_change
            - absence
          description: Trigger type
        triggerConfig:
          type: object
          additionalProperties:
            nullable: true
          description: Trigger-specific configuration
        entityType:
          type: string
          enum:
            - device
            - company
            - compliance
            - planner
            - user
            - goal
            - training
            - ticket
            - meeting
          description: Entity type
        conditions:
          type: array
          items:
            nullable: true
          description: Condition groups
        actions:
          type: array
          items:
            nullable: true
          description: Actions to execute
        aggregationConfig:
          nullable: true
          description: Aggregation configuration
    AutomationRuleSingleResponse:
      type: object
      properties:
        data:
          $ref: '#/components/schemas/AutomationRuleDetail'
      required:
        - data
    ErrorResponse:
      type: object
      properties:
        error:
          type: string
          description: Error message
        requestId:
          type: string
          description: Request correlation ID
        details:
          nullable: true
          description: Additional error details
        code:
          type: string
          description: Error code
      required:
        - error
    AutomationRuleDetail:
      type: object
      properties:
        id:
          type: string
          format: uuid
          description: Rule ID
        name:
          type: string
          description: Rule name
        description:
          type: string
          nullable: true
          description: Rule description
        isActive:
          type: boolean
          description: Whether the rule is active
        priority:
          type: number
          description: Rule priority (lower = higher priority)
        scopeType:
          type: string
          enum:
            - tenant
            - company
          description: Scope type
        companyIds:
          type: array
          nullable: true
          items:
            type: string
            format: uuid
          description: Company IDs
        triggerType:
          type: string
          description: Trigger type
        entityType:
          type: string
          description: Entity type
        triggerConfig:
          type: object
          additionalProperties:
            nullable: true
          description: Trigger-specific configuration
        conditions:
          type: array
          items:
            $ref: '#/components/schemas/RuleConditionGroup'
          description: Condition groups
        actions:
          type: array
          items:
            $ref: '#/components/schemas/RuleAction'
          description: Actions to execute
        aggregationConfig:
          $ref: '#/components/schemas/RuleAggregationConfig'
        companies:
          type: array
          items:
            $ref: '#/components/schemas/RuleCompanyRef'
          description: Company details for company-scoped rules
        createdBy:
          $ref: '#/components/schemas/RuleUserRef'
        updatedBy:
          allOf:
            - $ref: '#/components/schemas/RuleUserRef'
            - description: User who last updated the rule
        createdAt:
          type: string
          format: date-time
          description: Creation timestamp
        updatedAt:
          type: string
          format: date-time
          description: Last update timestamp
        version:
          type: number
          description: Rule version for optimistic locking
      required:
        - id
        - name
        - description
        - isActive
        - priority
        - scopeType
        - companyIds
        - triggerType
        - entityType
        - triggerConfig
        - conditions
        - actions
        - aggregationConfig
        - createdBy
        - updatedBy
        - createdAt
        - updatedAt
        - version
    RuleConditionGroup:
      type: object
      properties:
        id:
          type: string
          description: Condition group ID
        logic:
          type: string
          enum:
            - AND
            - OR
          description: Logic operator for combining conditions
        conditions:
          type: array
          items:
            $ref: '#/components/schemas/RuleCondition'
          description: Conditions in this group
        groups:
          type: array
          items:
            nullable: true
          description: Nested condition groups (recursive)
      required:
        - id
        - logic
        - conditions
    RuleAction:
      type: object
      properties:
        id:
          type: string
          description: Action ID
        actionType:
          type: string
          description: >-
            Type of action (add_to_planner, update_field, send_email,
            in_app_alert, open_ticket, ai_transform)
        config:
          type: object
          additionalProperties:
            nullable: true
          description: Action-specific configuration
        order:
          type: number
          description: Order of execution
        requiresApproval:
          type: boolean
          description: Whether this action requires human approval
      required:
        - id
        - actionType
        - config
        - order
    RuleAggregationConfig:
      type: object
      nullable: true
      properties:
        enabled:
          type: boolean
          description: Whether aggregation is enabled
        groupBy:
          type: string
          description: How to group matches (none, day, week, month, quarter)
        groupField:
          type: string
          description: Field to group by
        minBatchSize:
          type: number
          description: Minimum items before triggering
        maxWaitHours:
          type: number
          description: Maximum wait time before triggering
        combinedActionConfig:
          type: object
          properties:
            titleTemplate:
              type: string
              description: Template for combined action title
            descriptionTemplate:
              type: string
              description: Template for combined action description
          required:
            - titleTemplate
            - descriptionTemplate
          description: Configuration for combined actions
      required:
        - enabled
        - groupBy
    RuleCompanyRef:
      type: object
      properties:
        id:
          type: string
          format: uuid
          description: Company ID
        name:
          type: string
          description: Company name
      required:
        - id
        - name
    RuleUserRef:
      type: object
      nullable: true
      properties:
        id:
          type: string
          format: uuid
          description: User ID
        name:
          type: string
          description: User name
      required:
        - id
        - name
      description: User who created the rule
    RuleCondition:
      type: object
      properties:
        id:
          type: string
          description: Condition ID
        field:
          type: string
          description: Field to evaluate
        operator:
          type: string
          description: Comparison operator
        value:
          nullable: true
          description: Value to compare against
      required:
        - id
        - field
        - operator
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      bearerFormat: API Key
      description: >-
        Use your API key as a Bearer token. API keys can be generated in
        Settings → Integrations → API Access.

````