# Create Lesson

POST https://services.leadconnectorhq.com/courses/products/{productId}/lessons

Create a lesson. Requires title and categoryId. Accepts lesson columns. locationId, userId, productId, originId are not accepted. Requires a Location token with courses.write.

## Authentication

Send `Authorization: Bearer <token>` using:

- **Sub-Account token: OAuth access token or Private Integration Token.** Scopes: `courses.write`

## Parameters

### Header Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `Version` | string | Yes | API Version |

### Path Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `productId` | string | Yes | Product id |

### Query Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `locationId` | string | Yes | Location id or sub-account id is required. |

## OpenAPI Specification

```json
{
  "openapi": "3.0.0",
  "info": {
    "title": "HighLevel API",
    "version": "v3"
  },
  "servers": [
    {
      "url": "https://services.leadconnectorhq.com"
    }
  ],
  "paths": {
    "/courses/products/{productId}/lessons": {
      "post": {
        "summary": "Create Lesson",
        "operationId": "createLesson",
        "description": "Create a lesson. Requires title and categoryId. Accepts lesson columns. locationId, userId, productId, originId are not accepted. Requires a Location token with courses.write.",
        "parameters": [
          {
            "name": "productId",
            "required": true,
            "in": "path",
            "example": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
            "description": "Product id",
            "schema": {
              "type": "string",
              "format": "uuid",
              "minLength": 1
            }
          },
          {
            "name": "locationId",
            "required": true,
            "in": "query",
            "description": "Location id or sub-account id is required.",
            "schema": {
              "type": "string",
              "example": "ve9EPM428h8vShlRW1KT",
              "minLength": 1
            }
          },
          {
            "name": "Version",
            "in": "header",
            "description": "API Version",
            "required": true,
            "schema": {
              "type": "string",
              "enum": [
                "v3"
              ]
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateLessonDto"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/LessonItemDto"
                }
              }
            }
          },
          "400": {
            "description": "Bad Request"
          },
          "404": {
            "description": "Not Found"
          },
          "415": {
            "description": "Unsupported Media Type"
          },
          "429": {
            "description": "Too Many Requests"
          },
          "500": {
            "description": "Internal Server Error"
          }
        },
        "security": [
          {
            "Location-Access": [
              "courses.write"
            ]
          }
        ]
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearer": {
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "name": "Authorization",
        "in": "header",
        "description": "Use the Access Token generated with user type as Sub-Account (OR) Private Integration Token of Sub-Account.",
        "type": "http"
      },
      "Location-Access": {
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "name": "Authorization",
        "in": "header",
        "description": "Use the Access Token generated with user type as Sub-Account (OR) Private Integration Token of Sub-Account.",
        "type": "http"
      },
      "Location-Access-Only": {
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "name": "Authorization",
        "in": "header",
        "description": "Use the Access Token generated with user type as Sub-Account.",
        "type": "http"
      },
      "Agency-Access": {
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "name": "Authorization",
        "in": "header",
        "description": "Use the Access Token generated with user type as Agency (OR) Private Integration Token of Agency.",
        "type": "http"
      },
      "Agency-Access-Only": {
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "name": "Authorization",
        "in": "header",
        "description": "Use the Access Token generated with user type as Agency.",
        "type": "http"
      }
    },
    "schemas": {
      "CreateLessonDto": {
        "type": "object",
        "properties": {
          "description": {
            "type": "string",
            "nullable": true
          },
          "visibility": {
            "type": "string",
            "enum": [
              "draft",
              "published",
              "locked"
            ]
          },
          "posterImage": {
            "type": "string",
            "nullable": true
          },
          "sequenceNo": {
            "type": "number",
            "example": 1
          },
          "commentStatus": {
            "type": "string",
            "enum": [
              "visible",
              "hidden",
              "locked"
            ]
          },
          "contentId": {
            "type": "string",
            "nullable": true
          },
          "contentType": {
            "type": "string",
            "enum": [
              "video",
              "assignment",
              "quiz",
              "audio",
              "funnel"
            ]
          },
          "commentPermission": {
            "type": "string",
            "enum": [
              "hidden",
              "enabled",
              "locked"
            ]
          },
          "lockedByPost": {
            "type": "string",
            "nullable": true
          },
          "lockedByCategory": {
            "type": "string",
            "nullable": true
          },
          "certificateTemplateId": {
            "type": "string",
            "nullable": true
          },
          "metaData": {
            "type": "object",
            "nullable": true,
            "additionalProperties": true
          },
          "title": {
            "type": "string",
            "description": "Lesson title",
            "example": "Lesson 1"
          },
          "categoryId": {
            "type": "string",
            "description": "Category id",
            "example": "b2c3d4e5-f678-4901-bcde-f12345678901"
          }
        },
        "required": [
          "title",
          "categoryId"
        ],
        "title": "CreateLessonDto"
      },
      "LessonItemDto": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "description": "Lesson id",
            "example": "c3d4e5f6-7890-4123-cdef-123456789012"
          },
          "title": {
            "type": "string",
            "example": "Lesson 1"
          },
          "description": {
            "type": "string",
            "nullable": true
          },
          "categoryId": {
            "type": "string"
          },
          "visibility": {
            "type": "string",
            "enum": [
              "draft",
              "published",
              "locked"
            ]
          },
          "posterImage": {
            "type": "string",
            "nullable": true
          },
          "sequenceNo": {
            "type": "number"
          },
          "commentStatus": {
            "type": "string",
            "enum": [
              "visible",
              "hidden",
              "locked"
            ]
          },
          "contentId": {
            "type": "string",
            "nullable": true
          },
          "contentType": {
            "type": "string",
            "enum": [
              "video",
              "assignment",
              "quiz",
              "audio",
              "funnel"
            ]
          },
          "commentPermission": {
            "type": "string",
            "enum": [
              "hidden",
              "enabled",
              "locked"
            ]
          },
          "lockedByPost": {
            "type": "string",
            "nullable": true
          },
          "lockedByCategory": {
            "type": "string",
            "nullable": true
          },
          "certificateTemplateId": {
            "type": "string",
            "nullable": true
          },
          "metaData": {
            "type": "object",
            "nullable": true,
            "additionalProperties": true
          },
          "createdAt": {
            "type": "string"
          },
          "updatedAt": {
            "type": "string"
          }
        },
        "required": [
          "id",
          "title",
          "description",
          "categoryId",
          "visibility",
          "posterImage",
          "sequenceNo",
          "commentStatus",
          "contentId",
          "contentType",
          "commentPermission",
          "lockedByPost",
          "lockedByCategory",
          "certificateTemplateId",
          "metaData",
          "createdAt",
          "updatedAt"
        ],
        "title": "LessonItemDto"
      }
    }
  }
}
```

