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

# Create or update topic or pathway enrolments

> This endpoint creates or updates topic or pathway enrolments for one user, using enrolment codes. It is the single endpoint for creating and updating all enrolments, including pathway enrolments. Use the `UPDATE` action code to change dates on an existing enrolment. See [How can I enrol people or import enrolments via a spreadsheet (CSV)](https://support.tribalhabits.com/en/articles/5735753-how-can-i-enrol-people-or-import-enrolments-via-a-spreadsheet-csv) for an explanation of enrolment codes.

Up to 5 enrolments can be given, using the `enrolment_code_N` fields where N is from 1..5.

The response lists the user's current enrolment for each code. For pathway codes, each item has the pathway enrolment fields instead. If any code or date is invalid, `400` is returned with a list of errors, for example `{"errors":["'TH-4-999' does not correspond to a known topic or pathway"]}`. If the user cannot be found, `404` is returned with `{"errors":["Cannot find user"]}`.




## OpenAPI

````yaml /openapi.yaml post /topic_assignments
openapi: 3.1.0
info:
  title: Tribal Habits Public API
  version: '1'
  description: >
    The Tribal Habits Public API V1. Use it to manage your Tribal Habits user
    accounts (list, show, create and update) and other entities.


    Replace `myorg` in the server URL with your organisation's subdomain. See
    [Vanity URL](/vanity-url) if you use your own domain.
servers:
  - url: https://myorg.tribalhabits.com/papi
security:
  - ApiKeyHeader: []
tags:
  - name: Users
    description: Users
  - name: Topics
    description: Topics
  - name: Pathways
    description: Pathways
  - name: Enrolments
    description: Topic and Pathway Enrolments
  - name: Certificates
    description: >-
      Certificate generation and retrieval for completed topic and pathway
      enrolments.
  - name: External Knowledge
    description: Knowledge obtained from a source external of Tribal Habits.
  - name: Webhooks
    description: >-
      Webhooks triggered from certain actions in code that will call URLs
      assigned by you.
paths:
  /topic_assignments:
    post:
      tags:
        - Enrolments
      summary: Create or update topic or pathway enrolments
      description: >
        This endpoint creates or updates topic or pathway enrolments for one
        user, using enrolment codes. It is the single endpoint for creating and
        updating all enrolments, including pathway enrolments. Use the `UPDATE`
        action code to change dates on an existing enrolment. See [How can I
        enrol people or import enrolments via a spreadsheet
        (CSV)](https://support.tribalhabits.com/en/articles/5735753-how-can-i-enrol-people-or-import-enrolments-via-a-spreadsheet-csv)
        for an explanation of enrolment codes.


        Up to 5 enrolments can be given, using the `enrolment_code_N` fields
        where N is from 1..5.


        The response lists the user's current enrolment for each code. For
        pathway codes, each item has the pathway enrolment fields instead. If
        any code or date is invalid, `400` is returned with a list of errors,
        for example `{"errors":["'TH-4-999' does not correspond to a known topic
        or pathway"]}`. If the user cannot be found, `404` is returned with
        `{"errors":["Cannot find user"]}`.
      operationId: createOrUpdateEnrolment
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/EnrolmentCreate'
            example:
              user_name: user1@example.com
              enrolment_code_1: TH-4-77-NEW
              enrolment_code_1_due_date: 31/12/2021
      responses:
        '200':
          description: The user's current enrolment for each code
          content:
            application/json:
              schema:
                type: object
                properties:
                  assignments:
                    type: array
                    items:
                      anyOf:
                        - $ref: '#/components/schemas/TopicEnrolment'
                          title: Topic enrolment
                        - $ref: '#/components/schemas/PathwayEnrolment'
                          title: Pathway enrolment
              example:
                assignments:
                  - id: 12345
                    created_at: '2019-04-01T18:03:15.966+11:00'
                    updated_at: '2020-01-22T14:38:39.099+11:00'
                    completed_topic_at: '2019-10-23T15:27:09.829+11:00'
                    status: Conquered
                    due_date: null
                    relationship: reader
                    conquered_minutes: 7
                    conquered_cpd_minutes: 7
                    enrolled_by: Upload people enrolment by API
                    certified_date: null
                    recertification_allowed: true
                    version: null
                    skills_attained:
                      - id: 13
                        name: First Aid
                    categories:
                      - name: Health
                        minutes: 39.5
                        points: 500
                    person:
                      id: 2
                      name: User One
                      user_name: user1@example.com
                      link: /people/users/7
                    topic:
                      id: 3
                      title: Confident and effective business networking
                      link: /knowledge/topics/3/overview
                      knowledge_type: 0
                      show_certificate: true
                      external_id: '123'
        '400':
          description: A code or date is invalid
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorList'
              example:
                errors:
                  - '''TH-4-999'' does not correspond to a known topic or pathway'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '404':
          description: The user cannot be found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorList'
              example:
                errors:
                  - Cannot find user
        '406':
          $ref: '#/components/responses/NotAcceptable'
        '429':
          $ref: '#/components/responses/TooManyRequests'
components:
  schemas:
    EnrolmentCreate:
      type: object
      properties:
        user_name:
          type: string
          description: >-
            User name identifier (case-insensitive). Required, unless `user_id`
            is supplied instead
        user_id:
          type: integer
          description: The internal user ID (`person.id`). Alternative to `user_name`
        enrolment_code_1:
          type: string
          description: >-
            The enrolment code, eg `TH-4-77-NEW`. If no codes are given, an
            empty `assignments` list is returned
        enrolment_code_1_due_date:
          type: string
          description: >-
            When the enrolment is due. Formats: 'yyyy-mm-dd', 'dd/mm/yyyy' or
            'dd/mm/yy'
        enrolment_code_1_conquered_date:
          type: string
          description: >-
            When the enrolment was conquered (completed), used with completion
            codes. Same formats
        enrolment_code_1_certified_date:
          type: string
          description: When the enrolment is certified up to. Same formats
        enrolment_code_1_skill_attained:
          type: string
          description: Skill names attained, separated with a semicolon
        enrolment_code_2:
          type: string
          description: The enrolment code, eg `TH-4-77-NEW`
        enrolment_code_2_due_date:
          type: string
          description: >-
            When the enrolment is due. Formats: 'yyyy-mm-dd', 'dd/mm/yyyy' or
            'dd/mm/yy'
        enrolment_code_2_conquered_date:
          type: string
          description: >-
            When the enrolment was conquered (completed), used with completion
            codes. Same formats
        enrolment_code_2_certified_date:
          type: string
          description: When the enrolment is certified up to. Same formats
        enrolment_code_2_skill_attained:
          type: string
          description: Skill names attained, separated with a semicolon
        enrolment_code_3:
          type: string
          description: The enrolment code, eg `TH-4-77-NEW`
        enrolment_code_3_due_date:
          type: string
          description: >-
            When the enrolment is due. Formats: 'yyyy-mm-dd', 'dd/mm/yyyy' or
            'dd/mm/yy'
        enrolment_code_3_conquered_date:
          type: string
          description: >-
            When the enrolment was conquered (completed), used with completion
            codes. Same formats
        enrolment_code_3_certified_date:
          type: string
          description: When the enrolment is certified up to. Same formats
        enrolment_code_3_skill_attained:
          type: string
          description: Skill names attained, separated with a semicolon
        enrolment_code_4:
          type: string
          description: The enrolment code, eg `TH-4-77-NEW`
        enrolment_code_4_due_date:
          type: string
          description: >-
            When the enrolment is due. Formats: 'yyyy-mm-dd', 'dd/mm/yyyy' or
            'dd/mm/yy'
        enrolment_code_4_conquered_date:
          type: string
          description: >-
            When the enrolment was conquered (completed), used with completion
            codes. Same formats
        enrolment_code_4_certified_date:
          type: string
          description: When the enrolment is certified up to. Same formats
        enrolment_code_4_skill_attained:
          type: string
          description: Skill names attained, separated with a semicolon
        enrolment_code_5:
          type: string
          description: The enrolment code, eg `TH-4-77-NEW`
        enrolment_code_5_due_date:
          type: string
          description: >-
            When the enrolment is due. Formats: 'yyyy-mm-dd', 'dd/mm/yyyy' or
            'dd/mm/yy'
        enrolment_code_5_conquered_date:
          type: string
          description: >-
            When the enrolment was conquered (completed), used with completion
            codes. Same formats
        enrolment_code_5_certified_date:
          type: string
          description: When the enrolment is certified up to. Same formats
        enrolment_code_5_skill_attained:
          type: string
          description: Skill names attained, separated with a semicolon
    TopicEnrolment:
      type: object
      properties:
        id:
          type: integer
        created_at:
          type: string
          format: date-time
        updated_at:
          type: string
          format: date-time
        completed_topic_at:
          type:
            - string
            - 'null'
          format: date-time
          description: When the topic was completed, or `null`
        status:
          type: string
          enum:
            - Pre-enrolled
            - Unexplored
            - Exploring
            - Applying
            - Conquered
          description: >-
            Progress of the enrolment: `Pre-enrolled`, `Unexplored`,
            `Exploring`, `Applying` or `Conquered` (completed)
        due_date:
          type:
            - string
            - 'null'
          format: date-time
        relationship:
          type: string
          enum:
            - reader
            - author
            - assessor
          description: '`reader` (explorer), `author` (creator) or `assessor`'
        conquered_minutes:
          type:
            - number
            - 'null'
          description: Minutes recorded on completion
        conquered_cpd_minutes:
          type:
            - number
            - 'null'
          description: Minutes recorded on completion
        enrolled_by:
          type:
            - string
            - 'null'
        certified_date:
          type:
            - string
            - 'null'
          description: Date the certification is valid until, or `null`
        recertification_allowed:
          type: boolean
        version:
          type:
            - string
            - 'null'
          description: Version of the topic completed, or `null`
        skills_attained:
          type: array
          items:
            $ref: '#/components/schemas/SkillAttained'
        categories:
          type: array
          description: Continuing education categories recorded on completion
          items:
            type: object
            properties:
              name:
                type: string
              minutes:
                type: number
              points:
                type: number
        person:
          $ref: '#/components/schemas/EnrolmentPerson'
        topic:
          type: object
          properties:
            id:
              type: integer
            title:
              type: string
            link:
              type: string
              description: Path of the related page in Tribal Habits
            knowledge_type:
              type: integer
              enum:
                - 0
                - 1
              description: '`0` = standard topic, `1` = short topic'
            show_certificate:
              type: boolean
            external_id:
              type:
                - string
                - 'null'
    PathwayEnrolment:
      type: object
      properties:
        id:
          type: integer
        created_at:
          type: string
          format: date-time
        updated_at:
          type: string
          format: date-time
        conquered_at:
          type:
            - string
            - 'null'
          format: date-time
          description: When the pathway was completed, or `null`
        status:
          type: string
          enum:
            - Pre-enrolled
            - Unexplored
            - Exploring
            - Applying
            - Conquered
            - recertify
          description: >-
            Progress of the enrolment: `Pre-enrolled`, `Unexplored`,
            `Exploring`, `Applying`, `Conquered` (completed) or `recertify`
        due_date:
          type:
            - string
            - 'null'
          format: date-time
        enrolled_by:
          type:
            - string
            - 'null'
        certified_date:
          type:
            - string
            - 'null'
          description: Date the certification is valid until, or `null`
        recertification_allowed:
          type: boolean
        skills_attained:
          type: array
          items:
            $ref: '#/components/schemas/SkillAttained'
        person:
          $ref: '#/components/schemas/EnrolmentPerson'
        pathway:
          type: object
          properties:
            id:
              type: integer
            title:
              type: string
            link:
              type: string
            show_certificate:
              type: boolean
            external_id:
              type:
                - string
                - 'null'
    ErrorList:
      type: object
      properties:
        errors:
          type: array
          items:
            type: string
    SkillAttained:
      type: object
      properties:
        id:
          type: integer
        name:
          type: string
    EnrolmentPerson:
      type: object
      properties:
        id:
          type: integer
          description: Internal user ID. This is not the `user_name`
        name:
          type: string
        user_name:
          type: string
        link:
          type: string
          description: Path of the related page in Tribal Habits
  responses:
    Unauthorized:
      description: >-
        Unauthorized - The request does not include the API key, the API key is
        incorrect, or API access is not enabled on your plan.
    NotAcceptable:
      description: >-
        Not Acceptable - A `POST` or `PUT` request had a `Content-Type` header
        other than `application/json`
    TooManyRequests:
      description: >-
        Too Many Requests - You have exceeded the rate limit. See [Rate
        limits](/rate-limits)
      headers:
        Retry-After:
          description: Number of seconds until the rate limit window resets
          schema:
            type: integer
      content:
        application/json:
          schema:
            type: object
            properties:
              error:
                type: string
              retry_after_seconds:
                type: integer
          example:
            error: Rate limit exceeded. Please slow down.
            retry_after_seconds: 23
  securitySchemes:
    ApiKeyHeader:
      type: apiKey
      in: header
      name: Authorization
      description: >
        Your organisation's API key, sent as `Authorization: my_api_key`. The
        key can also be passed as an `api_key` query parameter. See
        [Authentication](/authentication).

````

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