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

# Create an action rule

> Write an account-scoped rule using its validated definition. Send Accept: application/json for JSON errors. New rules start disabled.



## OpenAPI

````yaml https://plainrouter.com/openapi.json post /agent/workspaces/{workspace}/action-rules
openapi: 3.1.0
info:
  title: Plainrouter Conversion API
  version: 0.5.0
  description: Plainrouter public Signals Conversion API.
servers:
  - url: https://plainrouter.com/api/v1
    description: Production
security:
  - workspaceSecret: []
paths:
  /agent/workspaces/{workspace}/action-rules:
    post:
      tags:
        - ActionRuleApi
      summary: Create an action rule
      description: >-
        Write an account-scoped rule using its validated definition. Send
        Accept: application/json for JSON errors. New rules start disabled.
      operationId: actions.rules.store
      parameters:
        - name: workspace
          in: path
          required: true
          description: The workspace ID
          schema:
            type: integer
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              description: >-
                Creates a disabled rule. enabled must be absent. window,
                window_days, author_type and current_revision_id must be absent
                or empty.
              properties:
                name:
                  type: string
                  pattern: \S
                  maxLength: 255
                definition:
                  anyOf:
                    - type: object
                      description: >-
                        Only target_level, action, budget_change_percent,
                        minimum_counted_arrivals, cost_comparison and cost_ratio
                        are accepted.
                      properties:
                        target_level:
                          type: string
                          enum:
                            - ad
                            - ad_set
                        action:
                          enum:
                            - pause
                          type: string
                        minimum_counted_arrivals:
                          type: integer
                          minimum: 50
                          maximum: 9223372036854776000
                        cost_comparison:
                          type: string
                          enum:
                            - at_least
                            - at_most
                        cost_ratio:
                          description: >-
                            Numeric value from 0.10 to 10.00, with zero to two
                            decimal places.
                          anyOf:
                            - type: number
                              minimum: 0.1
                              maximum: 10
                              multipleOf: 0.01
                            - type: string
                              pattern: >-
                                ^\+?0*(?:\.[1-9][0-9]?|[1-9](?:\.[0-9]{0,2})?|10(?:\.0{0,2})?)$
                      required:
                        - target_level
                        - action
                        - minimum_counted_arrivals
                        - cost_comparison
                        - cost_ratio
                      additionalProperties: false
                    - type: object
                      description: >-
                        Only target_level, action, budget_change_percent,
                        minimum_counted_arrivals, cost_comparison and cost_ratio
                        are accepted.
                      properties:
                        target_level:
                          type: string
                          enum:
                            - ad_set
                            - campaign
                        action:
                          enum:
                            - increase_budget
                          type: string
                        minimum_counted_arrivals:
                          type: integer
                          minimum: 100
                          maximum: 9223372036854776000
                        cost_comparison:
                          type: string
                          enum:
                            - at_least
                            - at_most
                        cost_ratio:
                          description: >-
                            Numeric value from 0.10 to 10.00, with zero to two
                            decimal places.
                          anyOf:
                            - type: number
                              minimum: 0.1
                              maximum: 10
                              multipleOf: 0.01
                            - type: string
                              pattern: >-
                                ^\+?0*(?:\.[1-9][0-9]?|[1-9](?:\.[0-9]{0,2})?|10(?:\.0{0,2})?)$
                        budget_change_percent:
                          type: integer
                          minimum: 1
                          maximum: 50
                      required:
                        - target_level
                        - action
                        - minimum_counted_arrivals
                        - cost_comparison
                        - cost_ratio
                        - budget_change_percent
                      additionalProperties: false
                    - type: object
                      description: >-
                        Only target_level, action, budget_change_percent,
                        minimum_counted_arrivals, cost_comparison and cost_ratio
                        are accepted.
                      properties:
                        target_level:
                          type: string
                          enum:
                            - ad_set
                            - campaign
                        action:
                          enum:
                            - decrease_budget
                          type: string
                        minimum_counted_arrivals:
                          type: integer
                          minimum: 50
                          maximum: 9223372036854776000
                        cost_comparison:
                          type: string
                          enum:
                            - at_least
                            - at_most
                        cost_ratio:
                          description: >-
                            Numeric value from 0.10 to 10.00, with zero to two
                            decimal places.
                          anyOf:
                            - type: number
                              minimum: 0.1
                              maximum: 10
                              multipleOf: 0.01
                            - type: string
                              pattern: >-
                                ^\+?0*(?:\.[1-9][0-9]?|[1-9](?:\.[0-9]{0,2})?|10(?:\.0{0,2})?)$
                        budget_change_percent:
                          type: integer
                          minimum: 1
                          maximum: 50
                      required:
                        - target_level
                        - action
                        - minimum_counted_arrivals
                        - cost_comparison
                        - cost_ratio
                        - budget_change_percent
                      additionalProperties: false
                account_id:
                  type: integer
                  description: >-
                    Optional account ID, ignored by an account-bound key. An
                    unbound key requires exactly one active available
                    advertising account with an active connection; omission uses
                    that account and a supplied ID must match it. Multiple
                    active accounts return 422 even when account_id is supplied.
                  minimum: 1
                platform_ad_account_id:
                  minimum: 1
                  type: integer
                enabled:
                  not: {}
                window:
                  anyOf:
                    - type: 'null'
                    - const: ''
                    - type: array
                      items: {}
                      maxItems: 0
                    - type: object
                      maxProperties: 0
                window_days:
                  anyOf:
                    - type: 'null'
                    - const: ''
                    - type: array
                      items: {}
                      maxItems: 0
                    - type: object
                      maxProperties: 0
                author_type:
                  anyOf:
                    - type: 'null'
                    - const: ''
                    - type: array
                      items: {}
                      maxItems: 0
                    - type: object
                      maxProperties: 0
                current_revision_id:
                  anyOf:
                    - type: 'null'
                    - const: ''
                    - type: array
                      items: {}
                      maxItems: 0
                    - type: object
                      maxProperties: 0
              required:
                - name
                - platform_ad_account_id
                - definition
      responses:
        '201':
          description: Saved rule with immutable revisions; no runs are included.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ActionRuleWriteRead'
        '401':
          description: Missing, invalid, expired or revoked workspace key.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorMessage'
        '403':
          description: Insufficient ability or grant, or a conflicting workspace selector.
          content:
            application/json:
              schema:
                anyOf:
                  - $ref: '#/components/schemas/ErrorMessage'
                  - type: object
                    properties:
                      error:
                        type: string
                        enum:
                          - insufficient_scope
                      error_description:
                        type: string
                    required:
                      - error
                      - error_description
        '404':
          description: Workspace, account or rule unavailable in this scope.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiRouteNotFound'
        '422':
          description: >-
            Invalid rule input or account ID, mismatched account binding, or
            ambiguous active accounts.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ValidationError'
        '429':
          description: The shared API rate limit is exceeded.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorMessage'
          headers:
            Retry-After:
              description: Seconds until a retry is allowed.
              schema:
                type: integer
        '503':
          description: The bounded workspace transaction timed out; retry after one second.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/WorkspaceLockTimeout'
          headers:
            Retry-After:
              description: Seconds until the operation may be retried.
              required: true
              schema:
                type: integer
                enum:
                  - 1
      security:
        - ruleWriter: []
