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

# Create a role

> Create a role and its permission entries in a single request.



## OpenAPI

````yaml /en/api-reference/openapi.en-v1.json post /v1/organizations/{organization_id}/roles
openapi: 3.0.3
info:
  title: API Publica Portal
  version: 1.0.0
  description: Public REST API for portal
servers:
  - url: https://api.flexxible.net/
    description: Portal API
security:
  - bearerAuth: []
tags: []
paths:
  /v1/organizations/{organization_id}/roles:
    post:
      tags:
        - Roles
      summary: Create a role
      description: Create a role and its permission entries in a single request.
      operationId: create_role
      parameters:
        - name: organization_id
          in: path
          required: true
          schema:
            type: string
            pattern: ^[0-9a-f]{24}$
            minLength: 24
            maxLength: 24
          description: Organization identifier.
          example: 507f1f77bcf86cd799439011
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateRoleRequestV1'
            examples:
              organization_scoped_role:
                summary: Create role with organization scope permission
                value:
                  name: Operador de organizacion
                  permissions:
                    - portal_permission: organization_admin
                      workspaces_permission: admin_read_only
                      analyzer_permission: access
                      target_organization: 507f1f77bcf86cd799439011
                      target_reporting_groups:
                        - 64f0c2a1b2d3e4f5060708c1
                        - 64f0c2a1b2d3e4f5060708c2
              mixed_permissions_role:
                summary: Create role with mixed permission scopes
                value:
                  name: Soporte de nivel 1
                  permissions:
                    - portal_permission: l1_support_team
                      workspaces_permission: l1_support_team
                      analyzer_permission: no_access
                      target_organization: all
                      target_reporting_groups: all
                    - portal_permission: l1_support_team_read_only
                      workspaces_permission: l1_support_team_read_only
                      analyzer_permission: access
                      target_organization: 507f1f77bcf86cd799439011
                      target_reporting_groups:
                        - 64f0c2a1b2d3e4f5060708d1
      responses:
        '201':
          description: User role created successfully.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/RoleV1'
              examples:
                created:
                  summary: Role created
                  value:
                    id: 64f0c2a1b2d3e4f5060708aa
                    name: Operador de organizacion
                    organization_id: 507f1f77bcf86cd799439011
                    created_at: '2026-03-12T10:30:00Z'
                    created_by: 64f0c2a1b2d3e4f5060708bb
                    permissions:
                      - portal_permission: organization_admin
                        workspaces_permission: admin_read_only
                        analyzer_permission: access
                        target_organization: 507f1f77bcf86cd799439011
                        target_reporting_groups:
                          - 64f0c2a1b2d3e4f5060708c1
                          - 64f0c2a1b2d3e4f5060708c2
        '400':
          description: Invalid request payload.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                invalid_permission_payload:
                  summary: Invalid permission payload
                  value:
                    error:
                      message: Cuerpo de solicitud no valido
                      code: bad_request
                      details: >-
                        permissions[0].target_organization debe ser `all` o una
                        cadena hexadecimal en minusculas de 24 caracteres
        '401':
          description: Not authorized or organization not accessible.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                organization_not_authorized:
                  summary: Organization access failure
                  value:
                    error:
                      message: No autorizado
                      code: unauthorized
        '404':
          description: Referenced resource not found within authorized organization scope.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                reporting_group_not_found:
                  summary: Referenced Reporting Group not found
                  value:
                    error:
                      message: Grupo de reporte no encontrado
                      code: not_found
        '409':
          description: The request conflicts with an existing resource.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                role_name_already_exists:
                  summary: Role name already exists
                  value:
                    error:
                      message: El nombre del rol ya existe
                      code: conflict
                      details: name ya esta en uso dentro de esta organizacion
        '422':
          description: >-
            The request cannot be completed due to organization entity limit
            restrictions.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                organization_entity_limit_exceeded:
                  summary: Role limit exceeded
                  value:
                    error:
                      message: Entity ownership limit exceeded.
                      code: unprocessable_entity
        '500':
          description: Internal server error.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                unexpected_error:
                  summary: Unhandled failure
                  value:
                    error:
                      message: Error interno del servidor
                      code: internal_error