## HighLevel SDK Examples

**Node.js** (`@gohighlevel/api-client`)

```javascript
import HighLevel from '@gohighlevel/api-client';

const ghl = new HighLevel({
  privateIntegrationToken: '<PRIVATE_INTEGRATION_TOKEN>'
});

const body = {
  "sequenceNo": 1,
  "title": "Lesson 1",
  "categoryId": "b2c3d4e5-f678-4901-bcde-f12345678901"
};

const response = await ghl.courses.createLesson('<PRODUCTID>', { locationId: '<LOCATIONID>' }, body);
console.log(response);
```

**Python** (`gohighlevel-api-client`)

```python
from highlevel import HighLevel

client = HighLevel(
    private_integration_token='<PRIVATE_INTEGRATION_TOKEN>'
)

body = {
    "sequenceNo": 1,
    "title": "Lesson 1",
    "categoryId": "b2c3d4e5-f678-4901-bcde-f12345678901"
}

response = await client.courses.create_lesson('<PRODUCTID>', locationId='<LOCATIONID>', body=body)
print(response)
```

**PHP** (`gohighlevel/api-client`)

```php
<?php
require_once 'vendor/autoload.php';

use HighLevel\HighLevel;
use HighLevel\HighLevelConfig;

$config = new HighLevelConfig([
    'privateIntegrationToken' => '<PRIVATE_INTEGRATION_TOKEN>'
]);
$ghl = new HighLevel($config);

$body = [
    'sequenceNo' => 1,
    'title' => 'Lesson 1',
    'categoryId' => 'b2c3d4e5-f678-4901-bcde-f12345678901'
];

$response = $ghl->courses->createLesson('<PRODUCTID>', ['locationId' => '<LOCATIONID>'], $body);
echo json_encode($response, JSON_PRETTY_PRINT);
```

## Code Examples

**cURL**

