# Tích hợp API

## **Tài liệu hướng dẫn tích hợp SlimEmail API**

Base URL dùng chung: `https://user.slimemail.vn`\
Mọi request là dạng `POST`, dữ liệu gửi dưới dạng `application/x-www-form-urlencoded`.

### 🔒 Yêu cầu bắt buộc

* `api_key`: API key trong cài đặt SlimEmail.
* `app_path`: Đường dẫn cài đặt SlimEmail, ví dụ `https://user.slimemail.vn`.

***

### 1. 🎯 **Đăng ký nhận tin (Subscribe)**

**Endpoint:** `/subscribe`

#### Tham số yêu cầu:

| Tham số   | Bắt buộc | Mô tả                                                          |
| --------- | -------- | -------------------------------------------------------------- |
| `api_key` | ✅        | API key                                                        |
| `list`    | ✅        | List ID (danh sách đăng ký)                                    |
| `email`   | ✅        | Email người dùng                                               |
| `name`    | ❌        | Tên người dùng                                                 |
| `boolean` | ❌        | Trả về true/false thay vì thông báo HTML (`true` hoặc `false`) |

#### Ví dụ:

```bash
POST https://user.slimemail.vn/subscribe
```

**Body:**

```x-www-form-urlencoded
api_key=YOUR_API_KEY
app_path=https://user.slimemail.vn
list=LIST_ID
email=john@example.com
name=John Doe
boolean=true
```

***

### 2. ❌ **Huỷ đăng ký (Unsubscribe)**

**Endpoint:** `/unsubscribe`

#### Tham số yêu cầu:

| Tham số   | Bắt buộc | Mô tả         |
| --------- | -------- | ------------- |
| `api_key` | ✅        | API key       |
| `list`    | ✅        | List ID       |
| `email`   | ✅        | Email cần huỷ |

#### Ví dụ:

```bash
POST https://user.slimemail.vn/unsubscribe
```

**Body:**

```x-www-form-urlencoded
api_key=YOUR_API_KEY
app_path=https://user.slimemail.vn
list=LIST_ID
email=john@example.com
```

***

### 3. 🗑️ **Xoá người đăng ký (Delete Subscriber)**

**Endpoint:** `/api/subscribers/delete.php`

#### Tham số yêu cầu:

| Tham số   | Bắt buộc | Mô tả         |
| --------- | -------- | ------------- |
| `api_key` | ✅        | API key       |
| `list`    | ✅        | List ID       |
| `email`   | ✅        | Email cần xoá |

#### Ví dụ:

```bash
POST https://user.slimemail.vn/api/subscribers/delete.php
```

**Body:**

```x-www-form-urlencoded
api_key=YOUR_API_KEY
app_path=https://user.slimemail.vn
list=LIST_ID
email=john@example.com
```

***

### 4. 📨 **Tạo và gửi chiến dịch (Create & Send Campaigns)**

**Endpoint:** `/api/campaigns/create.php`

#### Tham số yêu cầu:

| Tham số         | Bắt buộc | Mô tả                                       |
| --------------- | -------- | ------------------------------------------- |
| `api_key`       | ✅        | API key                                     |
| `from_name`     | ✅        | Tên người gửi                               |
| `from_email`    | ✅        | Email người gửi                             |
| `reply_to`      | ✅        | Email trả lời                               |
| `title`         | ✅        | Tiêu đề chiến dịch                          |
| `subject`       | ✅        | Tiêu đề email                               |
| `plain_text`    | ❌        | Nội dung text (tuỳ chọn)                    |
| `html_text`     | ✅        | Nội dung HTML                               |
| `list_ids`      | ✅        | Danh sách ID (ngăn cách dấu phẩy nếu nhiều) |
| `send_campaign` | ✅        | `1` để gửi ngay                             |
| `brand_id`      | ❌        | Nếu không dùng `list_ids`                   |

#### Ví dụ:

```bash
POST https://user.slimemail.vn/api/campaigns/create.php
```

**Body:**

```x-www-form-urlencoded
api_key=YOUR_API_KEY
app_path=https://user.slimemail.vn
from_name=SlimCRM
from_email=marketing@slimcrm.vn
reply_to=support@slimcrm.vn
title=Chiến dịch tháng 6
subject=Khám phá tính năng mới!
html_text=<h1>Xin chào!</h1><p>Chúng tôi vừa cập nhật hệ thống...</p>
list_ids=abc123xyz
send_campaign=1
```

***

### 5. 🔎 **Kiểm tra trạng thái đăng ký (Subscription Status)**

**Endpoint:** `/api/subscribers/subscription-status.php`

#### Tham số yêu cầu:

| Tham số   | Bắt buộc | Mô tả              |
| --------- | -------- | ------------------ |
| `api_key` | ✅        | API key            |
| `list_id` | ✅        | List ID            |
| `email`   | ✅        | Email cần kiểm tra |

#### Phản hồi có thể là:

* `Subscribed`
* `Unsubscribed`
* `Unconfirmed`
* `Bounced`
* `Soft bounced`
* `Complained`
* `Email does not exist in list`

#### Ví dụ:

```bash
POST https://user.slimemail.vn/api/subscribers/subscription-status.php
```

**Body:**

```x-www-form-urlencoded
api_key=YOUR_API_KEY
app_path=https://user.slimemail.vn
list_id=abc123xyz
email=john@example.com
```

***

### 6. 📊 **Đếm số lượng subscriber đang hoạt động**

**Endpoint:** `/api/subscribers/active-subscriber-count.php`

#### Tham số yêu cầu:

| Tham số   | Bắt buộc | Mô tả   |
| --------- | -------- | ------- |
| `api_key` | ✅        | API key |
| `list_id` | ✅        | List ID |

#### Ví dụ:

```bash
POST https://user.slimemail.vn/api/subscribers/active-subscriber-count.php
```

**Body:**

```x-www-form-urlencoded
api_key=YOUR_API_KEY
app_path=https://user.slimemail.vn
list_id=abc123xyz
```

#### Phản hồi:

Trả về số lượng subscriber đang hoạt động dưới dạng số.

***


---

# 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.slimemail.vn/start/huong-dan-nang-cao/tich-hop-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.
