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

# Create CourseLesson

> Create a new CourseLesson record.

A **CourseLesson** is an individual learning unit within a Course. Lessons are the building blocks that customers complete to work through a course's content. Each lesson belongs to a `Course` and optionally to a `CourseSection` that groups related lessons together.

Lessons have two key behavioural settings:

**`UnlockType`** — controls when a lesson becomes available to enrolled members:

| Value      | Meaning                                                        |
| ---------- | -------------------------------------------------------------- |
| Immediate  | Available as soon as the member enrols                         |
| Sequential | Unlocked only after the previous lesson is completed           |
| Timed      | Unlocked after a number of days specified by `UnlockAfterDays` |

**`CompletionType`** — defines what action marks the lesson as done:

| Value   | Meaning                                                                    |
| ------- | -------------------------------------------------------------------------- |
| None    | No completion tracking                                                     |
| Visited | Marked complete when the member opens the lesson                           |
| Button  | Member must click a completion button                                      |
| Video   | Member must finish watching the embedded video (must be hosted on YouTube) |

## Authentication

<Note>
  This endpoint requires OAuth2 authentication. Include a valid bearer token in the `Authorization` header.
  The authenticated user must be a full unrestricted administrator or have the **`CourseLesson-Create`** role.
</Note>

## Enums

<Accordion title="eLessonUnlockType — UnlockType values">
  | Value | Name       |
  | ----- | ---------- |
  | 1     | Immediate  |
  | 2     | Sequential |
  | 3     | Timed      |
</Accordion>

<Accordion title="eLessonCompletionType — CompletionType values">
  | Value | Name    |
  | ----- | ------- |
  | 1     | None    |
  | 2     | Visited |
  | 3     | Button  |
  | 4     | Video   |
</Accordion>

## Request Body

### Required Fields

<ParamField body="CourseId" type="integer" required>
  ID of the course this lesson belongs to.
</ParamField>

<ParamField body="Title" type="string" required>
  Lesson title displayed to members.
</ParamField>

<ParamField body="DisplayOrder" type="integer" required>
  Position of the lesson within its section (or the course if unsectioned); lower numbers appear first.
</ParamField>

<ParamField body="UnlockType" type="integer" required>
  When the lesson becomes available: Immediate (1), after the previous lesson is done — Sequential (2), or after a set number of days — Timed (3).
</ParamField>

<ParamField body="UnlockAfterDays" type="integer" required>
  Number of days after enrolment before the lesson unlocks; only used when UnlockType is Timed (3).
</ParamField>

<ParamField body="CompletionType" type="integer" required>
  How completion is tracked: None (1), Visited (2), completion Button (3), or Video watched (4). Video completion requires the lesson to embed a YouTube-hosted video..
</ParamField>

### Optional Fields

<ParamField body="SectionId" type="integer">
  ID of the course section this lesson belongs to (optional; lessons without a section appear ungrouped).
</ParamField>

<ParamField body="InstructorId" type="integer">
  ID of the coworker attributed as instructor for this lesson (optional; overrides the course-level host for this lesson).
</ParamField>

<ParamField body="SummaryText" type="string">
  Short summary shown in the lesson listing.
</ParamField>

<ParamField body="LessonContents" type="string">
  Full HTML or rich-text body of the lesson displayed to members when they open it.
</ParamField>

<ParamField body="Active" type="boolean">
  Whether the lesson is active and visible to enrolled members.
</ParamField>

<ParamField body="NewImageUrl" type="string">
  URL of a new thumbnail image to upload (JPG/JPEG, PNG, or GIF, max 10 MB).
</ParamField>

<ParamField body="ClearImageFile" type="boolean">
  Set to true to remove the existing thumbnail image.
</ParamField>

## Code Examples

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST \
    "https://spaces.nexudus.com/api/content/courselessons" \
    -H "Authorization: Bearer YOUR_TOKEN" \
    -H "Content-Type: application/json" \
    -d '{
      "CourseId": 0,
      "Title": "",
      "DisplayOrder": 0,
      "UnlockType": 0,
      "UnlockAfterDays": 0,
      "CompletionType": 0
  }'
  ```

  ```javascript JavaScript theme={null}
  const response = await fetch(
    'https://spaces.nexudus.com/api/content/courselessons',
    {
      method: 'POST',
      headers: {
        'Authorization': 'Bearer YOUR_TOKEN',
        'Content-Type': 'application/json'
      },
      body: JSON.stringify({
        CourseId: 0,
        Title: '',
        DisplayOrder: 0,
        UnlockType: 0,
        UnlockAfterDays: 0,
        CompletionType: 0
      })
    }
  );

  const data = await response.json();
  ```

  ```python Python theme={null}
  import requests

  response = requests.post(
      'https://spaces.nexudus.com/api/content/courselessons',
      headers={
          'Authorization': 'Bearer YOUR_TOKEN',
          'Content-Type': 'application/json'
      },
      json={
          'CourseId': 0,
          'Title': '',
          'DisplayOrder': 0,
          'UnlockType': 0,
          'UnlockAfterDays': 0,
          'CompletionType': 0
      }
  )

  data = response.json()
  ```
</CodeGroup>

## Response

### 200

<ResponseField name="Status" type="integer">
  HTTP status code. `200` on success.
</ResponseField>

<ResponseField name="Message" type="string">
  A human-readable message confirming the creation.
</ResponseField>

<ResponseField name="Value" type="object">
  Contains the `Id` of the newly created record.
</ResponseField>

<ResponseField name="WasSuccessful" type="boolean">
  `true` if the courselesson was created successfully.
</ResponseField>

<ResponseField name="Errors" type="array">
  `null` on success.
</ResponseField>

```json Example Response theme={null}
{
  "Status": 200,
  "Message": "CourseLesson was successfully created.",
  "Value": {
    "Id": 87654321
  },
  "OpenInDialog": false,
  "OpenInWindow": false,
  "RedirectURL": null,
  "JavaScript": null,
  "UpdatedOn": "2025-01-15T10:30:00Z",
  "UpdatedBy": "admin@example.com",
  "Errors": null,
  "WasSuccessful": true
}
```

### 400

<ResponseField name="Message" type="string">
  A summary of the validation error(s), in the format `PropertyName: error message`.
</ResponseField>

<ResponseField name="Value" type="any">
  `null` on validation failure.
</ResponseField>

<ResponseField name="Errors" type="object[]">
  Array of validation errors.

  <Expandable>
    <ResponseField name="AttemptedValue" type="any">
      The value that was submitted for the field, or `null` if missing.
    </ResponseField>

    <ResponseField name="Message" type="string">
      The validation error message.
    </ResponseField>

    <ResponseField name="PropertyName" type="string">
      The name of the property that failed validation.
    </ResponseField>
  </Expandable>
</ResponseField>

<ResponseField name="WasSuccessful" type="boolean">
  `false` when the request fails validation.
</ResponseField>

```json Example Response theme={null}
{
  "Message": "Title: is a required field",
  "Value": null,
  "Errors": [
    {
      "AttemptedValue": null,
      "Message": "is a required field",
      "PropertyName": "Title"
    }
  ],
  "WasSuccessful": false
}
```
