> ## 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.

# Crear operacions

> Crea una o diverses operacions basades en l'abast i objectius enviats. Tipus d'operació disponibles actualment: execute_microservice, delete_workspaces, shutdown_workspaces, restart_workspaces i suspend_workspaces.



## OpenAPI

````yaml /ca/api-reference/openapi.ca-v1.json post /v1/organizations/{organization_id}/operations
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}/operations:
    post:
      tags:
        - Operacions
      summary: Crear operacions
      description: >-
        Crea una o diverses operacions basades en l'abast i objectius enviats.
        Tipus d'operació disponibles actualment: execute_microservice,
        delete_workspaces, shutdown_workspaces, restart_workspaces i
        suspend_workspaces.
      operationId: createOperations
      parameters:
        - name: organization_id
          in: path
          required: true
          schema:
            type: string
            maxLength: 24
            pattern: ^[0-9a-f]{24}$
          description: Identificador únic de l'organització.
          example: 507f1f77bcf86cd799439011
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateOperationV1Request'
            examples:
              workspace_scope:
                summary: Crear operació sobre workspaces
                value:
                  type: execute_microservice
                  target:
                    type: workspaces
                    ids:
                      - 507f1f77bcf86cd799439011
                      - 507f1f77bcf86cd799439012
                  expiration_in_seconds: 600
                  payload:
                    microservice_id: 507f1f77bcf86cd799439015
                    parameters:
                      mode: safe
              session_scope:
                summary: Crear operació sobre sessions
                value:
                  type: execute_microservice
                  target:
                    type: sessions
                    ids:
                      - 550E8400-E29B-41D4-A716-446655440000
                      - 7F5C3F8D-8A9B-4C8D-B8D1-123456789ABC
                  payload:
                    microservice_id: 507f1f77bcf86cd799439015
                    parameters:
                      mode: safe
              delete_workspaces_workspace_scope:
                summary: Crear operació delete_workspaces sobre workspaces
                value:
                  type: delete_workspaces
                  target:
                    type: workspaces
                    ids:
                      - 507f1f77bcf86cd799439011
                      - 507f1f77bcf86cd799439012
              shutdown_workspaces_workspace_scope:
                summary: Crear operació shutdown_workspaces sobre workspaces
                value:
                  type: shutdown_workspaces
                  target:
                    type: workspaces
                    ids:
                      - 507f1f77bcf86cd799439011
              restart_workspaces_workspace_scope_with_expiration:
                summary: >-
                  Crear operació restart_workspaces sobre workspaces amb
                  expiració personalitzada
                value:
                  type: restart_workspaces
                  target:
                    type: workspaces
                    ids:
                      - 507f1f77bcf86cd799439011
                  expiration_in_seconds: 1200
              suspend_workspaces_workspace_scope:
                summary: Crear operació suspend_workspaces sobre workspaces
                value:
                  type: suspend_workspaces
                  target:
                    type: workspaces
                    ids:
                      - 507f1f77bcf86cd799439011
      responses:
        '201':
          description: Operacions creades correctament.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CreateOperationV1Response'
              example:
                ids:
                  - organization_id: 507f1f77bcf86cd799439011
                    operation_id: 507f1f77bcf86cd799439031
        '400':
          $ref: '#/components/responses/BadRequest'
          description: >-
            Sol·licitud incorrecta. Causes comunes: tipus no suportat,
            target.type invàlid, target.ids buit, expiration_in_seconds fora de
            rang, o càrrega útil no permesa per a
            delete_workspaces/shutdown_workspaces/restart_workspaces/suspend_workspaces.
        '401':
          $ref: '#/components/responses/Unauthorized'
          description: No autoritzat.
        '404':
          $ref: '#/components/responses/NotFound'
          description: Organització no trobada.
        '422':
          $ref: '#/components/responses/UnprocessableEntity'
          description: >-
            Entitat no processable. Causes comunes: objectius no resolubles en
            l'organització, o permisos insuficients sobre grups de report.
        '429':
          $ref: '#/components/responses/TooManyRequests'
        '500':
          $ref: '#/components/responses/InternalServerError'
components:
  schemas:
    CreateOperationV1Request:
      type: object
      required:
        - type
        - target
      properties:
        type:
          type: string
          description: Tipus de comandament d'operació.
          enum:
            - execute_microservice
            - delete_workspaces
            - shutdown_workspaces
            - restart_workspaces
            - suspend_workspaces
        target:
          type: object
          description: Objecte d'abast i objectius.
          required:
            - type
            - ids
          properties:
            type:
              type: string
              description: >-
                Abast d'objectius. Per a
                delete_workspaces/shutdown_workspaces/restart_workspaces/suspend_workspaces
                només es permetre workspaces.
              enum:
                - workspaces
                - sessions
            ids:
              type: array
              description: >-
                Llista d'identificadors objectiu. Per a workspaces s'esperen
                ids; per a sessions s'esperen UUID en majúscula.
              minItems: 1
              maxItems: 20000
              items:
                type: string
                minLength: 1
                maxLength: 64
          additionalProperties: false
        expiration_in_seconds:
          type: integer
          maximum: 84600
          minimum: 600
          description: >-
            Expiració personalitzada en segons. Si s'ometeix s'utilitza el valor
            per defecte del comandament.
        payload:
          type: object
          description: >-
            Càrrega específica del tipus d'operació. Per a
            delete_workspaces/shutdown_workspaces/restart_workspaces/suspend_workspaces
            no es permet càrrega útil.
          additionalProperties: true
      additionalProperties: false
    CreateOperationV1Response:
      type: object
      required:
        - ids
      properties:
        ids:
          type: array
          description: Identificadors d'operacions creades en el mateix ordre de creació.
          minItems: 1
          items:
            type: object
            required:
              - organization_id
              - operation_id
            properties:
              organization_id:
                type: string
                pattern: ^[0-9a-f]{24}$
                minLength: 24
                maxLength: 24
                description: Identificador de l'organització propietària de l'operació.
              operation_id:
                type: string
                pattern: ^[0-9a-f]{24}$
                minLength: 24
                maxLength: 24
                description: Identificador de l'operació creada.
    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

````