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

# Crea un flux

> Crea un nou flux d'automatització per a l'organització especificada. El flux defineix la lògica d'execució, les condicions i els workspaces objectius. Retorna les dades del flux creat després d'una creació exitosa.



## OpenAPI

````yaml /ca/api-reference/openapi.ca-v1.json post /v1/organizations/{organization_id}/flows
openapi: 3.0.3
info:
  title: API Publica Portal
  version: 1.0.0
  description: API pública REST per al portal
servers:
  - url: https://api.flexxible.net
    description: Portal API (production)
security:
  - bearerAuth: []
tags: []
paths:
  /v1/organizations/{organization_id}/flows:
    post:
      tags:
        - Fluxos
      summary: Crea un flux
      description: >-
        Crea un nou flux d'automatització per a l'organització especificada. El
        flux defineix la lògica d'execució, les condicions i els workspaces
        objectius. Retorna les dades del flux creat després d'una creació
        exitosa.
      operationId: createFlow
      parameters:
        - name: organization_id
          in: path
          required: true
          schema:
            type: string
            maxLength: 24
            pattern: ^[0-9a-f]{24}$
          description: El identificador únic de l'organització
          example: 507f1f77bcf86cd799439011
        - name: Accept-Language
          in: header
          required: false
          schema:
            type: string
            enum:
              - en-EN
              - es-ES
              - pt-BR
              - ca-ES
              - eu-ES
            default: es-ES
          description: >-
            Codi de idioma per a camps de text que admeten diversos idiomes. Al
            crear o actualitzar recursos, això especifica el idioma dels valors
            de text proporcionats. Al recuperar recursos, això determina quina
            variant de idioma dels camps de text multilingües es retorna. Valors
            acceptats: 'en-EN' (anglès), 'es-ES' (espanyol), 'pt-BR'
            (portuguès), 'ca-ES' (català), 'eu-ES' (euskera). El valor
            predeterminat és 'es-ES' si no es proporciona.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateFlowV1Request'
            examples:
              create-workspace-flow:
                summary: Crear un flux dirigit a workspaces específics
                value:
                  name:
                    en-EN: Daily Backup Flow
                    es-ES: Proceso de copia diaria
                  description:
                    en-EN: Automated daily backup process
                    es-ES: Proceso automatizado de copia de seguridad diaria
                  type: workspace
                  detection_only: false
                  cooldown_minutes: 60
                  enabled: false
                  init_text:
                    en-EN: Starting backup process...
                    es-ES: Iniciando proceso de copia...
                  ok_text:
                    en-EN: Backup completed successfully
                    es-ES: Copia completada correctamente
                  ko_text:
                    en-EN: Backup failed. Please check logs.
                    es-ES: Copia fallida. Revise los registros.
                  target:
                    type: workspaces
                    ids:
                      - 507f1f77bcf86cd799439012
                      - 507f1f77bcf86cd799439013
                  microservice_id: 507f1f77bcf86cd799439014
                  conditions:
                    - condition_type_id: 507f1f77bcf86cd799439015
                      operator: gt
                      compare_to: '80'
                      check_every: 300
      responses:
        '201':
          description: Flux creat correctament. La resposta conté el recurs creat.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/FlowV1'
              example:
                id: 507f1f77bcf86cd799439011
        '400':
          $ref: '#/components/responses/BadRequest'
          description: >-
            Sol·licitud incorrecta. Causes comunes: - Falten camps obligatoris -
            Valors de camp invàlids - Configuració de condició invàlida -
            Identificador de microservei invàlid
        '401':
          $ref: '#/components/responses/Unauthorized'
          description: No autoritzat - es requereix autenticació
        '404':
          $ref: '#/components/responses/NotFound'
          description: Organització no trobada
        '422':
          $ref: '#/components/responses/UnprocessableEntity'
          description: >-
            Entitat no processable. Causes comunes: - Microservei referenciat no
            trobat - Entitats objectiu referenciades (espais de treball, grups
            d'espais de treball, grups de report) no trobades o no pertanyents -
            Tipus de condició invàlid - El flux no pot habilitar-se
        '429':
          $ref: '#/components/responses/TooManyRequests'
        '500':
          $ref: '#/components/responses/InternalServerError'
components:
  schemas:
    CreateFlowV1Request:
      type: object
      properties:
        name:
          $ref: '#/components/schemas/MultilangField'
          description: >-
            Nom del flux. Es requereix com a mínim una clau de idioma; cada
            valor ha de tenir entre 1 i 512 caràcters.
        description:
          $ref: '#/components/schemas/MultilangField'
          description: >-
            Descripció del flux. Es requereix com a mínim una clau de idioma;
            cada valor ha de tenir entre 1 i 512 caràcters.
        type:
          type: string
          enum:
            - session
            - workspace
        detection_only:
          type: boolean
        cooldown_minutes:
          type: number
          minimum: 10
          maximum: 1440
          description: Temps d'espera en minuts. Ha d'estar entre 10 i 1440.
        enabled:
          type: boolean
          default: false
          description: >-
            Si és cert, el flux queda habilitat després de la seva creació
            (requereix condicions, microservei i objectiu vàlids). Si se s'omete
            o és fals, es crea un flux deshabilitat.
        init_text:
          $ref: '#/components/schemas/MultilangField'
          description: >-
            Missatge de text inicial. Se s'omete si no és necessari. Quan es
            proporciona, es requereix com a mínim una clau de idioma; cada valor
            ha de tenir entre 1 i 512 caràcters.
        ok_text:
          $ref: '#/components/schemas/MultilangField'
          description: >-
            Missatge de text d'èxit. Se s'omete si no és necessari. Quan es
            proporciona, es requereix com a mínim una clau de idioma; cada valor
            ha de tenir entre 1 i 512 caràcters.
        ko_text:
          $ref: '#/components/schemas/MultilangField'
          description: >-
            Missatge de text d'error. Se s'omete si no és necessari. Quan es
            proporciona, es requereix com a mínim una clau de idioma; cada valor
            ha de tenir entre 1 i 512 caràcters.
        target:
          type: object
          properties:
            type:
              type: string
              enum:
                - all_workspaces
                - workspaces
                - workspace_groups
                - reporting_groups
            ids:
              type: array
              items:
                type: string
                maxLength: 512
          required:
            - type
        microservice_id:
          type: string
          maxLength: 24
          pattern: ^[0-9a-f]{24}$
        conditions:
          type: array
          items:
            $ref: '#/components/schemas/FlowConditionInputV1'
      required:
        - name
        - description
        - type
        - detection_only
        - cooldown_minutes
        - target
        - microservice_id
        - conditions
    FlowV1:
      type: object
      description: >-
        Detall del flux tal com el retorna GET flow by id. L'organització està
        implícita per la ruta
        `/v1/organizations/{organization_id}/flows/{flow_id}`. Els
        workspaces/grups de destinació es normalitzen en target.ids (cadenes
        hexadecimals de ObjectId de MongoDB).
      properties:
        id:
          type: string
          maxLength: 24
          pattern: ^[0-9a-f]{24}$
        created_at:
          type: string
          format: date-time
        name:
          type: string
          description: Resol per Accept-Language quan és multilingüe
        description:
          type: string
          description: Resol per Accept-Language quan és multilingüe
        type:
          type: string
          enum:
            - session
            - workspace
        version:
          type: number
        detection_only:
          type: boolean
        cooldown_minutes:
          type: number
          description: Temps d'espera en minuts
        enabled:
          type: boolean
        conditions:
          type: array
          items:
            $ref: '#/components/schemas/FlowConditionV1'
          description: Omitit o buit quan el flux no té condicions
        trigger:
          type: string
          nullable: true
        target:
          $ref: '#/components/schemas/FlowTargetSelectorV1'
          description: >-
            Destí d'execució: el tipus selecciona l'abast; ids enumera valors de
            _id de Workspace, _id de grup de Workspace o _id de Grup de reporte
            (buit quan el tipus és ALL_WORKSPACES)
        microservice_id:
          type: string
          nullable: true
          description: ID del microservei vinculat quan està present
        init_text:
          type: string
          nullable: true
          description: Resol per Accept-Language quan és multilingüe
        ok_text:
          type: string
          nullable: true
          description: Resol per Accept-Language quan és multilingüe
        ko_text:
          type: string
          nullable: true
          description: Resol per Accept-Language quan és multilingüe
        execution_metrics:
          $ref: '#/components/schemas/FlowExecutionMetricsV1'
          nullable: true
          description: Present quan es van calcular mètriques per a aquest flux
      required:
        - id
        - created_at
        - name
        - description
        - type
        - version
        - detection_only
        - cooldown_minutes
        - enabled
        - target
    MultilangField:
      type: object
      description: >-
        Camp multilingüe. Les claus són codis de idioma (en-EN, es-ES, pt-BR,
        eu-ES, ca-ES). Hi ha d'haver com a mínim una clau. Cada valor ha de
        tenir entre 1 i 512 caràcters.
      properties:
        en-EN:
          type: string
          minLength: 1
          maxLength: 512
        es-ES:
          type: string
          minLength: 1
          maxLength: 512
        pt-BR:
          type: string
          minLength: 1
          maxLength: 512
        eu-ES:
          type: string
          minLength: 1
          maxLength: 512
        ca-ES:
          type: string
          minLength: 1
          maxLength: 512
      additionalProperties: false
    FlowConditionInputV1:
      type: object
      properties:
        condition_type_id:
          type: string
          maxLength: 24
          pattern: ^[0-9a-f]{24}$
        operator:
          type: string
          enum:
            - eq
            - gt
            - lt
            - gte
            - lte
            - startsWith
            - endsWith
            - contains
            - at
        compare_to:
          type: string
          maxLength: 512
        period:
          type: number
          nullable: true
        check_every:
          type: number
      required:
        - condition_type_id
        - operator
        - compare_to
        - check_every
    FlowConditionV1:
      type: object
      properties:
        condition_type_id:
          type: string
        metric:
          type: string
        operator:
          type: string
        compare_to:
          type: string
        period:
          type: number
          nullable: true
        check_every:
          type: number
      required:
        - condition_type_id
        - metric
        - operator
        - compare_to
        - check_every
    FlowTargetSelectorV1:
      type: object
      properties:
        type:
          type: string
          enum:
            - all_workspaces
            - workspaces
            - workspace_groups
            - reporting_groups
          description: >-
            ALL_WORKSPACES: ids sempre és []. WORKSPACES: ids són _id de
            documents de Workspace (24 hex). WORKSPACE_GROUPS /
            REPORTING_GROUPS: ids són valors de _id de grup.
        ids:
          type: array
          items:
            type: string
            maxLength: 24
            pattern: ^[0-9a-f]{24}$
      required:
        - type
        - ids
    FlowExecutionMetricsV1:
      type: object
      properties:
        targeted_workspaces:
          type: number
        evaluations_per_day:
          type: number
        possible_executions_per_day:
          type: number
        total_possible_executions_per_day:
          type: number
      required:
        - targeted_workspaces
        - evaluations_per_day
        - possible_executions_per_day
        - total_possible_executions_per_day
    ErrorResponse:
      type: object
      properties:
        error:
          type: object
          properties:
            message:
              type: string
            code:
              type: string
            details:
              type: string
          required:
            - message
            - code
      required:
        - error
  responses:
    BadRequest:
      description: Sol·licitud incorrecta
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    Unauthorized:
      description: No autoritzat
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    NotFound:
      description: No trobat
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    UnprocessableEntity:
      description: Entitat no processable
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    TooManyRequests:
      description: Masses sol·licituds
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    InternalServerError:
      description: Error intern del servidor
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT

````