# Enroll Contact

POST https://services.leadconnectorhq.com/courses/enrollments

Grant a contact access to a membership offer. Requires a Location token with courses.write. Send Version: v3. Uses POST smart-list/user with source public_api (not the queued attach-offer-user path). Returns 200 when already enrolled and 201 when newly attached. Login tokens are never returned. checkoutFrom public_api is not in membership paidSources, so these grants are omitted from Net Revenue paid filters. Default-offer rows return 404.

## 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 |

### 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/enrollments": {
      "post": {
        "summary": "Enroll Contact",
        "operationId": "enrollContact",
        "description": "Grant a contact access to a membership offer. Requires a Location token with courses.write. Send Version: v3. Uses POST smart-list/user with source public_api (not the queued attach-offer-user path). Returns 200 when already enrolled and 201 when newly attached. Login tokens are never returned. checkoutFrom public_api is not in membership paidSources, so these grants are omitted from Net Revenue paid filters. Default-offer rows return 404.",
        "parameters": [
          {
            "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/EnrollDto"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/EnrollResponseDto"
                }
              }
            }
          },
          "201": {
            "description": "Created",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/EnrollResponseDto"
                }
              }
            }
          },
          "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": {
      "EnrollDto": {
        "type": "object",
        "properties": {
          "contactId": {
            "type": "string",
            "description": "CRM contact id",
            "example": "abc123ContactId"
          },
          "offerId": {
            "type": "string",
            "description": "Membership offer id",
            "example": "c3d4e5f6-7890-4123-cdef-123456789012"
          }
        },
        "required": [
          "contactId",
          "offerId"
        ],
        "title": "EnrollDto"
      },
      "EnrollResponseDto": {
        "type": "object",
        "properties": {
          "alreadyEnrolled": {
            "type": "boolean",
            "description": "true when the contact already has a purchase for this offer in the location"
          },
          "contactId": {
            "type": "string",
            "example": "abc123ContactId"
          },
          "offerId": {
            "type": "string",
            "example": "c3d4e5f6-7890-4123-cdef-123456789012"
          }
        },
        "required": [
          "alreadyEnrolled",
          "contactId",
          "offerId"
        ],
        "title": "EnrollResponseDto"
      }
    }
  }
}
```

## 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 = {
  "contactId": "abc123ContactId",
  "offerId": "c3d4e5f6-7890-4123-cdef-123456789012"
};

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

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

```python
from highlevel import HighLevel

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

body = {
    "contactId": "abc123ContactId",
    "offerId": "c3d4e5f6-7890-4123-cdef-123456789012"
}

response = await client.courses.enroll_contact(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 = [
    'contactId' => 'abc123ContactId',
    'offerId' => 'c3d4e5f6-7890-4123-cdef-123456789012'
];

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

## Code Examples

**cURL**

```bash
curl -L -X POST 'https://services.leadconnectorhq.com/courses/enrollments?locationId=<LOCATIONID>' \
  -H 'Authorization: Bearer <TOKEN>' \
  -H 'Version: v3' \
  -H 'Content-Type: application/json' \
  --data-raw '{
  "contactId": "abc123ContactId",
  "offerId": "c3d4e5f6-7890-4123-cdef-123456789012"
}'
```

**Node.js**

```javascript
const options = {
  method: 'POST',
  headers: {
    Authorization: 'Bearer <TOKEN>',
    Version: 'v3',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
      "contactId": "abc123ContactId",
      "offerId": "c3d4e5f6-7890-4123-cdef-123456789012"
  })
};

try {
  const response = await fetch('https://services.leadconnectorhq.com/courses/enrollments?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/enrollments"

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

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

payload = {
    "contactId": "abc123ContactId",
    "offerId": "c3d4e5f6-7890-4123-cdef-123456789012"
}

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/enrollments?locationId=<LOCATIONID>',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_CUSTOMREQUEST => 'POST',
  CURLOPT_HTTPHEADER => [
    'Authorization: Bearer <TOKEN>',
    'Version: v3',
    'Content-Type: application/json',
  ],
  CURLOPT_POSTFIELDS => '{
  "contactId": "abc123ContactId",
  "offerId": "c3d4e5f6-7890-4123-cdef-123456789012"
}',
]);

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

**Java**

```java
HttpResponse<String> response = Unirest
  .post("https://services.leadconnectorhq.com/courses/enrollments?locationId=<LOCATIONID>")
  .header("Authorization", "Bearer <TOKEN>")
  .header("Version", "v3")
  .header("Content-Type", "application/json")
  .body("{\"contactId\":\"abc123ContactId\",\"offerId\":\"c3d4e5f6-7890-4123-cdef-123456789012\"}")
  .asString();
```

**Go**

```go
package main

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

func main() {
  url := "https://services.leadconnectorhq.com/courses/enrollments?locationId=<LOCATIONID>"
  payload := strings.NewReader(`{
  "contactId": "abc123ContactId",
  "offerId": "c3d4e5f6-7890-4123-cdef-123456789012"
}`)
  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/enrollments?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 = '{
  "contactId": "abc123ContactId",
  "offerId": "c3d4e5f6-7890-4123-cdef-123456789012"
}'

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

**PowerShell**

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

$body = '{
  "contactId": "abc123ContactId",
  "offerId": "c3d4e5f6-7890-4123-cdef-123456789012"
}'

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