components:
  schemas:
    ActionRuleWriteRead:
      type: object
      properties:
        rule:
          type: object
          properties:
            id:
              type: string
            workspace_id:
              type: integer
            platform_ad_account_id:
              type: integer
            name:
              type: string
            enabled:
              type: boolean
            suspended_at:
              type:
                - string
                - 'null'
              format: date-time
            suspended_reason:
              type:
                - string
                - 'null'
            window:
              type: object
              properties:
                days:
                  type: integer
                  enum:
                    - 3
                kind:
                  type: string
                  enum:
                    - last_complete_days
                timezone:
                  type: string
              required:
                - days
                - kind
                - timezone
            current_revision:
              type: object
              properties:
                id:
                  type: string
                target_level:
                  type: string
                  enum:
                    - ad
                    - ad_set
                    - campaign
                action:
                  type: string
                  enum:
                    - pause
                    - increase_budget
                    - decrease_budget
                budget_change_percent:
                  type:
                    - integer
                    - 'null'
                minimum_counted_arrivals:
                  type: integer
                cost_comparison:
                  type: string
                  enum:
                    - at_least
                    - at_most
                cost_ratio:
                  type: string
                author_type:
                  type: string
                  enum:
                    - user
                    - agent
                created_at:
                  type: string
                  format: date-time
              required:
                - id
                - target_level
                - action
                - budget_change_percent
                - minimum_counted_arrivals
                - cost_comparison
                - cost_ratio
                - author_type
                - created_at
            revisions:
              type: array
              description: Present on show and write responses.
              items:
                type: object
                properties:
                  id:
                    type: string
                  target_level:
                    type: string
                    enum:
                      - ad
                      - ad_set
                      - campaign
                  action:
                    type: string
                    enum:
                      - pause
                      - increase_budget
                      - decrease_budget
                  budget_change_percent:
                    type:
                      - integer
                      - 'null'
                  minimum_counted_arrivals:
                    type: integer
                  cost_comparison:
                    type: string
                    enum:
                      - at_least
                      - at_most
                  cost_ratio:
                    type: string
                  author_type:
                    type: string
                    enum:
                      - user
                      - agent
                  created_at:
                    type: string
                    format: date-time
                required:
                  - id
                  - target_level
                  - action
                  - budget_change_percent
                  - minimum_counted_arrivals
                  - cost_comparison
                  - cost_ratio
                  - author_type
                  - created_at
          required:
            - id
            - workspace_id
            - platform_ad_account_id
            - name
            - enabled
            - suspended_at
            - suspended_reason
            - window
            - current_revision
            - revisions
      required:
        - rule
      title: ActionRuleWriteRead
    ErrorMessage:
      type: object
      properties:
        message:
          type: string
      required:
        - message
      title: ErrorMessage
    ApiRouteNotFound:
      type: object
      properties:
        error:
          type: object
          properties:
            code:
              type: string
              enum:
                - api_route_not_found
            message:
              type: string
            resolution:
              type: string
          required:
            - code
            - message
            - resolution
        request:
          type: object
          properties:
            method:
              type: string
            path:
              type: string
          required:
            - method
            - path
        resources:
          type: object
          properties:
            documentation:
              type: string
            openapi:
              type: string
          required:
            - documentation
            - openapi
      required:
        - error
        - request
        - resources
      title: ApiRouteNotFound
    ValidationError:
      type: object
      properties:
        message:
          type: string
        errors:
          type: object
          additionalProperties:
            type: array
            items:
              type: string
      required:
        - message
        - errors
      title: ValidationError
    WorkspaceLockTimeout:
      type: object
      properties:
        error:
          type: object
          properties:
            code:
              type: string
              enum:
                - workspace_lock_timeout
            message:
              type: string
          required:
            - code
            - message
      required:
        - error
      title: WorkspaceLockTimeout
  securitySchemes:
    workspaceSecret:
      type: http
      description: >-
        Per-workspace Server secret. It authenticates only the Signals workspace
        represented by the credential.
      scheme: bearer
    ruleWriter:
      type: http
      description: >-
        A workspace-scoped key with write ability and the actions.rules.store or
        actions.rules.update grant. Send Accept: application/json.
      scheme: bearer

````

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