> ## 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 un arrendatari

> Crea un nou tenant i una organització associada per a l'organització propietària especificada. El nom del tenant també s'utilitza com a nom de l'organització acabada de crear. Requereix product_config_id. Admet opcionalment l'assignació de política.



## OpenAPI

````yaml /ca/api-reference/openapi.ca-v1.json post /v1/organizations/{organization_id}/tenants
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}/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 nom del tenant també s'utilitza com a nom
        de l'organització acabada de crear. Requereix product_config_id. Admet
        opcionalment l'assignació de política.
      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/CreateTenantRequestV1'
            examples:
              create-tenant-with-all-required-fields:
                summary: Crear un tenant amb la informació mínima requerida
                value:
                  name: Tenant de producción
                  product_config_id: 507f1f77bcf86cd799439030
                  organization_email: tenant@example.com
                  organization_language: en
                  organization_country: US
                  organization_industry: Tecnología
              create-tenant-with-optional-fields:
                summary: Crear un tenant amb política
                value:
                  name: Tenant empresarial
                  product_config_id: 507f1f77bcf86cd799439030
                  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/TenantByIdV1'
        '400':
          $ref: '#/components/responses/BadRequest'
          description: >-
            Sol·licitud incorrecta. Causes comunes: - Cos de la sol·licitud o
            paràmetres de ruta no vàlids - Falten camps obligatoris (nom,
            product_config_id, correu electrònic de l'organització, idioma de
            l'organització, país de l'organització, sector de l'organització) -
            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:
    CreateTenantRequestV1:
      type: object
      properties:
        name:
          type: string
          maxLength: 512
        product_config_id:
          type: string
          maxLength: 24
          pattern: ^[0-9a-f]{24}$
        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:
        - name
        - product_config_id
        - organization_email
        - organization_language
        - organization_country
        - organization_industry
    TenantByIdV1:
      type: object
      properties:
        id:
          type: string
        organization_id:
          type: string
          description: ID de l'organització del tenant
        create_date:
          type: string
          format: date-time
        name:
          type: string
        region:
          type: string
        product_id:
          type: string
          nullable: true
          description: ID del producte (nullable)
        policy_id:
          type: string
          nullable: true
          description: ID de la política (nullable)
      required:
        - id
        - organization_id
        - create_date
        - name
        - region
    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

````