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

# Xem trước (dry-run) trước khi assign

POST https://example.gitiho.com/api/lms/assignments/preview
Content-Type: application/json

Chạy thử toàn bộ batch để ước tính chi phí và kiểm tra tính hợp lệ của từng item **mà không tạo ra dữ liệu thực tế**, không tạo order và không tính phí. Dùng để hiển thị cho người dùng xác nhận trước khi gọi `assign-course`.

**Body params:**

| Param | Bắt buộc | Kiểu | Mô tả |
|-------|----------|------|-------|
| `items` | Có | array (1–100) | Danh sách cặp khoá – nhân sự cần kiểm tra |
| `items[].course_id` | Có | int | ID khoá học |
| `items[].employer_id` | Có | int | ID nhân sự |
| `deadline` | Không | date | Hạn hoàn thành (đưa vào để đồng bộ payload với bước assign) |

**Response gồm:**

- `amount` — tổng chi phí dự kiến nếu thực thi.
- `unpaid_invoice_blocking` — có hoá đơn chưa thanh toán đang chặn việc assign hay không.
- `summary` — `total` / `valid` / `invalid`.
- `items[]` — mỗi item có `course_id`, `employer_id`, `price`, `status` và `status_text`. Các trạng thái preview: `will_assign` (sẽ được assign), `skip_already_assigned` (đã assign trước đó, sẽ bỏ qua), `invalid_employer` (nhân sự không tồn tại/ngừng hoạt động), `invalid_course` (khoá không khả dụng).

Reference: https://developer.gitiho.com/gitiho-business-api/lms/xem-trước-dry-run-trước-khi-assign

## OpenAPI Specification

```yaml
openapi: 3.1.0
info:
  title: collection
  version: 1.0.0
paths:
  /api/lms/assignments/preview:
    post:
      operationId: Xem trước (dry-run) trước khi assign
      summary: Xem trước (dry-run) trước khi assign
      description: >-
        Chạy thử toàn bộ batch để ước tính chi phí và kiểm tra tính hợp lệ của
        từng item **mà không tạo ra dữ liệu thực tế**, không tạo order và không
        tính phí. Dùng để hiển thị cho người dùng xác nhận trước khi gọi
        `assign-course`.


        **Body params:**


        | Param | Bắt buộc | Kiểu | Mô tả |

        |-------|----------|------|-------|

        | `items` | Có | array (1–100) | Danh sách cặp khoá – nhân sự cần kiểm
        tra |

        | `items[].course_id` | Có | int | ID khoá học |

        | `items[].employer_id` | Có | int | ID nhân sự |

        | `deadline` | Không | date | Hạn hoàn thành (đưa vào để đồng bộ payload
        với bước assign) |


        **Response gồm:**


        - `amount` — tổng chi phí dự kiến nếu thực thi.

        - `unpaid_invoice_blocking` — có hoá đơn chưa thanh toán đang chặn việc
        assign hay không.

        - `summary` — `total` / `valid` / `invalid`.

        - `items[]` — mỗi item có `course_id`, `employer_id`, `price`, `status`
        và `status_text`. Các trạng thái preview: `will_assign` (sẽ được
        assign), `skip_already_assigned` (đã assign trước đó, sẽ bỏ qua),
        `invalid_employer` (nhân sự không tồn tại/ngừng hoạt động),
        `invalid_course` (khoá không khả dụng).
      tags:
        - LMS
      responses:
        '200':
          description: Successful response
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                items:
                  type: array
                  items:
                    $ref: >-
                      #/components/schemas/type_lms:XemTrướcDryRunTrướcKhiAssignLmsRequestItemsItem
                deadline:
                  type: string
                  format: date
              required:
                - items
                - deadline
servers:
  - url: https://example.gitiho.com
    description: Default
components:
  schemas:
    type_lms:XemTrướcDryRunTrướcKhiAssignLmsRequestItemsItem:
      type: object
      properties:
        course_id:
          type: integer
        employer_id:
          type: integer
      required:
        - course_id
        - employer_id
      title: XemTrướcDryRunTrướcKhiAssignLmsRequestItemsItem

```

## Examples

**Request**

```json
{
  "items": [
    {
      "course_id": 337,
      "employer_id": 2049
    },
    {
      "course_id": 814,
      "employer_id": 2050
    }
  ],
  "deadline": "2026-09-30"
}
```

**SDK Code**

```python
import requests

url = "https://example.gitiho.com/api/lms/assignments/preview"

payload = {
    "items": [
        {
            "course_id": 337,
            "employer_id": 2049
        },
        {
            "course_id": 814,
            "employer_id": 2050
        }
    ],
    "deadline": "2026-09-30"
}
headers = {"Content-Type": "application/json"}

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

print(response.json())
```

```javascript
const url = 'https://example.gitiho.com/api/lms/assignments/preview';
const options = {
  method: 'POST',
  headers: {'Content-Type': 'application/json'},
  body: '{"items":[{"course_id":337,"employer_id":2049},{"course_id":814,"employer_id":2050}],"deadline":"2026-09-30"}'
};

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://example.gitiho.com/api/lms/assignments/preview"

	payload := strings.NewReader("{\n  \"items\": [\n    {\n      \"course_id\": 337,\n      \"employer_id\": 2049\n    },\n    {\n      \"course_id\": 814,\n      \"employer_id\": 2050\n    }\n  ],\n  \"deadline\": \"2026-09-30\"\n}")

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

	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://example.gitiho.com/api/lms/assignments/preview")

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

request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n  \"items\": [\n    {\n      \"course_id\": 337,\n      \"employer_id\": 2049\n    },\n    {\n      \"course_id\": 814,\n      \"employer_id\": 2050\n    }\n  ],\n  \"deadline\": \"2026-09-30\"\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://example.gitiho.com/api/lms/assignments/preview")
  .header("Content-Type", "application/json")
  .body("{\n  \"items\": [\n    {\n      \"course_id\": 337,\n      \"employer_id\": 2049\n    },\n    {\n      \"course_id\": 814,\n      \"employer_id\": 2050\n    }\n  ],\n  \"deadline\": \"2026-09-30\"\n}")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://example.gitiho.com/api/lms/assignments/preview', [
  'body' => '{
  "items": [
    {
      "course_id": 337,
      "employer_id": 2049
    },
    {
      "course_id": 814,
      "employer_id": 2050
    }
  ],
  "deadline": "2026-09-30"
}',
  'headers' => [
    'Content-Type' => 'application/json',
  ],
]);

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

```csharp
using RestSharp;

var client = new RestClient("https://example.gitiho.com/api/lms/assignments/preview");
var request = new RestRequest(Method.POST);
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"items\": [\n    {\n      \"course_id\": 337,\n      \"employer_id\": 2049\n    },\n    {\n      \"course_id\": 814,\n      \"employer_id\": 2050\n    }\n  ],\n  \"deadline\": \"2026-09-30\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = ["Content-Type": "application/json"]
let parameters = [
  "items": [
    [
      "course_id": 337,
      "employer_id": 2049
    ],
    [
      "course_id": 814,
      "employer_id": 2050
    ]
  ],
  "deadline": "2026-09-30"
] as [String : Any]

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

let request = NSMutableURLRequest(url: NSURL(string: "https://example.gitiho.com/api/lms/assignments/preview")! 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()
```