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

# Create or get a user

> Get-or-create by email for the API key's company. Returns `201` when the user is
created and `200` when an account for that email already exists in this company;
the body is the same in both cases. On creation (unless `silent_creation`) a
membership is created and, if `send_welcome_message` is true, a WhatsApp welcome
message is sent. Calendar days and extra fields are applied on every call.




## OpenAPI

````yaml /openapi.yaml post /clients/users/
openapi: 3.1.0
info:
  title: hackU Client API
  version: 1.2.0
  description: >
    Public API for hackU corporate clients. It lets a company manage its
    learners

    (create, update, deactivate), enroll them in courses (routes) and pensums,

    read their progress, and send WhatsApp / email communications.


    **Authentication.** Every request must send the header

    `Authorization: Api-Key <token>`. The key identifies the company; there is
    no

    company parameter in the URL except where noted.


    **Pagination.** List endpoints that are paginated use limit/offset

    (`limit` default 50, maximum 500) and return `{count, next, previous,
    results}`.


    **Errors.** A missing, invalid, revoked or expired key returns `403` with

    `{"detail": "..."}`. Validation errors return `400` with

    `{"<field>": ["<message>", ...]}` (or `non_field_errors`). Some messages are

    returned in Spanish.


    **Identifiers.** `user_id` in every path is the hackU user id, returned as

    `user_pk` by `POST /clients/users/` and as `id` by `GET /clients/users/`.
servers:
  - url: https://app.reinvented.education/api
    description: Production
  - url: https://qa-admin.hacku.co/api
    description: Test
security:
  - ApiKeyAuth: []
tags:
  - name: Users
    description: Create, read, update and deactivate the company's learners.
  - name: Enrollment
    description: Assign courses (routes), modules and pensums.
  - name: Progress
    description: >-
      Read learners' progress in courses, modules, pensums, evaluations, surveys
      and certificates.
  - name: Catalog
    description: The company's courses (routes) and their modules.
  - name: Extra fields
    description: Company-defined custom user fields.
  - name: Communications
    description: Send WhatsApp or email messages using approved templates.
paths:
  /clients/users/:
    post:
      tags:
        - Users
      summary: Create or get a user
      description: >
        Get-or-create by email for the API key's company. Returns `201` when the
        user is

        created and `200` when an account for that email already exists in this
        company;

        the body is the same in both cases. On creation (unless
        `silent_creation`) a

        membership is created and, if `send_welcome_message` is true, a WhatsApp
        welcome

        message is sent. Calendar days and extra fields are applied on every
        call.
      operationId: createUser
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateUserRequest'
      responses:
        '200':
          description: A user with this email already existed for the company.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/UserPk'
        '201':
          description: User created.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/UserPk'
        '400':
          $ref: '#/components/responses/ValidationError'
        '403':
          $ref: '#/components/responses/Forbidden'
components:
  schemas:
    CreateUserRequest:
      type: object
      required:
        - email
        - first_name
        - last_name
        - friendly_name
        - phone_number
        - country
        - hour
        - selected_days
      properties:
        email:
          type: string
          format: email
          description: Identity key; repeating it returns the existing user.
        first_name:
          type: string
          maxLength: 100
        last_name:
          type: string
          maxLength: 100
        friendly_name:
          type: string
          maxLength: 100
          description: Name used in messages.
        phone_number:
          type: string
          pattern: \+?1?\d{9,15}$
          description: >-
            International format. Must be unique within the company for new
            users.
        country:
          type: string
          maxLength: 100
          description: Country slug, e.g. `colombia`, `mexico`.
        document_type:
          oneOf:
            - $ref: '#/components/schemas/DocumentType'
            - type: string
              const: ''
            - type: 'null'
        document_number:
          type:
            - string
            - 'null'
          maxLength: 100
        hour:
          type: string
          pattern: ^\d{2}:\d{2}$
          description: Daily delivery time, HH:MM.
        origin:
          type:
            - string
            - 'null'
          maxLength: 100
          description: Accepted but not stored.
        selected_days:
          type: array
          minItems: 1
          description: >-
            Delivery days. Spanish (lunes, martes, miercoles, jueves, viernes,
            sabado, domingo) or English (monday..sunday) names.
          items:
            type: string
            enum:
              - lunes
              - martes
              - miercoles
              - jueves
              - viernes
              - sabado
              - domingo
              - monday
              - tuesday
              - wednesday
              - thursday
              - friday
              - saturday
              - sunday
        extra_fields:
          type: array
          items:
            $ref: '#/components/schemas/ExtraFieldInput'
        silent_creation:
          type: boolean
          default: false
          description: Do not create a membership (and send no welcome).
        send_welcome_message:
          type: boolean
          default: false
          description: Send the WhatsApp welcome message when the user is created.
        offline_mode:
          type: boolean
          default: false
      example:
        email: ana.perez@example.com
        first_name: Ana
        last_name: Pérez
        friendly_name: Ana
        phone_number: '+573001112233'
        country: colombia
        document_type: CEDULA
        document_number: '1000000001'
        hour: '08:30'
        selected_days:
          - lunes
          - miercoles
          - viernes
        extra_fields:
          - name: area
            value: ventas
        send_welcome_message: true
    UserPk:
      type: object
      required:
        - user_pk
      properties:
        user_pk:
          type: integer
          description: hackU user id.
      example:
        user_pk: 48213
    DocumentType:
      type: string
      enum:
        - CEDULA
        - INE
        - TI
        - DNI
        - CEDULA_EX
        - PASS
        - PERMISO
        - SALVOC
        - EXPEDIENTE
        - CPF
        - RUT
      description: >-
        CEDULA: national id; INE; TI: identity card (minors); DNI; CEDULA_EX:
        foreigner id; PASS: passport; PERMISO: special permit; SALVOC:
        safe-conduct; EXPEDIENTE; CPF; RUT.
    ExtraFieldInput:
      type: object
      required:
        - name
        - value
      properties:
        name:
          type: string
          maxLength: 100
          description: The extra field's `name` (it must already exist for the company).
        value:
          type: string
          maxLength: 100
          description: >-
            For SELECT fields, the choice's `name` (slug). Numeric fields
            require digits.
    ValidationErrors:
      type: object
      description: >-
        Field name (or `non_field_errors`) mapped to a list of messages. Nested
        serializers return nested objects.
      additionalProperties: true
      example:
        email:
          - Enter a valid email address.
        selected_days:
          - Day funday is not valid.
    Error:
      type: object
      required:
        - detail
      properties:
        detail:
          type: string
  responses:
    ValidationError:
      description: Invalid input.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ValidationErrors'
    Forbidden:
      description: Missing, invalid, revoked or expired API key.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            detail: Authentication credentials were not provided.
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: Authorization
      description: >-
        Company API key. The header value must be `Api-Key <token>`, e.g.
        `Authorization: Api-Key AbCd1234.xxxxxxxx`.

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.