> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://developer.crehana.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://developer.crehana.com/_mcp/server.

# Assign Course To Multiple Users

POST https://www.crehana.com/api/v5/rest/org/{organization_slug}/learning/content/knowledge-hub/enrollments/v2/assign-course/
Content-Type: application/json

Assign a course to a set of users in a single request. Returns 422 when
the request does not end up assigning the course to any user.

Reference: https://developer.crehana.com/api-reference/endpoints/learning-v-2/assign-course-to-multiple-users-v-2

## Authentication

- `Api-Key` header (required) — API key of the organization. Always sent together with the `Secret-Access` header.

## Servers

- `https://www.crehana.com` (Production, default)
- `https://qa.creha.co` (QA)

## Request

### Path parameters

- `organization_slug` (string, required)

### Body (application/json)

This endpoint expects an AssignCourseToUsersInput.

- `content_value` (integer, required) — Id of the course to assign, as returned in course.content_value by the learning v2 catalog endpoints
- `centralized_user_list_ids` (list of integer, required) — Centralized user ids that will receive the course
- `send_email_to_all_selected_users` (boolean, optional, default: false) — Whether to notify every selected user by email

## Response

### 200

Course assigned (fully or partially; see the response code field)

- `message` (string, required) — Message of the response
- `code` (string, required) — Internal code of the response
- `datetime` (string, required) — Datetime of the API in ISO Format
- `data` (AssignCourseToUsersData, optional) — Course assignment details

### 202

Assignment queued for background processing

## Errors

### 400 Bad Request Error

Validation error

- `message` (string, required) — Message of the error
- `code` (string, required) — Internal code of the error
- `datetime` (string, required) — Datetime of the API in ISO Format
- `detail` (string, required) — Detail of the error

### 401 Unauthorized Error

Unauthorized - Invalid or missing credentials

- `any`

### 404 Not Found Error

Course does not exist or is deactivated

- `message` (string, required) — Message of the error
- `code` (string, required) — Internal code of the error
- `datetime` (string, required) — Datetime of the API in ISO Format
- `detail` (string, required) — Detail of the error

### 409 Conflict Error

Integrity error while assigning the course

- `message` (string, required) — Message of the error
- `code` (string, required) — Internal code of the error
- `datetime` (string, required) — Datetime of the API in ISO Format
- `detail` (string, required) — Detail of the error

### 422 Unprocessable Entity Error

No users could be assigned (none belong to the organization, or all are inactive/deleted)

- `any`

### 500 Internal Server Error

Internal server error

- `message` (string, required) — Message of the error
- `code` (string, required) — Internal code of the error
- `datetime` (string, required) — Datetime of the API in ISO Format
- `detail` (string, required) — Detail of the error

## Types

### AssignCourseToUsersData

- `course_id` (integer, required) — Id of the assigned course (the content_value sent in the request)
- `total_users_requested` (integer, required) — Number of users included in the request
- `total_user_assigned` (integer, required) — Users the course was assigned to; when is_async_flow is true it means users queued for background processing
- `total_users_skipped` (integer, required) — Requested users that could not be assigned
- `is_async_flow` (boolean, required) — Whether the assignment is processed asynchronously in background
- `list_users_not_active` (list of integer, optional) — Internal user ids skipped for being inactive (currently always empty: the enrollment service does not populate it)
- `list_users_deleted` (list of integer, optional) — Internal user ids skipped for being deleted (currently always empty: the enrollment service does not populate it)
- `list_user_dont_belong` (list of integer, optional) — Internal user ids (not centralized ids) that don't belong to the organization; only populated when no requested user belongs to it

## Examples

### Example 1

**Request**

```json
{
  "content_value": 49563,
  "centralized_user_list_ids": [
    87785
  ],
  "send_email_to_all_selected_users": true
}
```

**Response**

```json
{}
```

**SDK Code**

```python
import requests

url = "https://www.crehana.com/api/v5/rest/org/organization_slug/learning/content/knowledge-hub/enrollments/v2/assign-course/"

payload = {
    "content_value": 49563,
    "centralized_user_list_ids": [87785],
    "send_email_to_all_selected_users": True
}
headers = {
    "Secret-Access": "Secret-Access",
    "Api-Key": "<apiKey>",
    "Content-Type": "application/json"
}

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

print(response.json())
```

