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

# /realms/{realmId}/organizations/{organizationId}/business-policies/generate-policy



## OpenAPI

````yaml /api-reference/ruleengine.openapi.json post /realms/{realmId}/organizations/{organizationId}/business-policies/generate-policy
openapi: 3.0.3
info:
  title: Ruleengine
  version: 1.0.0
  description: >-
    Portão 3 ruleengine API. Generated by tools/openapi from code (routes +
    security) and the hand-written spec (request/response bodies). Confidence
    tiers: generated:typed=25 copied:manual=0 unknown=0.
servers:
  - url: https://api.ruleengine.v2.portao3.com.br/
    description: production
  - url: https://api.ruleengine.dev.3pers.com.br/
    description: development
security:
  - bearerAuth: []
tags:
  - name: Business Policies
  - name: Policy Evaluations
  - name: Policy Requests
paths:
  /realms/{realmId}/organizations/{organizationId}/business-policies/generate-policy:
    post:
      tags:
        - Business Policies
      summary: >-
        /realms/{realmId}/organizations/{organizationId}/business-policies/generate-policy
      operationId: >-
        postRealmsByRealmIdOrganizationsByOrganizationIdBusinessPoliciesGeneratePolicy
      parameters:
        - name: realmId
          in: path
          required: true
          schema:
            type: string
        - name: organizationId
          in: path
          required: true
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                context:
                  type: string
                  enum:
                    - PAYMENT
                    - SPEND_REVIEW
                    - TRAVEL
                prompt:
                  type: string
                  minLength: 3
                  maxLength: 2000
                includeWallets:
                  type: boolean
              required:
                - context
                - prompt
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                type: object
                properties:
                  policy:
                    type: object
                    properties:
                      realmId:
                        type: string
                      organizationId:
                        type: string
                      context:
                        type: string
                        enum:
                          - PAYMENT
                          - SPEND_REVIEW
                          - TRAVEL
                        description: The business surface a policy governs.
                      name:
                        type: string
                      description:
                        type: string
                      order:
                        type: number
                        description: Evaluation sorts ascending; first match wins.
                      status:
                        type: string
                        enum:
                          - ACTIVE
                          - DISABLED
                          - ARCHIVED
                        description: >-
                          `ARCHIVED` is a soft delete: terminal, set only
                          through the archive endpoint, and never evaluated
                          against a transaction.
                      actions:
                        type: object
                        properties:
                          hierarchy:
                            type: boolean
                            description: >-
                              true = approvals resolve one-by-one in array
                              order.
                          autoAction:
                            type: string
                            enum:
                              - APPROVE
                              - DENY
                              - NONE
                            description: >-
                              What happens when a policy matches:

                              - `APPROVE` — allowed outright, no policy-request

                              - `DENY` — refused outright

                              - `NONE` — an approval flow is required
                              (`approvals` must be non-empty)
                          moveBalance:
                            type: object
                            properties:
                              addBalance:
                                type: boolean
                              fromAccountId:
                                type: string
                                description: Required when `addBalance` is true.
                              fromWalletId:
                                type: string
                                description: Required when `addBalance` is true.
                            required:
                              - addBalance
                          approvals:
                            type: array
                            items:
                              type: object
                              properties:
                                type:
                                  type: string
                                  enum:
                                    - USER
                                    - GROUP
                                id:
                                  type: string
                                  description: >-
                                    userId when type=USER, identity groupId when
                                    type=GROUP.
                                name:
                                  type: string
                              required:
                                - id
                                - type
                              description: >-
                                A participant as RENDERED on a read: the
                                persisted spec plus the display name resolved at
                                read time.


                                `name` is never accepted on input and never
                                persisted — a request body carrying it is
                                rejected. It is optional on the way out: a
                                participant whose name cannot be resolved is
                                returned without one.
                            description: >-
                              Non-empty when autoAction=NONE; empty/absent
                              otherwise.
                        required:
                          - autoAction
                          - hierarchy
                        description: >-
                          `BusinessPolicyActions` as rendered — approvals carry
                          their live name.
                      conditions:
                        type: object
                        properties:
                          logic:
                            type: string
                            enum:
                              - AND
                              - OR
                          groups:
                            type: array
                            items:
                              type: object
                              properties:
                                logic:
                                  type: string
                                  enum:
                                    - AND
                                    - OR
                                dependsOn:
                                  type: array
                                  items:
                                    type: string
                                items:
                                  type: array
                                  items:
                                    type: object
                                    properties:
                                      operator:
                                        type: string
                                        description: >-
                                          Same ConditionOperator union the
                                          security rules use (incl. LLM_EVALUATE).
                                      field:
                                        type: string
                                      maskType:
                                        type: string
                                      dynamicFieldValue:
                                        type: string
                                      value: {}
                                    required:
                                      - operator
                                      - field
                              required:
                                - logic
                                - items
                            description: >-
                              An EMPTY array matches unconditionally — the
                              catch-all/default policy.
                        required:
                          - logic
                          - groups
                    required:
                      - realmId
                      - organizationId
                      - context
                      - name
                      - order
                      - status
                      - actions
                      - conditions
                    description: >-
                      `POST .../business-policies/generate-policy` response — a
                      DRAFT policy. It is NOT persisted and has no `id`: submit
                      it through the create route to save it (stripping
                      `actions.approvals[].name`, which the create route
                      rejects, exactly as the edit flow already does).
                  unsupported:
                    type: array
                    items:
                      type: string
                    description: >-
                      Restrictions the request asked for that this policy does
                      NOT express — for example a wallet whose id was not
                      supplied. Empty when everything was captured.


                      Always show these before the draft is saved: the policy is
                      otherwise valid and will govern MORE payments than the
                      request described.
                required:
                  - policy
                  - unsupported
                description: >-
                  `POST .../business-policies/generate-policy` response.


                  `policy` is create-compatible: submit it to `POST
                  .../business-policies` as it stands, minus
                  `actions.approvals[].name` (the create route rejects that,
                  exactly as it does on edit).
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT

````