Onecli Organization Rules API

Manage policy rules at the organization level. Organization rules apply across all projects. Available on OneCLI Cloud and self-hosted Enterprise.

OpenAPI Specification

onecli-organization-rules-api-openapi.yml Raw ↑
openapi: 3.1.0
info:
  title: OneCLI Agent Setup Organization Rules API
  version: '1.0'
  description: 'The OneCLI API lets you manage agents, secrets, policy rules, app connections, and user settings programmatically.


    **Base URL:** `https://api.onecli.sh/v1` (Cloud) or `http://localhost:10254/v1` (self-hosted)


    ## Authentication


    All endpoints require authentication via one of:


    - **API Key** — `Authorization: Bearer <key>` header. Generate keys in the dashboard or via `GET /v1/user/api-key`.

    - **Session** — Cookie-based session from the web dashboard.


    For organization-scoped API keys, include the `X-Project-Id` header to specify which project to operate on.

    '
servers:
- url: https://api.onecli.sh/v1
  description: OneCLI Cloud
- url: http://localhost:10254/v1
  description: Self-hosted (Docker)
security:
- bearerAuth: []
tags:
- name: Organization Rules
  description: Manage policy rules at the organization level. Organization rules apply across all projects. Available on OneCLI Cloud and self-hosted Enterprise.
paths:
  /org/rules:
    get:
      operationId: listOrgRules
      summary: List organization rules
      description: Returns all policy rules scoped to the organization. Available on OneCLI Cloud and self-hosted Enterprise. Requires the admin or owner role.
      tags:
      - Organization Rules
      responses:
        '200':
          description: List of organization rules
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/PolicyRule'
    post:
      operationId: createOrgRule
      summary: Create an organization rule
      description: 'Creates a new policy rule at the organization level. Organization rules apply across all projects and cannot be assigned to specific agents. Requires admin role. Available on OneCLI Cloud and self-hosted Enterprise.

        '
      tags:
      - Organization Rules
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
              - name
              - hostPattern
              - action
              - enabled
              properties:
                name:
                  type: string
                  minLength: 1
                  maxLength: 255
                hostPattern:
                  type: string
                pathPattern:
                  type: string
                method:
                  type: string
                  enum:
                  - GET
                  - POST
                  - PUT
                  - PATCH
                  - DELETE
                action:
                  type: string
                  enum:
                  - block
                  - rate_limit
                  - manual_approval
                  - allow
                enabled:
                  type: boolean
                rateLimit:
                  type: integer
                  minimum: 1
                rateLimitWindow:
                  type: string
                  enum:
                  - minute
                  - hour
                  - day
                conditions:
                  type: array
                  items:
                    $ref: '#/components/schemas/RuleCondition'
      responses:
        '201':
          description: Rule created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PolicyRule'
        '400':
          description: Validation error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '403':
          description: Insufficient permissions
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
  /org/rules/{ruleId}:
    get:
      operationId: getOrgRule
      summary: Get an organization rule
      description: Available on OneCLI Cloud and self-hosted Enterprise. Requires the admin or owner role.
      tags:
      - Organization Rules
      parameters:
      - $ref: '#/components/parameters/ruleId'
      responses:
        '200':
          description: Rule details
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PolicyRule'
        '404':
          description: Rule not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
    patch:
      operationId: updateOrgRule
      summary: Update an organization rule
      description: Requires admin role. Available on OneCLI Cloud and self-hosted Enterprise.
      tags:
      - Organization Rules
      parameters:
      - $ref: '#/components/parameters/ruleId'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                name:
                  type: string
                hostPattern:
                  type: string
                pathPattern:
                  type: string
                  nullable: true
                method:
                  type: string
                  enum:
                  - GET
                  - POST
                  - PUT
                  - PATCH
                  - DELETE
                  nullable: true
                action:
                  type: string
                  enum:
                  - block
                  - rate_limit
                  - manual_approval
                  - allow
                enabled:
                  type: boolean
                rateLimit:
                  type: integer
                  nullable: true
                rateLimitWindow:
                  type: string
                  enum:
                  - minute
                  - hour
                  - day
                  nullable: true
                conditions:
                  type: array
                  nullable: true
                  items:
                    $ref: '#/components/schemas/RuleCondition'
      responses:
        '200':
          description: Rule updated
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
        '403':
          description: Insufficient permissions
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '404':
          description: Rule not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
    delete:
      operationId: deleteOrgRule
      summary: Delete an organization rule
      description: Requires admin role. Available on OneCLI Cloud and self-hosted Enterprise.
      tags:
      - Organization Rules
      parameters:
      - $ref: '#/components/parameters/ruleId'
      responses:
        '204':
          description: Rule deleted
        '403':
          description: Insufficient permissions
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '404':
          description: Rule not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
  /org/rules/permissions/{provider}:
    get:
      operationId: getAppPermissions
      summary: Get app permissions
      description: 'Returns the layered tool-level permission states for a provider at the organization level. The shape matches the project endpoint (`{ defaults, byAgent }`), but organization rules are agent-less, so `byAgent` is always empty. Readable by all members. Available on OneCLI Cloud and self-hosted Enterprise.

        '
      tags:
      - Organization Rules
      parameters:
      - $ref: '#/components/parameters/provider'
      responses:
        '200':
          description: Layered permission states
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AppPermissionStates'
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
    put:
      operationId: setAppPermissions
      summary: Set app permissions
      description: 'Updates tool-level permissions for a provider at the organization level. Organization permissions are agent-less: `agentId` and the `inherit` permission are not accepted here (they are project-scope concepts). Requires admin role. Available on OneCLI Cloud and self-hosted Enterprise.

        '
      tags:
      - Organization Rules
      parameters:
      - $ref: '#/components/parameters/provider'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
              - changes
              properties:
                changes:
                  type: array
                  minItems: 1
                  items:
                    $ref: '#/components/schemas/PermissionChange'
                conditions:
                  type: array
                  maxItems: 10
                  items:
                    $ref: '#/components/schemas/RuleCondition'
      responses:
        '200':
          description: Permissions updated
          content:
            application/json:
              schema:
                type: object
        '400':
          description: Validation error or unknown provider
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '403':
          description: Insufficient permissions (requires admin role)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
  /org/rules/overlap/{provider}:
    get:
      operationId: getOrgRuleOverlap
      summary: Count overlapping custom rules (organization)
      description: Counts custom organization rules whose host patterns overlap the app's hosts. Requires admin role. Available on OneCLI Cloud and self-hosted Enterprise.
      tags:
      - Organization Rules
      parameters:
      - $ref: '#/components/parameters/provider'
      responses:
        '200':
          description: Overlap count
          content:
            application/json:
              schema:
                type: object
                properties:
                  count:
                    type: integer
