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

# Crear un arrendatari

> Crea un nou tenant i una organització associada per a l'organització propietària especificada. El cos de sol·licitud utilitza un discriminador `type` amb rutes excloents: `tenant` (END CUSTOMER) i `organization` (PARTNER/WHOLESALER).



## OpenAPI

````yaml /ca/api-reference/openapi.ca-v2.json post /v2/organizations/{organization_id}/tenants
openapi: 3.0.3
info:
  title: API Publica Portal
  version: 2.0.0
  description: API pública REST per al portal
servers:
  - url: https://api.flexxible.net
    description: Portal API (production)
security:
  - bearerAuth: []
tags:
  - name: Activitat digital
    description: Creació de grups de processos core per organització
  - name: Roles
    description: Endpoint de creacion de roles de organizacion
  - name: Usuarios
    description: Endpoint de creacion de usuarios de organizacion
  - name: Grupos de workspaces
    description: Endpoints de gestión de grupos de workspaces
  - name: Workspaces
    description: Endpoint de eliminacion de workspaces de la organizacion
  - name: Aplicaciones instaladas
    description: Endpoint de detalle de aplicación instalada de la organización
  - name: Autenticación
    description: Endpoints de autenticación y contexto de sesión
  - name: Microservicios
    description: Detalle de microservicios por organizacion
  - name: Operaciones
    description: Consulta de detalle de operaciones por organización
  - name: Organización
    description: Operaciones de organización
  - name: Objetivos de política de parches
    description: Endpoints de gestión de objetivos de política de parches
  - name: Configuraciones de producto
    description: Endpoints de gestión de configuraciones de producto
  - name: Grupos de reporte
    description: Operaciones sobre grupos de reporte
  - name: Sesiones
    description: Endpoint de detalle de sesion de la organizacion
  - name: Tenants
    description: Endpoints de gestión de tenants
paths:
  /v2/organizations/{organization_id}/tenants:
    post:
      tags:
        - Llogaters
      summary: Crear un arrendatari
      description: >-
        Crea un nou tenant i una organització associada per a l'organització
        propietària especificada. El cos de sol·licitud utilitza un
        discriminador `type` amb rutes excloents: `tenant` (END CUSTOMER) i
        `organization` (PARTNER/WHOLESALER).
      operationId: createTenant
      parameters:
        - name: organization_id
          in: path
          required: true
          schema:
            type: string
            maxLength: 24
            pattern: ^[0-9a-f]{24}$
          description: >-
            L'identificador únic de l'organització propietària que crearà el
            tenant
          example: 507f1f77bcf86cd799439011
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateTenantRequestV2'
            examples:
              create-tenant-end-customer:
                summary: Crear tenant per organització END CUSTOMER
                value:
                  type: tenant
                  name: Tenant de producción
                  tenant_config:
                    product_config_id: 507f1f77bcf86cd799439030
                    analyzer: existing
                  policy_id: 507f1f77bcf86cd799439050
                  organization_email: tenant@example.com
                  organization_language: en
                  organization_country: US
                  organization_industry: Tecnología
              create-tenant-partner-or-wholesaler:
                summary: Crear tenant per organització PARTNER o WHOLESALER
                value:
                  type: organization
                  name: Tenant empresarial
                  organization_config:
                    product_id: 507f1f77bcf86cd799439030
                    region: west-eu-01_one
                  policy_id: 507f1f77bcf86cd799439050
                  organization_email: enterprise@example.com
                  organization_language: es
                  organization_country: ES
                  organization_industry: Finanzas
      responses:
        '201':
          description: >-
            Tenant i organització associats creats correctament. Torna el recurs
            tenant creat.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TenantByIdV2'
        '400':
          $ref: '#/components/responses/BadRequest'
          description: >-
            Sol·licitud incorrecta. Causes comunes: - Cos de sol·licitud o
            paràmetres de ruta no vàlids - S'han barrejat configuracions
            excloents (`tenant_config` i `organization_config`) - Falta de camps
            obligatoris per al tipus seleccionat - Format d'id no vàlid
        '401':
          $ref: '#/components/responses/Unauthorized'
          description: No autoritzat - es requereix autenticació
        '404':
          $ref: '#/components/responses/NotFound'
          description: No s'ha trobat l'organització propietària
        '422':
          description: >-
            Entitat no processable - Error de validació de lògica de negoci.
            Causes comunes: - Product config no trobat - L'organització no és
            elegible per crear tenants - L'organització no existeix en build -
            L'organització no té productes elegibles - Relació de partner no
            vàlida - L'organització i l'organització pare són clients finals -
            Entitat referenciada no trobada
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '429':
          $ref: '#/components/responses/TooManyRequests'
        '500':
          $ref: '#/components/responses/InternalServerError'
components:
  schemas:
    CreateTenantRequestV2:
      type: object
      additionalProperties: false
      properties:
        type:
          type: string
          enum:
            - tenant
            - organization
          description: >-
            Tipus de creació. `tenant` per END CUSTOMER, `organization` per
            PARTNER/WHOLESALER.
        name:
          type: string
          maxLength: 512
        tenant_config:
          type: object
          additionalProperties: false
          nullable: true
          description: Configuració específica per `type=tenant`.
          properties:
            product_config_id:
              type: string
              maxLength: 24
              pattern: ^[0-9a-f]{24}$
            analyzer:
              type: string
              enum:
                - existing
                - new
          required:
            - product_config_id
            - analyzer
        organization_config:
          type: object
          additionalProperties: false
          nullable: true
          description: Configuració específica per `type=organization`.
          properties:
            product_id:
              type: string
              maxLength: 24
              pattern: ^[0-9a-f]{24}$
            region:
              type: string
              maxLength: 128
          required:
            - product_id
            - region
        policy_id:
          type: string
          maxLength: 24
          pattern: ^[0-9a-f]{24}$
        organization_email:
          type: string
          maxLength: 512
        organization_language:
          type: string
          maxLength: 512
        organization_country:
          type: string
          maxLength: 512
        organization_industry:
          type: string
          maxLength: 512
      required:
        - type
        - name
        - organization_email
        - organization_language
        - organization_country
        - organization_industry
      description: >-
        Cos únic de creació amb camps condicionals per `type`: si `type=tenant`,
        requereix `tenant_config`; si `type=organization`, requereix
        `organization_config`.
    TenantByIdV2:
      type: object
      required:
        - id
        - organization_id
        - created_at
        - name
        - region
      properties:
        id:
          type: string
        organization_id:
          type: string
          description: ID de l'organització del tenant
        created_at:
          type: string
          format: date-time
        name:
          type: string
        region:
          type: string
        product_id:
          type: string
          nullable: true
          description: ID del producte
        policy_id:
          type: string
          nullable: true
          description: ID de la política
    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'
    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

````