components:
  schemas:
    CreateRoleRequestV1:
      type: object
      properties:
        name:
          type: string
          minLength: 1
          maxLength: 120
          description: User role name.
        permissions:
          type: array
          minItems: 1
          description: Permission entries assigned to the role.
          items:
            $ref: '#/components/schemas/CreateRolePermissionRequestItemV1'
      required:
        - name
        - permissions
    RoleV1:
      type: object
      properties:
        id:
          type: string
          pattern: ^[0-9a-f]{24}$
          minLength: 24
          maxLength: 24
          description: Role identifier.
        name:
          type: string
          description: Role name.
        organization_id:
          type: string
          pattern: ^[0-9a-f]{24}$
          minLength: 24
          maxLength: 24
          description: Organization identifier associated with this role.
        created_at:
          type: string
          format: date-time
          description: Role creation timestamp in ISO 8601 format.
        created_by:
          type: string
          nullable: true
          pattern: ^[0-9a-f]{24}$
          minLength: 24
          maxLength: 24
          description: Identifier of the user who created the role.
        permissions:
          type: array
          nullable: true
          description: Permission entries configured for this role.
          items:
            $ref: '#/components/schemas/GetRolePermissionItemV1'
      required:
        - id
        - name
        - organization_id
        - created_at
        - created_by
    ErrorResponse:
      type: object
      properties:
        error:
          type: object
          properties:
            message:
              type: string
            code:
              type: string
            details:
              type: string
          required:
            - message
            - code
      required:
        - error
    CreateRolePermissionRequestItemV1:
      type: object
      properties:
        portal_permission:
          type: string
          enum:
            - admin
            - organization_admin
            - organization_admin_read_only
            - user
            - platform
            - l1_support_team
            - l1_support_team_read_only
            - l2_support_team
            - l2_support_team_read_only
            - l3_engineering_team
            - l3_engineering_team_read_only
            - billing
          description: Portal permission level.
        workspaces_permission:
          type: string
          enum:
            - no_access
            - l1_support_team_read_only
            - l1_support_team
            - l2_support_team_read_only
            - l2_support_team
            - l3_engineering_team_read_only
            - l3_engineering_team
            - admin_read_only
            - admin
          description: Workspace permission level.
        analyzer_permission:
          type: string
          enum:
            - no_access
            - access
            - admin
          description: Analyzer permission level.
        target_organization:
          oneOf:
            - type: string
              enum:
                - all
            - type: string
              pattern: ^[0-9a-f]{24}$
              minLength: 24
              maxLength: 24
          description: >-
            Organization scope of permission: `all` for all organizations or a
            specific `organization_id`.
        target_reporting_groups:
          oneOf:
            - type: string
              enum:
                - all
            - type: array
              minItems: 1
              items:
                type: string
                pattern: ^[0-9a-f]{24}$
                minLength: 24
                maxLength: 24
          description: >-
            Reporting groups scope of permission: `all` for all groups or list
            of specific `reporting_group_id`.
      required:
        - portal_permission
        - workspaces_permission
        - analyzer_permission
        - target_organization
        - target_reporting_groups
    GetRolePermissionItemV1:
      type: object
      properties:
        portal_permission:
          type: string
          nullable: true
          enum:
            - admin
            - organization_admin
            - organization_admin_read_only
            - user
            - platform
            - l1_support_team
            - l1_support_team_read_only
            - l2_support_team
            - l2_support_team_read_only
            - l3_engineering_team
            - l3_engineering_team_read_only
            - billing
          description: Portal permission level.
        workspaces_permission:
          type: string
          nullable: true
          enum:
            - no_access
            - l1_support_team_read_only
            - l1_support_team
            - l2_support_team_read_only
            - l2_support_team
            - l3_engineering_team_read_only
            - l3_engineering_team
            - admin_read_only
            - admin
          description: Workspace permission level.
        analyzer_permission:
          type: string
          nullable: true
          enum:
            - no_access
            - access
            - admin
          description: Analyzer permission level.
        target_organization:
          oneOf:
            - type: string
              enum:
                - all
            - type: string
              pattern: ^[0-9a-f]{24}$
              minLength: 24
              maxLength: 24
          description: >-
            Organization scope of permission: `all` for all organizations or a
            specific `organization_id`.
        target_reporting_groups:
          oneOf:
            - type: string
              enum:
                - all
            - type: array
              minItems: 1
              items:
                type: string
                pattern: ^[0-9a-f]{24}$
                minLength: 24
                maxLength: 24
          description: >-
            Reporting groups scope of permission: `all` for all groups or list
            of specific `reporting_group_id`.
      required:
        - target_organization
        - target_reporting_groups
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT

````