# Kết nối API

## Tạo Api Token

API Token là chuỗi mã hóa chứa thông tin truy cập api, có thời gian hết hạn xác định bởi người tạo

* Truy cập **\[ Hệ thống ]** > **\[ Cài đặt ]** > **\[ Quản lý API ]**
* Bấm nút **\[ Thêm tài khoản ]** để tạo token mới
* *Lưu ý:* mỗi token sẽ có thời gian hết hạn xác định
* **Nếu bạn không tìm thấy** mục **\[ Quản lý API ]** thì hãy yêu cầu bộ phận hỗ trợ của SlimCRM kích hoạt tính năng API bởi mặc định tính năng này bị tắt

![(Tạo API token mới)](/files/-MkpwVanO4tOL1NLUFE6)

## Cách sử dụng API

Chi tiết danh sách các API được liệt kê bên dưới\
Giả sử bạn đã tạo token **jEheVytlAoFl7F8MqUQ7jAo2hOXASztXj** và bạn cần lấy về danh sách tất cả các KHÁCH HÀNG của SlimCRM, hãy sử dụng API thông qua cURL request như sau&#x20;

```
curl -H "authtoken: jEheVytlAoFl7F8MqUQ7jAo2hOXASztXj" https://crm.slimsoft.vn/demo/api/customers
```