components:
  schemas:
    PermissionChange:
      type: object
      required:
      - toolId
      - permission
      properties:
        toolId:
          type: string
          minLength: 1
        permission:
          type: string
          enum:
          - allow
          - manual_approval
          - block
    PermissionState:
      type: object
      properties:
        permission:
          type: string
          enum:
          - allow
          - manual_approval
          - block
        conditions:
          type: array
          items:
            type: object
    Error:
      description: 'Error responses take one of two shapes depending on the failing layer:

        route-level validation returns the flat shape (`{ "error": "..." }`),

        while authentication failures (401/403) and service errors (not-found,

        conflict, and service-level validation) return the envelope

        (`{ "error": { "message": "...", "type": "..." } }`).

        '
      oneOf:
      - $ref: '#/components/schemas/ErrorFlat'
      - $ref: '#/components/schemas/ErrorEnvelope'
    PolicyRule:
      type: object
      description: 'A policy rule. Custom (user-authored) rules carry their endpoint fields (`hostPattern`/`pathPattern`/`method`); app-permission rules (`metadata.source: app_permission`) omit them and are identified by `metadata.provider` + `metadata.toolId`.'
      properties:
        id:
          type: string
        name:
          type: string
        hostPattern:
          type: string
          description: Custom rules only; absent on app-permission rules.
        pathPattern:
          type: string
          nullable: true
          description: Custom rules only; absent on app-permission rules.
        method:
          type: string
          nullable: true
          enum:
          - GET
          - POST
          - PUT
          - PATCH
          - DELETE
          - null
          description: Custom rules only; absent on app-permission rules.
        action:
          type: string
          enum:
          - block
          - rate_limit
          - manual_approval
          - allow
        enabled:
          type: boolean
        agentId:
          type: string
          nullable: true
        rateLimit:
          type: integer
          nullable: true
        rateLimitWindow:
          type: string
          nullable: true
          enum:
          - minute
          - hour
          - day
          - null
        scope:
          type: string
          enum:
          - project
          - organization
          description: Project lists include inherited organization rules; use this to tell them apart.
        metadata:
          type: object
          nullable: true
          description: 'Set on rules generated by app permissions (`source: app_permission`, plus `provider` and `toolId`). Null for custom rules.'
        conditions:
          type: array
          items:
            $ref: '#/components/schemas/RuleCondition'
        createdAt:
          type: string
          format: date-time
    ErrorFlat:
      type: object
      description: Flat error shape used by route-level validation.
      properties:
        error:
          type: string
      required:
      - error
    ErrorEnvelope:
      type: object
      description: Envelope error shape used for authentication failures and service errors.
      properties:
        error:
          type: object
          properties:
            message:
              type: string
            type:
              type: string
              description: Error category (e.g. `authentication_error`).
    AppPermissionStates:
      type: object
      description: Layered app-permission states for a provider.
      properties:
        defaults:
          type: object
          description: Tool states from the all-agents layer (tool ID → state).
          additionalProperties:
            $ref: '#/components/schemas/PermissionState'
        byAgent:
          type: object
          description: Per-agent override layers (agent ID → tool ID → state). Always empty at the organization scope, where rules are agent-less.
          additionalProperties:
            type: object
            additionalProperties:
              $ref: '#/components/schemas/PermissionState'
    RuleCondition:
      type: object
      description: A condition that must match for the rule to apply. Conditions inspect the request body to enable fine-grained filtering beyond host/path/method.
      required:
      - target
      - operator
      - value
      properties:
        target:
          type: string
          enum:
          - body
          description: What part of the request to inspect.
        operator:
          type: string
          enum:
          - contains
          description: How to match the value against the target.
        value:
          type: string
          minLength: 1
          maxLength: 1000
          description: The string to match against.
        key:
          type: string
          maxLength: 500
          description: Optional JSON key path within the body to scope the match.
  parameters:
    ruleId:
      name: ruleId
      in: path
      required: true
      schema:
        type: string
    provider:
      name: provider
      in: path
      required: true
      schema:
        type: string
      description: App provider identifier (e.g., `gmail`, `github`, `jira`)
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: API key obtained from the dashboard or `GET /user/api-key`