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

# Create a new user and add them to the company.

> This endpoint creates a new user given a name and an email and links them to the company.
Linking to existing users is currently not possible (maybe in the future).

Note: The email address for the user being added must not already exist within the system.

# Access Control Rules

- Company manager of the company.
- Admins can list all companies. Requires `manage_companies` permissions.



## OpenAPI

````yaml POST /api/v0/companies/{company_id}/users
openapi: 3.1.0
info:
  title: Cantina Client API
  description: >-
    Endpoints available to client organizations. For an overview and
    authentication, see
    https://docs.cantina.xyz/for-organizations/getting-started/api-access.
  license:
    name: Cantina
    identifier: Cantina
  version: 0.1.0
servers: []
security: []
paths:
  /api/v0/companies/{company_id}/users:
    post:
      tags:
        - companies
      summary: Create a new user and add them to the company.
      description: >-
        This endpoint creates a new user given a name and an email and links
        them to the company.

        Linking to existing users is currently not possible (maybe in the
        future).


        Note: The email address for the user being added must not already exist
        within the system.


        # Access Control Rules


        - Company manager of the company.

        - Admins can list all companies. Requires `manage_companies`
        permissions.
      operationId: add_company_user
      parameters:
        - name: company_id
          in: path
          required: true
          schema:
            type: string
            format: uuid
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/NewCompanyUser'
        required: true
      responses:
        '201':
          description: User successfully added to company
          headers:
            Location:
              schema:
                type: string
              description: The location where the user can be found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CreatedResource'
        '400':
          description: Bad request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CantinaError'
        '401':
          description: Access not authorised
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CantinaError'
        '403':
          description: Access forbidden
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CantinaError'
        '404':
          description: Not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CantinaError'
        '500':
          description: Error adding user to company
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CantinaError'
components:
  schemas:
    NewCompanyUser:
      type: object
      required:
        - name
        - username
        - email
        - role
      properties:
        name:
          type: string
        username:
          type: string
        email:
          type: string
        role:
          $ref: '#/components/schemas/CompanyRole'
        initialRepositories:
          type:
            - array
            - 'null'
          items:
            type: string
            format: uuid
          description: >-
            List of repositories the user will auto-join upon joining the
            company.

            If None auto-join all the current and future repositories.
    CreatedResource:
      type: object
      required:
        - id
      properties:
        id:
          type: string
          format: uuid
    CantinaError:
      type: object
      description: Error returned by the Cantina API.
      required:
        - type
        - msg
      properties:
        type:
          $ref: '#/components/schemas/ErrorType'
        msg:
          type: string
          description: Error message for the user.
    CompanyRole:
      type: string
      enum:
        - manager
        - member
        - unverified_member
    ErrorType:
      type: string
      description: Type of error.
      enum:
        - email_not_verified
        - auth_invalid
        - auth_expired
        - auth_token_missing
        - auth_id_missing
        - invalid_password
        - disabled_user
        - tc_not_accepted
        - evicted
        - unauthorized
        - bad_request
        - not_found
        - forbidden
        - gone
        - payload_too_large
        - service_unavailable
        - internal_error

````