Bạn có thể sử dụng [http://postman.com](http://postman.com/) để test và tìm hiểu nhanh các API mà không cần viết code

## &#x20;**1. Khách hàng**

## Tìm kiếm thông tin khách hàng theo keyword

<mark style="color:blue;">`GET`</mark> `[url]/api/customers/search/:keyseach`

Keysearch: có thể là tên, số điện thoại, email...

#### Headers

| Name                                        | Type   | Description |
| ------------------------------------------- | ------ | ----------- |
| authtoken<mark style="color:red;">\*</mark> | String |             |

{% tabs %}
{% tab title="200: OK Customer object" %}

```javascript
{
    // Response
}
```

{% endtab %}
{% endtabs %}

## Thêm mới khách hàng

<mark style="color:green;">`POST`</mark> `[url]/api/customers`

#### Headers

| Name      | Type   | Description |
| --------- | ------ | ----------- |
| authtoken | string | Api token   |

#### Request Body

| Name        | Type   | Description    |
| ----------- | ------ | -------------- |
| company     | string | Tên công ty    |
| vat         | string | Mã số thuế VAT |
| phonenumber | string | Số điện thoại  |
| website     | string | Website        |
| address     | string | Địa chỉ        |
| city        | string | Khu vực        |
|             | String |                |

{% tabs %}
{% tab title="200 " %}

```
HTTP/1.1 200 OK
{
  "status": true,
  "message": "Customer add successful."
}

HTTP/1.1 404 Not Found
{
  "status": false,
  "message": "Customer add fail."
}
```

{% endtab %}
{% endtabs %}

## Cập nhật thông tin khách hàng

<mark style="color:orange;">`PUT`</mark> `[url]/api/customers/:id`

#### Headers

| Name                                        | Type   | Description |
| ------------------------------------------- | ------ | ----------- |
| authtoken<mark style="color:red;">\*</mark> | String | Api token   |

#### Request Body

| Name                                      | Type   | Description                |
| ----------------------------------------- | ------ | -------------------------- |
| company<mark style="color:red;">\*</mark> | String | Mandatory Customer company |
| optionalvat                               | String | Vat                        |
| phonenumber                               | String | Customer Phone             |
| website                                   | String | Customer Website           |
| groups\_in                                | Number | Customer groups            |
| default\_language                         | String | Customer Default Language  |
| default\_currency                         | String |                            |
| address                                   | String |                            |
| billing\_street                           | String |                            |
| billing\_country                          | String |                            |
| shipping\_street                          | String |                            |
|                                           | String |                            |

{% tabs %}
{% tab title="200: OK " %}

```javascript
{ 
 "company": "Tên công ty", 
 "vat": "", 
 "phonenumber": "0123456789", 
 "website": "", 
 "default_language": "", 
 "default_currency": "0", 
 "country": "243", 
 "city": "TP HN", 
 "zip": "700000", 
 "state": "", 
 "address": "Ngõ 14", 
 "billing_street": "Nguyễn Trãi", 
 "billing_city": "TP Hà Nội", 
 "billing_state": "Quận HĐ", 
 "billing_zip": "700000", 
 "billing_country": "243", 
 "shipping_street": "", 
 "shipping_city": "", 
 "shipping_state": "", 
 "shipping_zip": "", 
 "shipping_country": "0" 
} 

```

{% endtab %}
{% endtabs %}

## Xóa thông tin khách hàng

<mark style="color:red;">`DELETE`</mark> `[url]/api/delete/customers/:id`

#### Headers

| Name                                        | Type   | Description |
| ------------------------------------------- | ------ | ----------- |
| authtoken<mark style="color:red;">\*</mark> | String |             |

#### Request Body

| Name                                 | Type   | Description        |
| ------------------------------------ | ------ | ------------------ |
| id<mark style="color:red;">\*</mark> | Number | Customer unique ID |

## Lấy về thông tin khách hàng

<mark style="color:blue;">`GET`</mark> `[url]/api/customers/:id`

#### Headers

| Name                                        | Type   | Description |
| ------------------------------------------- | ------ | ----------- |
| authtoken<mark style="color:red;">\*</mark> | String |             |

#### Request Body

| Name                                 | Type   | Description        |
| ------------------------------------ | ------ | ------------------ |
| id<mark style="color:red;">\*</mark> | Number | customer unique ID |

## **2. Cơ hội**

## Tìm kiếm thông tin "Cơ hội" theo keyword

<mark style="color:blue;">`GET`</mark> `[url]/api/leads/:keysearch`

Keyseach: có thể là tên, email, số điện thoại

#### Headers

| Name      | Type   | Description |
| --------- | ------ | ----------- |
| authtoken | String |             |

{% tabs %}
{% tab title="200: OK Lead Object" %}

```javascript
{
    // Response
}
```

{% endtab %}
{% endtabs %}

## Thêm mới cơ hội

<mark style="color:green;">`POST`</mark> `[url]/api/leads`

#### Headers

| Name      | Type   | Description |
| --------- | ------ | ----------- |
| authtoken | string | Api token   |

#### Request Body

| Name             | Type   | Description                    |
| ---------------- | ------ | ------------------------------ |
| source           | string | Nguồn cơ hội                   |
| status           | string | Tình trạng cơ hội              |
| name             | string | Tên cơ hội                     |
| assigned         | string | ID người phụ trách             |
| tags             | string | Gắn nhãn                       |
| title            | string | Chức vụ                        |
| email            | string | Địa chỉ email                  |
| website          | string | Website                        |
| phonenumber      | string | Số điện thoại                  |
| company          | string | Tên công ty                    |
| address          | string | Địa chỉ                        |
| city             | string | Khu vực                        |
| description      | string | Mô tả                          |
| contacted\_today | string | Đã liên hệ                     |
| is\_public       | string | Công khai, tất cả đều được xem |

{% tabs %}
{% tab title="200 " %}

```
HTTP/1.1 200 OK
{
  "status": true,
  "message": "Lead add successful."
}

HTTP/1.1 404 Not Found
{
  "status": false,
  "message": "Lead add fail."
}
```

{% endtab %}
{% endtabs %}

## Lấy thông tin cơ hội

<mark style="color:blue;">`GET`</mark> `[url]/api/leads/:id`

#### Path Parameters

| Name | Type   | Description     |
| ---- | ------ | --------------- |
| id   | string | ID của "Cơ hội" |

#### Headers

| Name      | Type   | Description |
| --------- | ------ | ----------- |
| authtoken | string | API token   |

{% tabs %}
{% tab title="200 " %}

```
HTTP/1.1 200 OK
{
    "id": "17",
    "hash": "c6e938f8b7a40b1bcfd98dc04f6eeee0-60d9c039da373a685fc0f74d4bfae631",
    "name": "Lead name",
    "contact": "",
    "title": "",
    "company": "Themesic Interactive",
    "description": "",
    "country": "243",
    "zip": null,
    "city": "London",
    "state": "London",
    "address": "1a The Alexander Suite Silk Point",
    "assigned": "5",
    "dateadded": "2019-07-18 08:59:28",
    "from_form_id": "0",
    "status": "0",
    "source": "4",
    ...
}
```

{% endtab %}

{% tab title="404 " %}

```
HTTP/1.1 404 Not Found
{
  "status": false,
  "message": "No data were found"
}
```

{% endtab %}
{% endtabs %}

## **3. Dự án**

→ Thêm mới Dự án\
→ Xóa Dự án\
→ Yêu cầu thông tin về Dự án\
→ Tìm kiếm thông tin Dự án\
→ Sửa thông tin Dự án

## **4. Nhân viên**

→ Thêm mới Nhân viên\
→ Xóa Nhân viên\
→ Yêu cầu thông tin Nhân viên\
→ Tìm kiếm thông tin Nhân viên\
→ Sửa thông tin Nhân viên

## **5. Công việc**

→ Thêm mới Công việc\
→ Xóa Công việc\
→ Yêu cầu thông tin về Công việc\
→ Tìm kiếm thông tin Công việc\
→ Sửa thông tin Công việc

## **6. Yêu cầu hỗ trợ (tickets)**

→ Thêm mới Yêu cầu\
→ Xóa Yêu cầu\
→ Yêu cầu thông tin\
→ Tìm kiếm thông tin về Yêu cầu hỗ trợ\
→ Sửa thông tin về Yêu cầu hỗ trợ<br>

{% hint style="info" %}
Tải về [tài liệu API đầy đủ](https://drive.google.com/file/d/1YHkIK8FsZifRAt4ux53h0btiOd5dV3tj/view?usp=sharing)
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://help.slimcrm.vn/tich-hop/tong-quan-cac-api.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
