> 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 Track To Multiple Users

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

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

Reference: https://developer.crehana.com/api-reference/endpoints/learning-v-2/assign-track-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 AssignTrackToUsersInput.

- `track_id` (integer, required) — Id of the track (learning path) to assign, as returned in track.id by the learning tracks catalog endpoint
- `centralized_user_list_ids` (list of integer, required) — Centralized user ids that will receive the track
- `send_email_to_all_selected_users` (boolean, optional, default: false) — Whether to notify every selected user by email

## Response

### 200

Track 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` (AssignTrackToUsersData, optional) — Track 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

Track 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 track

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

### AssignTrackToUsersData

- `track_id` (integer, required) — Id of the assigned track (the track_id sent in the request)
- `total_users_requested` (integer, required) — Number of users included in the request
- `total_user_assigned` (integer, required) — Users the track 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
- `list_users_deleted` (list of integer, optional) — Internal user ids skipped for being deleted
- `list_user_dont_belong` (list of integer, optional) — Internal user ids (not centralized ids) that don't belong to the organization

## Examples

### Example 1

**Request**

```json
{
  "track_id": 1234,
  "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-track/"

payload = {
    "track_id": 1234,
    "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-track/';
const options = {
  method: 'POST',
  headers: {
    'Secret-Access': 'Secret-Access',
    'Api-Key': '<apiKey>',
    'Content-Type': 'application/json'
  },
  body: '{"track_id":1234,"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-track/"

	payload := strings.NewReader("{\n  \"track_id\": 1234,\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-track/")

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  \"track_id\": 1234,\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-track/")
  .header("Secret-Access", "Secret-Access")
  .header("Api-Key", "<apiKey>")
  .header("Content-Type", "application/json")
  .body("{\n  \"track_id\": 1234,\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-track/', [
  'body' => '{
  "track_id": 1234,
  "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-track/");
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  \"track_id\": 1234,\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 = [
  "track_id": 1234,
  "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-track/")! 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
{
  "track_id": 1234,
  "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-track/"

payload = {
    "track_id": 1234,
    "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-track/';
const options = {
  method: 'POST',
  headers: {
    'Secret-Access': 'Secret-Access',
    'Api-Key': '<apiKey>',
    'Content-Type': 'application/json'
  },
  body: '{"track_id":1234,"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-track/"

	payload := strings.NewReader("{\n  \"track_id\": 1234,\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-track/")

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  \"track_id\": 1234,\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-track/")
  .header("Secret-Access", "Secret-Access")
  .header("Api-Key", "<apiKey>")
  .header("Content-Type", "application/json")
  .body("{\n  \"track_id\": 1234,\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-track/', [
  'body' => '{
  "track_id": 1234,
  "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-track/");
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  \"track_id\": 1234,\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 = [
  "track_id": 1234,
  "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-track/")! 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()
```