```javascript
const url = 'https://www.crehana.com/api/v5/rest/org/organization_slug/learning/content/knowledge-hub/enrollments/v2/assign-course/';
const options = {
  method: 'POST',
  headers: {
    'Secret-Access': 'Secret-Access',
    'Api-Key': '<apiKey>',
    'Content-Type': 'application/json'
  },
  body: '{"content_value":49563,"centralized_user_list_ids":[87785],"send_email_to_all_selected_users":true}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

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

func main() {

	url := "https://www.crehana.com/api/v5/rest/org/organization_slug/learning/content/knowledge-hub/enrollments/v2/assign-course/"

	payload := strings.NewReader("{\n  \"content_value\": 49563,\n  \"centralized_user_list_ids\": [\n    87785\n  ],\n  \"send_email_to_all_selected_users\": true\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Secret-Access", "Secret-Access")
	req.Header.Add("Api-Key", "<apiKey>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

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

url = URI("https://www.crehana.com/api/v5/rest/org/organization_slug/learning/content/knowledge-hub/enrollments/v2/assign-course/")

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

request = Net::HTTP::Post.new(url)
request["Secret-Access"] = 'Secret-Access'
request["Api-Key"] = '<apiKey>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"content_value\": 49563,\n  \"centralized_user_list_ids\": [\n    87785\n  ],\n  \"send_email_to_all_selected_users\": true\n}"

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

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://www.crehana.com/api/v5/rest/org/organization_slug/learning/content/knowledge-hub/enrollments/v2/assign-course/")
  .header("Secret-Access", "Secret-Access")
  .header("Api-Key", "<apiKey>")
  .header("Content-Type", "application/json")
  .body("{\n  \"content_value\": 49563,\n  \"centralized_user_list_ids\": [\n    87785\n  ],\n  \"send_email_to_all_selected_users\": true\n}")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://www.crehana.com/api/v5/rest/org/organization_slug/learning/content/knowledge-hub/enrollments/v2/assign-course/', [
  'body' => '{
  "content_value": 49563,
  "centralized_user_list_ids": [
    87785
  ],
  "send_email_to_all_selected_users": true
}',
  'headers' => [
    'Api-Key' => '<apiKey>',
    'Content-Type' => 'application/json',
    'Secret-Access' => 'Secret-Access',
  ],
]);

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("https://www.crehana.com/api/v5/rest/org/organization_slug/learning/content/knowledge-hub/enrollments/v2/assign-course/");
var request = new RestRequest(Method.POST);
request.AddHeader("Secret-Access", "Secret-Access");
request.AddHeader("Api-Key", "<apiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"content_value\": 49563,\n  \"centralized_user_list_ids\": [\n    87785\n  ],\n  \"send_email_to_all_selected_users\": true\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "Secret-Access": "Secret-Access",
  "Api-Key": "<apiKey>",
  "Content-Type": "application/json"
]
let parameters = [
  "content_value": 49563,
  "centralized_user_list_ids": [87785],
  "send_email_to_all_selected_users": true
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://www.crehana.com/api/v5/rest/org/organization_slug/learning/content/knowledge-hub/enrollments/v2/assign-course/")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```

### Example 2

**Request**

```json
{
  "content_value": 49563,
  "centralized_user_list_ids": [
    87785
  ],
  "send_email_to_all_selected_users": true
}
```

**Response**

```json
{}
```

**SDK Code**

```python
import requests

url = "https://www.crehana.com/api/v5/rest/org/organization_slug/learning/content/knowledge-hub/enrollments/v2/assign-course/"

payload = {
    "content_value": 49563,
    "centralized_user_list_ids": [87785],
    "send_email_to_all_selected_users": True
}
headers = {
    "Secret-Access": "Secret-Access",
    "Api-Key": "<apiKey>",
    "Content-Type": "application/json"
}

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

print(response.json())
```

```javascript
const url = 'https://www.crehana.com/api/v5/rest/org/organization_slug/learning/content/knowledge-hub/enrollments/v2/assign-course/';
const options = {
  method: 'POST',
  headers: {
    'Secret-Access': 'Secret-Access',
    'Api-Key': '<apiKey>',
    'Content-Type': 'application/json'
  },
  body: '{"content_value":49563,"centralized_user_list_ids":[87785],"send_email_to_all_selected_users":true}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

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

func main() {

	url := "https://www.crehana.com/api/v5/rest/org/organization_slug/learning/content/knowledge-hub/enrollments/v2/assign-course/"

	payload := strings.NewReader("{\n  \"content_value\": 49563,\n  \"centralized_user_list_ids\": [\n    87785\n  ],\n  \"send_email_to_all_selected_users\": true\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Secret-Access", "Secret-Access")
	req.Header.Add("Api-Key", "<apiKey>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

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

url = URI("https://www.crehana.com/api/v5/rest/org/organization_slug/learning/content/knowledge-hub/enrollments/v2/assign-course/")

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

request = Net::HTTP::Post.new(url)
request["Secret-Access"] = 'Secret-Access'
request["Api-Key"] = '<apiKey>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"content_value\": 49563,\n  \"centralized_user_list_ids\": [\n    87785\n  ],\n  \"send_email_to_all_selected_users\": true\n}"

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

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://www.crehana.com/api/v5/rest/org/organization_slug/learning/content/knowledge-hub/enrollments/v2/assign-course/")
  .header("Secret-Access", "Secret-Access")
  .header("Api-Key", "<apiKey>")
  .header("Content-Type", "application/json")
  .body("{\n  \"content_value\": 49563,\n  \"centralized_user_list_ids\": [\n    87785\n  ],\n  \"send_email_to_all_selected_users\": true\n}")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://www.crehana.com/api/v5/rest/org/organization_slug/learning/content/knowledge-hub/enrollments/v2/assign-course/', [
  'body' => '{
  "content_value": 49563,
  "centralized_user_list_ids": [
    87785
  ],
  "send_email_to_all_selected_users": true
}',
  'headers' => [
    'Api-Key' => '<apiKey>',
    'Content-Type' => 'application/json',
    'Secret-Access' => 'Secret-Access',
  ],
]);

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("https://www.crehana.com/api/v5/rest/org/organization_slug/learning/content/knowledge-hub/enrollments/v2/assign-course/");
var request = new RestRequest(Method.POST);
request.AddHeader("Secret-Access", "Secret-Access");
request.AddHeader("Api-Key", "<apiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"content_value\": 49563,\n  \"centralized_user_list_ids\": [\n    87785\n  ],\n  \"send_email_to_all_selected_users\": true\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "Secret-Access": "Secret-Access",
  "Api-Key": "<apiKey>",
  "Content-Type": "application/json"
]
let parameters = [
  "content_value": 49563,
  "centralized_user_list_ids": [87785],
  "send_email_to_all_selected_users": true
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://www.crehana.com/api/v5/rest/org/organization_slug/learning/content/knowledge-hub/enrollments/v2/assign-course/")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```