```bash
curl -L -X POST 'https://services.leadconnectorhq.com/courses/products/<productId>/lessons?locationId=<LOCATIONID>' \
  -H 'Authorization: Bearer <TOKEN>' \
  -H 'Version: v3' \
  -H 'Content-Type: application/json' \
  --data-raw '{
  "sequenceNo": 1,
  "title": "Lesson 1",
  "categoryId": "b2c3d4e5-f678-4901-bcde-f12345678901"
}'
```

**Node.js**

```javascript
const options = {
  method: 'POST',
  headers: {
    Authorization: 'Bearer <TOKEN>',
    Version: 'v3',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
      "sequenceNo": 1,
      "title": "Lesson 1",
      "categoryId": "b2c3d4e5-f678-4901-bcde-f12345678901"
  })
};

try {
  const response = await fetch('https://services.leadconnectorhq.com/courses/products/<productId>/lessons?locationId=<LOCATIONID>', options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

**Python**

```python
import requests

url = "https://services.leadconnectorhq.com/courses/products/{productId}/lessons"

headers = {
    "Authorization": "Bearer <TOKEN>",
    "Version": "v3"
}

params = {
    "locationId": "<LOCATIONID>"
}

payload = {
    "sequenceNo": 1,
    "title": "Lesson 1",
    "categoryId": "b2c3d4e5-f678-4901-bcde-f12345678901"
}

response = requests.post(url, params=params, json=payload, headers=headers)
print(response.json())
```

**PHP**

```php
<?php
$curl = curl_init();

curl_setopt_array($curl, [
  CURLOPT_URL => 'https://services.leadconnectorhq.com/courses/products/<productId>/lessons?locationId=<LOCATIONID>',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_CUSTOMREQUEST => 'POST',
  CURLOPT_HTTPHEADER => [
    'Authorization: Bearer <TOKEN>',
    'Version: v3',
    'Content-Type: application/json',
  ],
  CURLOPT_POSTFIELDS => '{
  "sequenceNo": 1,
  "title": "Lesson 1",
  "categoryId": "b2c3d4e5-f678-4901-bcde-f12345678901"
}',
]);

$response = curl_exec($curl);
curl_close($curl);
echo $response;
```

**Java**

```java
HttpResponse<String> response = Unirest
  .post("https://services.leadconnectorhq.com/courses/products/<productId>/lessons?locationId=<LOCATIONID>")
  .header("Authorization", "Bearer <TOKEN>")
  .header("Version", "v3")
  .header("Content-Type", "application/json")
  .body("{\"sequenceNo\":1,\"title\":\"Lesson 1\",\"categoryId\":\"b2c3d4e5-f678-4901-bcde-f12345678901\"}")
  .asString();
```

**Go**

```go
package main

import (
  "fmt"
  "net/http"
  "io"
  "strings"
)

func main() {
  url := "https://services.leadconnectorhq.com/courses/products/<productId>/lessons?locationId=<LOCATIONID>"
  payload := strings.NewReader(`{
  "sequenceNo": 1,
  "title": "Lesson 1",
  "categoryId": "b2c3d4e5-f678-4901-bcde-f12345678901"
}`)
  req, _ := http.NewRequest("POST", url, payload)
  req.Header.Add("Authorization", "Bearer <TOKEN>")
  req.Header.Add("Version", "v3")

  res, _ := http.DefaultClient.Do(req)
  defer res.Body.Close()
  body, _ := io.ReadAll(res.Body)
  fmt.Println(string(body))
}
```

**Ruby**

```ruby
require 'uri'
require 'net/http'

url = URI("https://services.leadconnectorhq.com/courses/products/<productId>/lessons?locationId=<LOCATIONID>")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Authorization"] = "Bearer <TOKEN>"
request["Version"] = "v3"
request["Content-Type"] = "application/json"
request.body = '{
  "sequenceNo": 1,
  "title": "Lesson 1",
  "categoryId": "b2c3d4e5-f678-4901-bcde-f12345678901"
}'

response = http.request(request)
puts response.read_body
```

**PowerShell**

```powershell
$headers = @{
  "Authorization" = "Bearer <TOKEN>"
  "Version" = "v3"
}

$body = '{
  "sequenceNo": 1,
  "title": "Lesson 1",
  "categoryId": "b2c3d4e5-f678-4901-bcde-f12345678901"
}'

$response = Invoke-RestMethod -Uri 'https://services.leadconnectorhq.com/courses/products/<productId>/lessons?locationId=<LOCATIONID>' -Method 'POST' -Headers $headers -Body $body -ContentType 'application/json'
$response | ConvertTo-Json
```
