# 資料庫

### 建立 SQL 資料庫連線 <a href="#sql" id="sql"></a>

POST `/api/sql-databases/`

#### 請求內容

**請求參數**

| 欄位            | 類型             | 必填 | 說明                                                                                                                                                                    |
| ------------- | -------------- | -- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| name          | string         | 是  | Display name for this database connection                                                                                                                             |
| description   | string         | 否  | Description of the database and its purpose                                                                                                                           |
| databaseType  | object         | 是  | Type of database: PostgreSQL, MySQL, MSSQL, Oracle, or MaiAgent `postgresql`: PostgreSQL ; `mysql`: MySQL ; `maiagent`: MaiAgent ; `oracle`: Oracle ; `mssql`: MSSQL; |
| databaseUrl   | string         | 否  | Connection string for external databases. Not required for MaiAgent type as it uses the system default.                                                               |
| includeTables | object         | 否  | Optional list of tables to include. Format: {"tables": \["table1", "table2"]}. For MaiAgent type, this is auto-populated from uploaded files.                         |
| isActive      | boolean        | 否  | When disabled, this database will not be used in Text-to-SQL queries                                                                                                  |
| chatbots      | array\[IdName] | 否  |                                                                                                                                                                       |
| groups        | array\[IdName] | 否  |                                                                                                                                                                       |

**請求結構範例**

```typescript
{
  "name": string // Display name for this database connection
  "description"?: string // Description of the database and its purpose (非必填)
  "databaseType":  // Type of database: PostgreSQL, MySQL, MSSQL, Oracle, or MaiAgent

* `postgresql` - PostgreSQL
* `mysql` - MySQL
* `maiagent` - MaiAgent
* `oracle` - Oracle
* `mssql` - MSSQL
  {
  }
  "databaseUrl"?: string // Connection string for external databases. Not required for MaiAgent type as it uses the system default. (非必填)
  "includeTables"?: object // Optional list of tables to include. Format: {"tables": ["table1", "table2"]}. For MaiAgent type, this is auto-populated from uploaded files. (非必填)
  "isActive"?: boolean // When disabled, this database will not be used in Text-to-SQL queries (非必填)
  "chatbots"?: [ // 非必填
    {
      "id": string (uuid)
    }
  ]
  "groups"?: [ // 非必填
    {
      "id": string (uuid)
    }
  ]
}
```

**請求範例值**

```json
{
  "name": "範例名稱",
  "description": "範例字串",
  "databaseType": {},
  "databaseUrl": "範例字串",
  "includeTables": null,
  "isActive": true,
  "chatbots": [
    {
      "id": "550e8400-e29b-41d4-a716-446655440000"
    }
  ],
  "groups": [
    {
      "id": "550e8400-e29b-41d4-a716-446655440000"
    }
  ]
}
```

#### 程式碼範例

{% tabs %}
{% tab title="Shell/Bash" %}

```bash
# 呼叫 API 示例 (Shell)
curl -X POST "https://api.maiagent.ai/api/sql-databases/" \
  -H "Authorization: Api-Key YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "範例名稱",
    "description": "範例字串",
    "databaseType": {},
    "databaseUrl": "範例字串",
    "includeTables": null,
    "isActive": true,
    "chatbots": [
      {
        "id": "550e8400-e29b-41d4-a716-446655440000"
      }
    ],
    "groups": [
      {
        "id": "550e8400-e29b-41d4-a716-446655440000"
      }
    ]
  }'

# 請確認在執行前替換 YOUR_API_KEY 並核對請求資料。
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
const axios = require('axios');

// 設定請求標頭
const config = {
  headers: {
    'Authorization': 'Api-Key YOUR_API_KEY',
    'Content-Type': 'application/json'
  }
};

// 請求內容 (payload)
const data = {
    "name": "範例名稱",
    "description": "範例字串",
    "databaseType": {},
    "databaseUrl": "範例字串",
    "includeTables": null,
    "isActive": true,
    "chatbots": [
      {
        "id": "550e8400-e29b-41d4-a716-446655440000"
      }
    ],
    "groups": [
      {
        "id": "550e8400-e29b-41d4-a716-446655440000"
      }
    ]
  };

axios.post("https://api.maiagent.ai/api/sql-databases/", data, config)
  .then(response => {
    console.log('成功取得回應:');
    console.log(response.data);
  })
  .catch(error => {
    console.error('請求發生錯誤:');
    console.error(error.response?.data || error.message);
  });
```

{% endtab %}

{% tab title="Python" %}

```python
import requests

url = "https://api.maiagent.ai/api/sql-databases/"
headers = {
    "Authorization": "Api-Key YOUR_API_KEY",
    "Content-Type": "application/json"
}

# 請求內容 (payload)
data = {
      "name": "範例名稱",
      "description": "範例字串",
      "databaseType": {},
      "databaseUrl": "範例字串",
      "includeTables": null,
      "isActive": true,
      "chatbots": [
        {
          "id": "550e8400-e29b-41d4-a716-446655440000"
        }
      ],
      "groups": [
        {
          "id": "550e8400-e29b-41d4-a716-446655440000"
        }
      ]
    }

response = requests.post(url, json=data, headers=headers)
try:
    print("成功取得回應:")
    print(response.json())
except Exception as e:
    print("請求發生錯誤:", e)
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php
require 'vendor/autoload.php';

$client = new GuzzleHttp\Client();

try {
    $response = $client->post("https://api.maiagent.ai/api/sql-databases/", [
        'headers' => [
            'Authorization' => 'Api-Key YOUR_API_KEY',
            'Content-Type' => 'application/json'
        ],
        'json' => {
            "name": "範例名稱",
            "description": "範例字串",
            "databaseType": {},
            "databaseUrl": "範例字串",
            "includeTables": null,
            "isActive": true,
            "chatbots": [
                {
                    "id": "550e8400-e29b-41d4-a716-446655440000"
                }
            ],
            "groups": [
                {
                    "id": "550e8400-e29b-41d4-a716-446655440000"
                }
            ]
        }
    ]);
    
    $data = json_decode($response->getBody(), true);
    echo "成功取得回應:\n";
    print_r($data);
} catch (Exception $e) {
    echo '請求發生錯誤: ' . $e->getMessage();
}
?>
```

{% endtab %}
{% endtabs %}

#### 回應內容

**狀態碼: 201**

**回應結構範例**

```typescript
{
  "id": string (uuid)
  "name": string // Display name for this database connection
  "description"?: string // Description of the database and its purpose (非必填)
  "databaseType":  // Type of database: PostgreSQL, MySQL, MSSQL, Oracle, or MaiAgent

* `postgresql` - PostgreSQL
* `mysql` - MySQL
* `maiagent` - MaiAgent
* `oracle` - Oracle
* `mssql` - MSSQL
  {
  }
  "databaseUrl"?: string // Connection string for external databases. Not required for MaiAgent type as it uses the system default. (非必填)
  "includeTables"?: object // Optional list of tables to include. Format: {"tables": ["table1", "table2"]}. For MaiAgent type, this is auto-populated from uploaded files. (非必填)
  "isActive"?: boolean // When disabled, this database will not be used in Text-to-SQL queries (非必填)
  "status": 
  {
  }
  "deletedAt": string (timestamp)
  "tables": [
    {
      "id": string (uuid)
      "tableName": string // Name of the table in the database
      "description"?: string // Description of the table and its data for better Text-to-SQL understanding (非必填)
      "status": 
      {
      }
      "errorMessage": string // Error details if table creation or deletion failed
      "sourceFile": 
      {
        "id": string (uuid)
        "name": string
        "isFromKnowledgeBase": boolean // Determine if the source file originated from a knowledge base upload.

Returns True if the file was uploaded via knowledge base,
False if uploaded directly to the database.
      }
      "columns": [
        {
          "id": string (uuid)
          "columnName": string
          "columnType"?: string // Data type of the column (e.g., VARCHAR, INTEGER, TIMESTAMP) (非必填)
          "description"?: string // Description of the column for better Text-to-SQL understanding (非必填)
          "isPrimaryKey"?: boolean // 非必填
          "isNullable"?: boolean // 非必填
          "createdAt": string (timestamp)
          "updatedAt": string (timestamp)
        }
      ]
      "createdAt": string (timestamp)
      "updatedAt": string (timestamp)
    }
  ]
  "chatbots": [
    {
      "id": string (uuid)
      "name": string
    }
  ]
  "groups": [
    {
      "id": string (uuid)
      "name": string
    }
  ]
  "canUpdate": boolean // Return whether the current user can update this resource.
  "canDelete": boolean // Return whether the current user can delete this resource.
  "createdAt": string (timestamp)
  "updatedAt": string (timestamp)
}
```

**回應範例值**

```json
{
  "id": "550e8400-e29b-41d4-a716-446655440000",
  "name": "回應字串",
  "description": "回應字串",
  "databaseType": {},
  "databaseUrl": "回應字串",
  "includeTables": null,
  "isActive": false,
  "status": {},
  "deletedAt": "回應字串",
  "tables": [
    {
      "id": "550e8400-e29b-41d4-a716-446655440000",
      "tableName": "回應字串",
      "description": "回應字串",
      "status": {},
      "errorMessage": "回應字串",
      "sourceFile": {
        "id": "550e8400-e29b-41d4-a716-446655440000",
        "name": "回應字串",
        "isFromKnowledgeBase": false
      },
      "columns": [
        {
          "id": "550e8400-e29b-41d4-a716-446655440000",
          "columnName": "回應字串",
          "columnType": "回應字串",
          "description": "回應字串",
          "isPrimaryKey": false,
          "isNullable": false,
          "createdAt": "回應字串",
          "updatedAt": "回應字串"
        }
      ],
      "createdAt": "回應字串",
      "updatedAt": "回應字串"
    }
  ],
  "chatbots": [
    {
      "id": "550e8400-e29b-41d4-a716-446655440000",
      "name": "回應字串"
    }
  ],
  "groups": [
    {
      "id": "550e8400-e29b-41d4-a716-446655440000",
      "name": "回應字串"
    }
  ],
  "canUpdate": false,
  "canDelete": false,
  "createdAt": "回應字串",
  "updatedAt": "回應字串"
}
```

***

### 建立 SQL 資料庫連線 <a href="#sql" id="sql"></a>

POST `/api/v1/sql-databases/`

#### 請求內容

**請求參數**

| 欄位            | 類型             | 必填 | 說明                                                                                                                                                                    |
| ------------- | -------------- | -- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| name          | string         | 是  | Display name for this database connection                                                                                                                             |
| description   | string         | 否  | Description of the database and its purpose                                                                                                                           |
| databaseType  | object         | 是  | Type of database: PostgreSQL, MySQL, MSSQL, Oracle, or MaiAgent `postgresql`: PostgreSQL ; `mysql`: MySQL ; `maiagent`: MaiAgent ; `oracle`: Oracle ; `mssql`: MSSQL; |
| databaseUrl   | string         | 否  | Connection string for external databases. Not required for MaiAgent type as it uses the system default.                                                               |
| includeTables | object         | 否  | Optional list of tables to include. Format: {"tables": \["table1", "table2"]}. For MaiAgent type, this is auto-populated from uploaded files.                         |
| isActive      | boolean        | 否  | When disabled, this database will not be used in Text-to-SQL queries                                                                                                  |
| chatbots      | array\[IdName] | 否  |                                                                                                                                                                       |
| groups        | array\[IdName] | 否  |                                                                                                                                                                       |

**請求結構範例**

```typescript
{
  "name": string // Display name for this database connection
  "description"?: string // Description of the database and its purpose (非必填)
  "databaseType":  // Type of database: PostgreSQL, MySQL, MSSQL, Oracle, or MaiAgent

* `postgresql` - PostgreSQL
* `mysql` - MySQL
* `maiagent` - MaiAgent
* `oracle` - Oracle
* `mssql` - MSSQL
  {
  }
  "databaseUrl"?: string // Connection string for external databases. Not required for MaiAgent type as it uses the system default. (非必填)
  "includeTables"?: object // Optional list of tables to include. Format: {"tables": ["table1", "table2"]}. For MaiAgent type, this is auto-populated from uploaded files. (非必填)
  "isActive"?: boolean // When disabled, this database will not be used in Text-to-SQL queries (非必填)
  "chatbots"?: [ // 非必填
    {
      "id": string (uuid)
    }
  ]
  "groups"?: [ // 非必填
    {
      "id": string (uuid)
    }
  ]
}
```

**請求範例值**

```json
{
  "name": "範例名稱",
  "description": "範例字串",
  "databaseType": {},
  "databaseUrl": "範例字串",
  "includeTables": null,
  "isActive": true,
  "chatbots": [
    {
      "id": "550e8400-e29b-41d4-a716-446655440000"
    }
  ],
  "groups": [
    {
      "id": "550e8400-e29b-41d4-a716-446655440000"
    }
  ]
}
```

#### 程式碼範例

{% tabs %}
{% tab title="Shell/Bash" %}

```bash
# 呼叫 API 示例 (Shell)
curl -X POST "https://api.maiagent.ai/api/v1/sql-databases/" \
  -H "Authorization: Api-Key YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "範例名稱",
    "description": "範例字串",
    "databaseType": {},
    "databaseUrl": "範例字串",
    "includeTables": null,
    "isActive": true,
    "chatbots": [
      {
        "id": "550e8400-e29b-41d4-a716-446655440000"
      }
    ],
    "groups": [
      {
        "id": "550e8400-e29b-41d4-a716-446655440000"
      }
    ]
  }'

# 請確認在執行前替換 YOUR_API_KEY 並核對請求資料。
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
const axios = require('axios');

// 設定請求標頭
const config = {
  headers: {
    'Authorization': 'Api-Key YOUR_API_KEY',
    'Content-Type': 'application/json'
  }
};

// 請求內容 (payload)
const data = {
    "name": "範例名稱",
    "description": "範例字串",
    "databaseType": {},
    "databaseUrl": "範例字串",
    "includeTables": null,
    "isActive": true,
    "chatbots": [
      {
        "id": "550e8400-e29b-41d4-a716-446655440000"
      }
    ],
    "groups": [
      {
        "id": "550e8400-e29b-41d4-a716-446655440000"
      }
    ]
  };

axios.post("https://api.maiagent.ai/api/v1/sql-databases/", data, config)
  .then(response => {
    console.log('成功取得回應:');
    console.log(response.data);
  })
  .catch(error => {
    console.error('請求發生錯誤:');
    console.error(error.response?.data || error.message);
  });
```

{% endtab %}

{% tab title="Python" %}

```python
import requests

url = "https://api.maiagent.ai/api/v1/sql-databases/"
headers = {
    "Authorization": "Api-Key YOUR_API_KEY",
    "Content-Type": "application/json"
}

# 請求內容 (payload)
data = {
      "name": "範例名稱",
      "description": "範例字串",
      "databaseType": {},
      "databaseUrl": "範例字串",
      "includeTables": null,
      "isActive": true,
      "chatbots": [
        {
          "id": "550e8400-e29b-41d4-a716-446655440000"
        }
      ],
      "groups": [
        {
          "id": "550e8400-e29b-41d4-a716-446655440000"
        }
      ]
    }

response = requests.post(url, json=data, headers=headers)
try:
    print("成功取得回應:")
    print(response.json())
except Exception as e:
    print("請求發生錯誤:", e)
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php
require 'vendor/autoload.php';

$client = new GuzzleHttp\Client();

try {
    $response = $client->post("https://api.maiagent.ai/api/v1/sql-databases/", [
        'headers' => [
            'Authorization' => 'Api-Key YOUR_API_KEY',
            'Content-Type' => 'application/json'
        ],
        'json' => {
            "name": "範例名稱",
            "description": "範例字串",
            "databaseType": {},
            "databaseUrl": "範例字串",
            "includeTables": null,
            "isActive": true,
            "chatbots": [
                {
                    "id": "550e8400-e29b-41d4-a716-446655440000"
                }
            ],
            "groups": [
                {
                    "id": "550e8400-e29b-41d4-a716-446655440000"
                }
            ]
        }
    ]);
    
    $data = json_decode($response->getBody(), true);
    echo "成功取得回應:\n";
    print_r($data);
} catch (Exception $e) {
    echo '請求發生錯誤: ' . $e->getMessage();
}
?>
```

{% endtab %}
{% endtabs %}

#### 回應內容

**狀態碼: 201**

**回應結構範例**

```typescript
{
  "id": string (uuid)
  "name": string // Display name for this database connection
  "description"?: string // Description of the database and its purpose (非必填)
  "databaseType":  // Type of database: PostgreSQL, MySQL, MSSQL, Oracle, or MaiAgent

* `postgresql` - PostgreSQL
* `mysql` - MySQL
* `maiagent` - MaiAgent
* `oracle` - Oracle
* `mssql` - MSSQL
  {
  }
  "databaseUrl"?: string // Connection string for external databases. Not required for MaiAgent type as it uses the system default. (非必填)
  "includeTables"?: object // Optional list of tables to include. Format: {"tables": ["table1", "table2"]}. For MaiAgent type, this is auto-populated from uploaded files. (非必填)
  "isActive"?: boolean // When disabled, this database will not be used in Text-to-SQL queries (非必填)
  "status": 
  {
  }
  "deletedAt": string (timestamp)
  "tables": [
    {
      "id": string (uuid)
      "tableName": string // Name of the table in the database
      "description"?: string // Description of the table and its data for better Text-to-SQL understanding (非必填)
      "status": 
      {
      }
      "errorMessage": string // Error details if table creation or deletion failed
      "sourceFile": 
      {
        "id": string (uuid)
        "name": string
        "isFromKnowledgeBase": boolean // Determine if the source file originated from a knowledge base upload.

Returns True if the file was uploaded via knowledge base,
False if uploaded directly to the database.
      }
      "columns": [
        {
          "id": string (uuid)
          "columnName": string
          "columnType"?: string // Data type of the column (e.g., VARCHAR, INTEGER, TIMESTAMP) (非必填)
          "description"?: string // Description of the column for better Text-to-SQL understanding (非必填)
          "isPrimaryKey"?: boolean // 非必填
          "isNullable"?: boolean // 非必填
          "createdAt": string (timestamp)
          "updatedAt": string (timestamp)
        }
      ]
      "createdAt": string (timestamp)
      "updatedAt": string (timestamp)
    }
  ]
  "chatbots": [
    {
      "id": string (uuid)
      "name": string
    }
  ]
  "groups": [
    {
      "id": string (uuid)
      "name": string
    }
  ]
  "canUpdate": boolean // Return whether the current user can update this resource.
  "canDelete": boolean // Return whether the current user can delete this resource.
  "createdAt": string (timestamp)
  "updatedAt": string (timestamp)
}
```

**回應範例值**

```json
{
  "id": "550e8400-e29b-41d4-a716-446655440000",
  "name": "回應字串",
  "description": "回應字串",
  "databaseType": {},
  "databaseUrl": "回應字串",
  "includeTables": null,
  "isActive": false,
  "status": {},
  "deletedAt": "回應字串",
  "tables": [
    {
      "id": "550e8400-e29b-41d4-a716-446655440000",
      "tableName": "回應字串",
      "description": "回應字串",
      "status": {},
      "errorMessage": "回應字串",
      "sourceFile": {
        "id": "550e8400-e29b-41d4-a716-446655440000",
        "name": "回應字串",
        "isFromKnowledgeBase": false
      },
      "columns": [
        {
          "id": "550e8400-e29b-41d4-a716-446655440000",
          "columnName": "回應字串",
          "columnType": "回應字串",
          "description": "回應字串",
          "isPrimaryKey": false,
          "isNullable": false,
          "createdAt": "回應字串",
          "updatedAt": "回應字串"
        }
      ],
      "createdAt": "回應字串",
      "updatedAt": "回應字串"
    }
  ],
  "chatbots": [
    {
      "id": "550e8400-e29b-41d4-a716-446655440000",
      "name": "回應字串"
    }
  ],
  "groups": [
    {
      "id": "550e8400-e29b-41d4-a716-446655440000",
      "name": "回應字串"
    }
  ],
  "canUpdate": false,
  "canDelete": false,
  "createdAt": "回應字串",
  "updatedAt": "回應字串"
}
```

***

### 列出 SQL 資料庫 <a href="#sql" id="sql"></a>

GET `/api/sql-databases/`

#### 參數

| 參數名稱           | 必填 | 類型      | 說明                                                                                                                                                                              |
| -------------- | -- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `databaseType` | ❌  | string  | Type of database: PostgreSQL, MySQL, MSSQL, Oracle, or MaiAgent \`postgresql\`: PostgreSQL ; \`mysql\`: MySQL ; \`maiagent\`: MaiAgent ; \`oracle\`: Oracle ; \`mssql\`: MSSQL; |
| `isActive`     | ❌  | boolean |                                                                                                                                                                                 |
| `isExternal`   | ❌  | boolean |                                                                                                                                                                                 |
| `page`         | ❌  | integer | A page number within the paginated result set.                                                                                                                                  |
| `pageSize`     | ❌  | integer | Number of results to return per page.                                                                                                                                           |
| `query`        | ❌  | string  |                                                                                                                                                                                 |

#### 程式碼範例

{% tabs %}
{% tab title="Shell/Bash" %}

```bash
# 呼叫 API 示例 (Shell)
curl -X GET "https://api.maiagent.ai/api/sql-databases/?databaseType=maiagent&isActive=true&isExternal=true&page=1&pageSize=1&query=example" \
  -H "Authorization: Api-Key YOUR_API_KEY"

# 請確認在執行前替換 YOUR_API_KEY 並核對請求資料。
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
const axios = require('axios');

// 設定請求標頭
const config = {
  headers: {
    'Authorization': 'Api-Key YOUR_API_KEY'
  }
};

axios.get("https://api.maiagent.ai/api/sql-databases/?databaseType=maiagent&isActive=true&isExternal=true&page=1&pageSize=1&query=example", config)
  .then(response => {
    console.log('成功取得回應:');
    console.log(response.data);
  })
  .catch(error => {
    console.error('請求發生錯誤:');
    console.error(error.response?.data || error.message);
  });
```

{% endtab %}

{% tab title="Python" %}

```python
import requests

url = "https://api.maiagent.ai/api/sql-databases/?databaseType=maiagent&isActive=true&isExternal=true&page=1&pageSize=1&query=example"
headers = {
    "Authorization": "Api-Key YOUR_API_KEY"
}


response = requests.get(url, headers=headers)
try:
    print("成功取得回應:")
    print(response.json())
except Exception as e:
    print("請求發生錯誤:", e)
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php
require 'vendor/autoload.php';

$client = new GuzzleHttp\Client();

try {
    $response = $client->get("https://api.maiagent.ai/api/sql-databases/?databaseType=maiagent&isActive=true&isExternal=true&page=1&pageSize=1&query=example", [
        'headers' => [
            'Authorization' => 'Api-Key YOUR_API_KEY'
        ]
    ]);
    
    $data = json_decode($response->getBody(), true);
    echo "成功取得回應:\n";
    print_r($data);
} catch (Exception $e) {
    echo '請求發生錯誤: ' . $e->getMessage();
}
?>
```

{% endtab %}
{% endtabs %}

#### 回應內容

**狀態碼: 200**

**回應結構範例**

```typescript
{
  "count": integer
  "next"?: string (uri) // 非必填
  "previous"?: string (uri) // 非必填
  "results": [
    {
      "id": string (uuid)
      "name": string // Display name for this database connection
      "description"?: string // Description of the database and its purpose (非必填)
      "databaseType":  // Type of database: PostgreSQL, MySQL, MSSQL, Oracle, or MaiAgent

* `postgresql` - PostgreSQL
* `mysql` - MySQL
* `maiagent` - MaiAgent
* `oracle` - Oracle
* `mssql` - MSSQL
      {
      }
      "databaseUrl"?: string // Connection string for external databases. Not required for MaiAgent type as it uses the system default. (非必填)
      "includeTables"?: object // Optional list of tables to include. Format: {"tables": ["table1", "table2"]}. For MaiAgent type, this is auto-populated from uploaded files. (非必填)
      "isActive"?: boolean // When disabled, this database will not be used in Text-to-SQL queries (非必填)
      "status": 
      {
      }
      "deletedAt": string (timestamp)
      "tables": [
        {
          "id": string (uuid)
          "tableName": string // Name of the table in the database
          "description"?: string // Description of the table and its data for better Text-to-SQL understanding (非必填)
          "status": 
          {
          }
          "errorMessage": string // Error details if table creation or deletion failed
          "sourceFile": 
          {
            "id": string (uuid)
            "name": string
            "isFromKnowledgeBase": boolean // Determine if the source file originated from a knowledge base upload.

Returns True if the file was uploaded via knowledge base,
False if uploaded directly to the database.
          }
          "columns": [
            {
              "id": string (uuid)
              "columnName": string
              "columnType"?: string // Data type of the column (e.g., VARCHAR, INTEGER, TIMESTAMP) (非必填)
              "description"?: string // Description of the column for better Text-to-SQL understanding (非必填)
              "isPrimaryKey"?: boolean // 非必填
              "isNullable"?: boolean // 非必填
              "createdAt": string (timestamp)
              "updatedAt": string (timestamp)
            }
          ]
          "createdAt": string (timestamp)
          "updatedAt": string (timestamp)
        }
      ]
      "chatbots": [
        {
          "id": string (uuid)
          "name": string
        }
      ]
      "groups": [
        {
          "id": string (uuid)
          "name": string
        }
      ]
      "canUpdate": boolean // Return whether the current user can update this resource.
      "canDelete": boolean // Return whether the current user can delete this resource.
      "createdAt": string (timestamp)
      "updatedAt": string (timestamp)
    }
  ]
}
```

**回應範例值**

```json
{
  "count": 123,
  "next": "http://api.example.org/accounts/?page=4",
  "previous": "http://api.example.org/accounts/?page=2",
  "results": [
    {
      "id": "550e8400-e29b-41d4-a716-446655440000",
      "name": "回應字串",
      "description": "回應字串",
      "databaseType": {},
      "databaseUrl": "回應字串",
      "includeTables": null,
      "isActive": false,
      "status": {},
      "deletedAt": "回應字串",
      "tables": [
        {
          "id": "550e8400-e29b-41d4-a716-446655440000",
          "tableName": "回應字串",
          "description": "回應字串",
          "status": {},
          "errorMessage": "回應字串",
          "sourceFile": {
            "id": "550e8400-e29b-41d4-a716-446655440000",
            "name": "回應字串",
            "isFromKnowledgeBase": false
          },
          "columns": [
            {
              "id": "550e8400-e29b-41d4-a716-446655440000",
              "columnName": "回應字串",
              "columnType": "回應字串",
              "description": "回應字串",
              "isPrimaryKey": false,
              "isNullable": false,
              "createdAt": "回應字串",
              "updatedAt": "回應字串"
            }
          ],
          "createdAt": "回應字串",
          "updatedAt": "回應字串"
        }
      ],
      "chatbots": [
        {
          "id": "550e8400-e29b-41d4-a716-446655440000",
          "name": "回應字串"
        }
      ],
      "groups": [
        {
          "id": "550e8400-e29b-41d4-a716-446655440000",
          "name": "回應字串"
        }
      ],
      "canUpdate": false,
      "canDelete": false,
      "createdAt": "回應字串",
      "updatedAt": "回應字串"
    }
  ]
}
```

***

### 列出 SQL 資料庫 <a href="#sql" id="sql"></a>

GET `/api/v1/sql-databases/`

#### 參數

| 參數名稱           | 必填 | 類型      | 說明                                                                                                                                                                              |
| -------------- | -- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `databaseType` | ❌  | string  | Type of database: PostgreSQL, MySQL, MSSQL, Oracle, or MaiAgent \`postgresql\`: PostgreSQL ; \`mysql\`: MySQL ; \`maiagent\`: MaiAgent ; \`oracle\`: Oracle ; \`mssql\`: MSSQL; |
| `isActive`     | ❌  | boolean |                                                                                                                                                                                 |
| `isExternal`   | ❌  | boolean |                                                                                                                                                                                 |
| `page`         | ❌  | integer | A page number within the paginated result set.                                                                                                                                  |
| `pageSize`     | ❌  | integer | Number of results to return per page.                                                                                                                                           |
| `query`        | ❌  | string  |                                                                                                                                                                                 |

#### 程式碼範例

{% tabs %}
{% tab title="Shell/Bash" %}

```bash
# 呼叫 API 示例 (Shell)
curl -X GET "https://api.maiagent.ai/api/v1/sql-databases/?databaseType=maiagent&isActive=true&isExternal=true&page=1&pageSize=1&query=example" \
  -H "Authorization: Api-Key YOUR_API_KEY"

# 請確認在執行前替換 YOUR_API_KEY 並核對請求資料。
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
const axios = require('axios');

// 設定請求標頭
const config = {
  headers: {
    'Authorization': 'Api-Key YOUR_API_KEY'
  }
};

axios.get("https://api.maiagent.ai/api/v1/sql-databases/?databaseType=maiagent&isActive=true&isExternal=true&page=1&pageSize=1&query=example", config)
  .then(response => {
    console.log('成功取得回應:');
    console.log(response.data);
  })
  .catch(error => {
    console.error('請求發生錯誤:');
    console.error(error.response?.data || error.message);
  });
```

{% endtab %}

{% tab title="Python" %}

```python
import requests

url = "https://api.maiagent.ai/api/v1/sql-databases/?databaseType=maiagent&isActive=true&isExternal=true&page=1&pageSize=1&query=example"
headers = {
    "Authorization": "Api-Key YOUR_API_KEY"
}


response = requests.get(url, headers=headers)
try:
    print("成功取得回應:")
    print(response.json())
except Exception as e:
    print("請求發生錯誤:", e)
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php
require 'vendor/autoload.php';

$client = new GuzzleHttp\Client();

try {
    $response = $client->get("https://api.maiagent.ai/api/v1/sql-databases/?databaseType=maiagent&isActive=true&isExternal=true&page=1&pageSize=1&query=example", [
        'headers' => [
            'Authorization' => 'Api-Key YOUR_API_KEY'
        ]
    ]);
    
    $data = json_decode($response->getBody(), true);
    echo "成功取得回應:\n";
    print_r($data);
} catch (Exception $e) {
    echo '請求發生錯誤: ' . $e->getMessage();
}
?>
```

{% endtab %}
{% endtabs %}

#### 回應內容

**狀態碼: 200**

**回應結構範例**

```typescript
{
  "count": integer
  "next"?: string (uri) // 非必填
  "previous"?: string (uri) // 非必填
  "results": [
    {
      "id": string (uuid)
      "name": string // Display name for this database connection
      "description"?: string // Description of the database and its purpose (非必填)
      "databaseType":  // Type of database: PostgreSQL, MySQL, MSSQL, Oracle, or MaiAgent

* `postgresql` - PostgreSQL
* `mysql` - MySQL
* `maiagent` - MaiAgent
* `oracle` - Oracle
* `mssql` - MSSQL
      {
      }
      "databaseUrl"?: string // Connection string for external databases. Not required for MaiAgent type as it uses the system default. (非必填)
      "includeTables"?: object // Optional list of tables to include. Format: {"tables": ["table1", "table2"]}. For MaiAgent type, this is auto-populated from uploaded files. (非必填)
      "isActive"?: boolean // When disabled, this database will not be used in Text-to-SQL queries (非必填)
      "status": 
      {
      }
      "deletedAt": string (timestamp)
      "tables": [
        {
          "id": string (uuid)
          "tableName": string // Name of the table in the database
          "description"?: string // Description of the table and its data for better Text-to-SQL understanding (非必填)
          "status": 
          {
          }
          "errorMessage": string // Error details if table creation or deletion failed
          "sourceFile": 
          {
            "id": string (uuid)
            "name": string
            "isFromKnowledgeBase": boolean // Determine if the source file originated from a knowledge base upload.

Returns True if the file was uploaded via knowledge base,
False if uploaded directly to the database.
          }
          "columns": [
            {
              "id": string (uuid)
              "columnName": string
              "columnType"?: string // Data type of the column (e.g., VARCHAR, INTEGER, TIMESTAMP) (非必填)
              "description"?: string // Description of the column for better Text-to-SQL understanding (非必填)
              "isPrimaryKey"?: boolean // 非必填
              "isNullable"?: boolean // 非必填
              "createdAt": string (timestamp)
              "updatedAt": string (timestamp)
            }
          ]
          "createdAt": string (timestamp)
          "updatedAt": string (timestamp)
        }
      ]
      "chatbots": [
        {
          "id": string (uuid)
          "name": string
        }
      ]
      "groups": [
        {
          "id": string (uuid)
          "name": string
        }
      ]
      "canUpdate": boolean // Return whether the current user can update this resource.
      "canDelete": boolean // Return whether the current user can delete this resource.
      "createdAt": string (timestamp)
      "updatedAt": string (timestamp)
    }
  ]
}
```

**回應範例值**

```json
{
  "count": 123,
  "next": "http://api.example.org/accounts/?page=4",
  "previous": "http://api.example.org/accounts/?page=2",
  "results": [
    {
      "id": "550e8400-e29b-41d4-a716-446655440000",
      "name": "回應字串",
      "description": "回應字串",
      "databaseType": {},
      "databaseUrl": "回應字串",
      "includeTables": null,
      "isActive": false,
      "status": {},
      "deletedAt": "回應字串",
      "tables": [
        {
          "id": "550e8400-e29b-41d4-a716-446655440000",
          "tableName": "回應字串",
          "description": "回應字串",
          "status": {},
          "errorMessage": "回應字串",
          "sourceFile": {
            "id": "550e8400-e29b-41d4-a716-446655440000",
            "name": "回應字串",
            "isFromKnowledgeBase": false
          },
          "columns": [
            {
              "id": "550e8400-e29b-41d4-a716-446655440000",
              "columnName": "回應字串",
              "columnType": "回應字串",
              "description": "回應字串",
              "isPrimaryKey": false,
              "isNullable": false,
              "createdAt": "回應字串",
              "updatedAt": "回應字串"
            }
          ],
          "createdAt": "回應字串",
          "updatedAt": "回應字串"
        }
      ],
      "chatbots": [
        {
          "id": "550e8400-e29b-41d4-a716-446655440000",
          "name": "回應字串"
        }
      ],
      "groups": [
        {
          "id": "550e8400-e29b-41d4-a716-446655440000",
          "name": "回應字串"
        }
      ],
      "canUpdate": false,
      "canDelete": false,
      "createdAt": "回應字串",
      "updatedAt": "回應字串"
    }
  ]
}
```

***

### 取得特定 SQL 資料庫 <a href="#sql" id="sql"></a>

GET `/api/sql-databases/{id}/`

#### 參數

| 參數名稱 | 必填 | 類型     | 說明                                           |
| ---- | -- | ------ | -------------------------------------------- |
| `id` | ✅  | string | A UUID string identifying this SQL Database. |

#### 程式碼範例

{% tabs %}
{% tab title="Shell/Bash" %}

```bash
# 呼叫 API 示例 (Shell)
curl -X GET "https://api.maiagent.ai/api/sql-databases/550e8400-e29b-41d4-a716-446655440000/" \
  -H "Authorization: Api-Key YOUR_API_KEY"

# 請確認在執行前替換 YOUR_API_KEY 並核對請求資料。
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
const axios = require('axios');

// 設定請求標頭
const config = {
  headers: {
    'Authorization': 'Api-Key YOUR_API_KEY'
  }
};

axios.get("https://api.maiagent.ai/api/sql-databases/550e8400-e29b-41d4-a716-446655440000/", config)
  .then(response => {
    console.log('成功取得回應:');
    console.log(response.data);
  })
  .catch(error => {
    console.error('請求發生錯誤:');
    console.error(error.response?.data || error.message);
  });
```

{% endtab %}

{% tab title="Python" %}

```python
import requests

url = "https://api.maiagent.ai/api/sql-databases/550e8400-e29b-41d4-a716-446655440000/"
headers = {
    "Authorization": "Api-Key YOUR_API_KEY"
}


response = requests.get(url, headers=headers)
try:
    print("成功取得回應:")
    print(response.json())
except Exception as e:
    print("請求發生錯誤:", e)
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php
require 'vendor/autoload.php';

$client = new GuzzleHttp\Client();

try {
    $response = $client->get("https://api.maiagent.ai/api/sql-databases/550e8400-e29b-41d4-a716-446655440000/", [
        'headers' => [
            'Authorization' => 'Api-Key YOUR_API_KEY'
        ]
    ]);
    
    $data = json_decode($response->getBody(), true);
    echo "成功取得回應:\n";
    print_r($data);
} catch (Exception $e) {
    echo '請求發生錯誤: ' . $e->getMessage();
}
?>
```

{% endtab %}
{% endtabs %}

#### 回應內容

**狀態碼: 200**

**回應結構範例**

```typescript
{
  "id": string (uuid)
  "name": string // Display name for this database connection
  "description"?: string // Description of the database and its purpose (非必填)
  "databaseType":  // Type of database: PostgreSQL, MySQL, MSSQL, Oracle, or MaiAgent

* `postgresql` - PostgreSQL
* `mysql` - MySQL
* `maiagent` - MaiAgent
* `oracle` - Oracle
* `mssql` - MSSQL
  {
  }
  "databaseUrl"?: string // Connection string for external databases. Not required for MaiAgent type as it uses the system default. (非必填)
  "includeTables"?: object // Optional list of tables to include. Format: {"tables": ["table1", "table2"]}. For MaiAgent type, this is auto-populated from uploaded files. (非必填)
  "isActive"?: boolean // When disabled, this database will not be used in Text-to-SQL queries (非必填)
  "status": 
  {
  }
  "deletedAt": string (timestamp)
  "tables": [
    {
      "id": string (uuid)
      "tableName": string // Name of the table in the database
      "description"?: string // Description of the table and its data for better Text-to-SQL understanding (非必填)
      "status": 
      {
      }
      "errorMessage": string // Error details if table creation or deletion failed
      "sourceFile": 
      {
        "id": string (uuid)
        "name": string
        "isFromKnowledgeBase": boolean // Determine if the source file originated from a knowledge base upload.

Returns True if the file was uploaded via knowledge base,
False if uploaded directly to the database.
      }
      "columns": [
        {
          "id": string (uuid)
          "columnName": string
          "columnType"?: string // Data type of the column (e.g., VARCHAR, INTEGER, TIMESTAMP) (非必填)
          "description"?: string // Description of the column for better Text-to-SQL understanding (非必填)
          "isPrimaryKey"?: boolean // 非必填
          "isNullable"?: boolean // 非必填
          "createdAt": string (timestamp)
          "updatedAt": string (timestamp)
        }
      ]
      "createdAt": string (timestamp)
      "updatedAt": string (timestamp)
    }
  ]
  "chatbots": [
    {
      "id": string (uuid)
      "name": string
    }
  ]
  "groups": [
    {
      "id": string (uuid)
      "name": string
    }
  ]
  "canUpdate": boolean // Return whether the current user can update this resource.
  "canDelete": boolean // Return whether the current user can delete this resource.
  "createdAt": string (timestamp)
  "updatedAt": string (timestamp)
}
```

**回應範例值**

```json
{
  "id": "550e8400-e29b-41d4-a716-446655440000",
  "name": "回應字串",
  "description": "回應字串",
  "databaseType": {},
  "databaseUrl": "回應字串",
  "includeTables": null,
  "isActive": false,
  "status": {},
  "deletedAt": "回應字串",
  "tables": [
    {
      "id": "550e8400-e29b-41d4-a716-446655440000",
      "tableName": "回應字串",
      "description": "回應字串",
      "status": {},
      "errorMessage": "回應字串",
      "sourceFile": {
        "id": "550e8400-e29b-41d4-a716-446655440000",
        "name": "回應字串",
        "isFromKnowledgeBase": false
      },
      "columns": [
        {
          "id": "550e8400-e29b-41d4-a716-446655440000",
          "columnName": "回應字串",
          "columnType": "回應字串",
          "description": "回應字串",
          "isPrimaryKey": false,
          "isNullable": false,
          "createdAt": "回應字串",
          "updatedAt": "回應字串"
        }
      ],
      "createdAt": "回應字串",
      "updatedAt": "回應字串"
    }
  ],
  "chatbots": [
    {
      "id": "550e8400-e29b-41d4-a716-446655440000",
      "name": "回應字串"
    }
  ],
  "groups": [
    {
      "id": "550e8400-e29b-41d4-a716-446655440000",
      "name": "回應字串"
    }
  ],
  "canUpdate": false,
  "canDelete": false,
  "createdAt": "回應字串",
  "updatedAt": "回應字串"
}
```

***

### 取得特定 SQL 資料庫 <a href="#sql" id="sql"></a>

GET `/api/v1/sql-databases/{id}/`

#### 參數

| 參數名稱 | 必填 | 類型     | 說明                                           |
| ---- | -- | ------ | -------------------------------------------- |
| `id` | ✅  | string | A UUID string identifying this SQL Database. |

#### 程式碼範例

{% tabs %}
{% tab title="Shell/Bash" %}

```bash
# 呼叫 API 示例 (Shell)
curl -X GET "https://api.maiagent.ai/api/v1/sql-databases/550e8400-e29b-41d4-a716-446655440000/" \
  -H "Authorization: Api-Key YOUR_API_KEY"

# 請確認在執行前替換 YOUR_API_KEY 並核對請求資料。
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
const axios = require('axios');

// 設定請求標頭
const config = {
  headers: {
    'Authorization': 'Api-Key YOUR_API_KEY'
  }
};

axios.get("https://api.maiagent.ai/api/v1/sql-databases/550e8400-e29b-41d4-a716-446655440000/", config)
  .then(response => {
    console.log('成功取得回應:');
    console.log(response.data);
  })
  .catch(error => {
    console.error('請求發生錯誤:');
    console.error(error.response?.data || error.message);
  });
```

{% endtab %}

{% tab title="Python" %}

```python
import requests

url = "https://api.maiagent.ai/api/v1/sql-databases/550e8400-e29b-41d4-a716-446655440000/"
headers = {
    "Authorization": "Api-Key YOUR_API_KEY"
}


response = requests.get(url, headers=headers)
try:
    print("成功取得回應:")
    print(response.json())
except Exception as e:
    print("請求發生錯誤:", e)
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php
require 'vendor/autoload.php';

$client = new GuzzleHttp\Client();

try {
    $response = $client->get("https://api.maiagent.ai/api/v1/sql-databases/550e8400-e29b-41d4-a716-446655440000/", [
        'headers' => [
            'Authorization' => 'Api-Key YOUR_API_KEY'
        ]
    ]);
    
    $data = json_decode($response->getBody(), true);
    echo "成功取得回應:\n";
    print_r($data);
} catch (Exception $e) {
    echo '請求發生錯誤: ' . $e->getMessage();
}
?>
```

{% endtab %}
{% endtabs %}

#### 回應內容

**狀態碼: 200**

**回應結構範例**

```typescript
{
  "id": string (uuid)
  "name": string // Display name for this database connection
  "description"?: string // Description of the database and its purpose (非必填)
  "databaseType":  // Type of database: PostgreSQL, MySQL, MSSQL, Oracle, or MaiAgent

* `postgresql` - PostgreSQL
* `mysql` - MySQL
* `maiagent` - MaiAgent
* `oracle` - Oracle
* `mssql` - MSSQL
  {
  }
  "databaseUrl"?: string // Connection string for external databases. Not required for MaiAgent type as it uses the system default. (非必填)
  "includeTables"?: object // Optional list of tables to include. Format: {"tables": ["table1", "table2"]}. For MaiAgent type, this is auto-populated from uploaded files. (非必填)
  "isActive"?: boolean // When disabled, this database will not be used in Text-to-SQL queries (非必填)
  "status": 
  {
  }
  "deletedAt": string (timestamp)
  "tables": [
    {
      "id": string (uuid)
      "tableName": string // Name of the table in the database
      "description"?: string // Description of the table and its data for better Text-to-SQL understanding (非必填)
      "status": 
      {
      }
      "errorMessage": string // Error details if table creation or deletion failed
      "sourceFile": 
      {
        "id": string (uuid)
        "name": string
        "isFromKnowledgeBase": boolean // Determine if the source file originated from a knowledge base upload.

Returns True if the file was uploaded via knowledge base,
False if uploaded directly to the database.
      }
      "columns": [
        {
          "id": string (uuid)
          "columnName": string
          "columnType"?: string // Data type of the column (e.g., VARCHAR, INTEGER, TIMESTAMP) (非必填)
          "description"?: string // Description of the column for better Text-to-SQL understanding (非必填)
          "isPrimaryKey"?: boolean // 非必填
          "isNullable"?: boolean // 非必填
          "createdAt": string (timestamp)
          "updatedAt": string (timestamp)
        }
      ]
      "createdAt": string (timestamp)
      "updatedAt": string (timestamp)
    }
  ]
  "chatbots": [
    {
      "id": string (uuid)
      "name": string
    }
  ]
  "groups": [
    {
      "id": string (uuid)
      "name": string
    }
  ]
  "canUpdate": boolean // Return whether the current user can update this resource.
  "canDelete": boolean // Return whether the current user can delete this resource.
  "createdAt": string (timestamp)
  "updatedAt": string (timestamp)
}
```

**回應範例值**

```json
{
  "id": "550e8400-e29b-41d4-a716-446655440000",
  "name": "回應字串",
  "description": "回應字串",
  "databaseType": {},
  "databaseUrl": "回應字串",
  "includeTables": null,
  "isActive": false,
  "status": {},
  "deletedAt": "回應字串",
  "tables": [
    {
      "id": "550e8400-e29b-41d4-a716-446655440000",
      "tableName": "回應字串",
      "description": "回應字串",
      "status": {},
      "errorMessage": "回應字串",
      "sourceFile": {
        "id": "550e8400-e29b-41d4-a716-446655440000",
        "name": "回應字串",
        "isFromKnowledgeBase": false
      },
      "columns": [
        {
          "id": "550e8400-e29b-41d4-a716-446655440000",
          "columnName": "回應字串",
          "columnType": "回應字串",
          "description": "回應字串",
          "isPrimaryKey": false,
          "isNullable": false,
          "createdAt": "回應字串",
          "updatedAt": "回應字串"
        }
      ],
      "createdAt": "回應字串",
      "updatedAt": "回應字串"
    }
  ],
  "chatbots": [
    {
      "id": "550e8400-e29b-41d4-a716-446655440000",
      "name": "回應字串"
    }
  ],
  "groups": [
    {
      "id": "550e8400-e29b-41d4-a716-446655440000",
      "name": "回應字串"
    }
  ],
  "canUpdate": false,
  "canDelete": false,
  "createdAt": "回應字串",
  "updatedAt": "回應字串"
}
```

***

### 更新 SQL 資料庫 <a href="#sql" id="sql"></a>

PUT `/api/sql-databases/{id}/`

#### 參數

| 參數名稱 | 必填 | 類型     | 說明                                           |
| ---- | -- | ------ | -------------------------------------------- |
| `id` | ✅  | string | A UUID string identifying this SQL Database. |

#### 請求內容

**請求參數**

| 欄位            | 類型             | 必填 | 說明                                                                                                                                            |
| ------------- | -------------- | -- | --------------------------------------------------------------------------------------------------------------------------------------------- |
| name          | string         | 是  | Display name for this database connection                                                                                                     |
| description   | string         | 否  | Description of the database and its purpose                                                                                                   |
| databaseUrl   | string         | 否  | Connection string for external databases. Not required for MaiAgent type as it uses the system default.                                       |
| includeTables | object         | 否  | Optional list of tables to include. Format: {"tables": \["table1", "table2"]}. For MaiAgent type, this is auto-populated from uploaded files. |
| isActive      | boolean        | 否  | When disabled, this database will not be used in Text-to-SQL queries                                                                          |
| chatbots      | array\[IdName] | 否  |                                                                                                                                               |
| groups        | array\[IdName] | 否  |                                                                                                                                               |

**請求結構範例**

```typescript
{
  "name": string // Display name for this database connection
  "description"?: string // Description of the database and its purpose (非必填)
  "databaseUrl"?: string // Connection string for external databases. Not required for MaiAgent type as it uses the system default. (非必填)
  "includeTables"?: object // Optional list of tables to include. Format: {"tables": ["table1", "table2"]}. For MaiAgent type, this is auto-populated from uploaded files. (非必填)
  "isActive"?: boolean // When disabled, this database will not be used in Text-to-SQL queries (非必填)
  "chatbots"?: [ // 非必填
    {
      "id": string (uuid)
    }
  ]
  "groups"?: [ // 非必填
    {
      "id": string (uuid)
    }
  ]
}
```

**請求範例值**

```json
{
  "name": "範例名稱",
  "description": "範例字串",
  "databaseUrl": "範例字串",
  "includeTables": null,
  "isActive": true,
  "chatbots": [
    {
      "id": "550e8400-e29b-41d4-a716-446655440000"
    }
  ],
  "groups": [
    {
      "id": "550e8400-e29b-41d4-a716-446655440000"
    }
  ]
}
```

#### 程式碼範例

{% tabs %}
{% tab title="Shell/Bash" %}

```bash
# 呼叫 API 示例 (Shell)
curl -X PUT "https://api.maiagent.ai/api/sql-databases/550e8400-e29b-41d4-a716-446655440000/" \
  -H "Authorization: Api-Key YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "範例名稱",
    "description": "範例字串",
    "databaseUrl": "範例字串",
    "includeTables": null,
    "isActive": true,
    "chatbots": [
      {
        "id": "550e8400-e29b-41d4-a716-446655440000"
      }
    ],
    "groups": [
      {
        "id": "550e8400-e29b-41d4-a716-446655440000"
      }
    ]
  }'

# 請確認在執行前替換 YOUR_API_KEY 並核對請求資料。
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
const axios = require('axios');

// 設定請求標頭
const config = {
  headers: {
    'Authorization': 'Api-Key YOUR_API_KEY',
    'Content-Type': 'application/json'
  }
};

// 請求內容 (payload)
const data = {
    "name": "範例名稱",
    "description": "範例字串",
    "databaseUrl": "範例字串",
    "includeTables": null,
    "isActive": true,
    "chatbots": [
      {
        "id": "550e8400-e29b-41d4-a716-446655440000"
      }
    ],
    "groups": [
      {
        "id": "550e8400-e29b-41d4-a716-446655440000"
      }
    ]
  };

axios.put("https://api.maiagent.ai/api/sql-databases/550e8400-e29b-41d4-a716-446655440000/", data, config)
  .then(response => {
    console.log('成功取得回應:');
    console.log(response.data);
  })
  .catch(error => {
    console.error('請求發生錯誤:');
    console.error(error.response?.data || error.message);
  });
```

{% endtab %}

{% tab title="Python" %}

```python
import requests

url = "https://api.maiagent.ai/api/sql-databases/550e8400-e29b-41d4-a716-446655440000/"
headers = {
    "Authorization": "Api-Key YOUR_API_KEY",
    "Content-Type": "application/json"
}

# 請求內容 (payload)
data = {
      "name": "範例名稱",
      "description": "範例字串",
      "databaseUrl": "範例字串",
      "includeTables": null,
      "isActive": true,
      "chatbots": [
        {
          "id": "550e8400-e29b-41d4-a716-446655440000"
        }
      ],
      "groups": [
        {
          "id": "550e8400-e29b-41d4-a716-446655440000"
        }
      ]
    }

response = requests.put(url, json=data, headers=headers)
try:
    print("成功取得回應:")
    print(response.json())
except Exception as e:
    print("請求發生錯誤:", e)
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php
require 'vendor/autoload.php';

$client = new GuzzleHttp\Client();

try {
    $response = $client->put("https://api.maiagent.ai/api/sql-databases/550e8400-e29b-41d4-a716-446655440000/", [
        'headers' => [
            'Authorization' => 'Api-Key YOUR_API_KEY',
            'Content-Type' => 'application/json'
        ],
        'json' => {
            "name": "範例名稱",
            "description": "範例字串",
            "databaseUrl": "範例字串",
            "includeTables": null,
            "isActive": true,
            "chatbots": [
                {
                    "id": "550e8400-e29b-41d4-a716-446655440000"
                }
            ],
            "groups": [
                {
                    "id": "550e8400-e29b-41d4-a716-446655440000"
                }
            ]
        }
    ]);
    
    $data = json_decode($response->getBody(), true);
    echo "成功取得回應:\n";
    print_r($data);
} catch (Exception $e) {
    echo '請求發生錯誤: ' . $e->getMessage();
}
?>
```

{% endtab %}
{% endtabs %}

#### 回應內容

**狀態碼: 200**

**回應結構範例**

```typescript
{
  "id": string (uuid)
  "name": string // Display name for this database connection
  "description"?: string // Description of the database and its purpose (非必填)
  "databaseType":  // Type of database: PostgreSQL, MySQL, MSSQL, Oracle, or MaiAgent

* `postgresql` - PostgreSQL
* `mysql` - MySQL
* `maiagent` - MaiAgent
* `oracle` - Oracle
* `mssql` - MSSQL
  {
  }
  "databaseUrl"?: string // Connection string for external databases. Not required for MaiAgent type as it uses the system default. (非必填)
  "includeTables"?: object // Optional list of tables to include. Format: {"tables": ["table1", "table2"]}. For MaiAgent type, this is auto-populated from uploaded files. (非必填)
  "isActive"?: boolean // When disabled, this database will not be used in Text-to-SQL queries (非必填)
  "status": 
  {
  }
  "deletedAt": string (timestamp)
  "tables": [
    {
      "id": string (uuid)
      "tableName": string // Name of the table in the database
      "description"?: string // Description of the table and its data for better Text-to-SQL understanding (非必填)
      "status": 
      {
      }
      "errorMessage": string // Error details if table creation or deletion failed
      "sourceFile": 
      {
        "id": string (uuid)
        "name": string
        "isFromKnowledgeBase": boolean // Determine if the source file originated from a knowledge base upload.

Returns True if the file was uploaded via knowledge base,
False if uploaded directly to the database.
      }
      "columns": [
        {
          "id": string (uuid)
          "columnName": string
          "columnType"?: string // Data type of the column (e.g., VARCHAR, INTEGER, TIMESTAMP) (非必填)
          "description"?: string // Description of the column for better Text-to-SQL understanding (非必填)
          "isPrimaryKey"?: boolean // 非必填
          "isNullable"?: boolean // 非必填
          "createdAt": string (timestamp)
          "updatedAt": string (timestamp)
        }
      ]
      "createdAt": string (timestamp)
      "updatedAt": string (timestamp)
    }
  ]
  "chatbots": [
    {
      "id": string (uuid)
      "name": string
    }
  ]
  "groups": [
    {
      "id": string (uuid)
      "name": string
    }
  ]
  "canUpdate": boolean // Return whether the current user can update this resource.
  "canDelete": boolean // Return whether the current user can delete this resource.
  "createdAt": string (timestamp)
  "updatedAt": string (timestamp)
}
```

**回應範例值**

```json
{
  "id": "550e8400-e29b-41d4-a716-446655440000",
  "name": "回應字串",
  "description": "回應字串",
  "databaseType": {},
  "databaseUrl": "回應字串",
  "includeTables": null,
  "isActive": false,
  "status": {},
  "deletedAt": "回應字串",
  "tables": [
    {
      "id": "550e8400-e29b-41d4-a716-446655440000",
      "tableName": "回應字串",
      "description": "回應字串",
      "status": {},
      "errorMessage": "回應字串",
      "sourceFile": {
        "id": "550e8400-e29b-41d4-a716-446655440000",
        "name": "回應字串",
        "isFromKnowledgeBase": false
      },
      "columns": [
        {
          "id": "550e8400-e29b-41d4-a716-446655440000",
          "columnName": "回應字串",
          "columnType": "回應字串",
          "description": "回應字串",
          "isPrimaryKey": false,
          "isNullable": false,
          "createdAt": "回應字串",
          "updatedAt": "回應字串"
        }
      ],
      "createdAt": "回應字串",
      "updatedAt": "回應字串"
    }
  ],
  "chatbots": [
    {
      "id": "550e8400-e29b-41d4-a716-446655440000",
      "name": "回應字串"
    }
  ],
  "groups": [
    {
      "id": "550e8400-e29b-41d4-a716-446655440000",
      "name": "回應字串"
    }
  ],
  "canUpdate": false,
  "canDelete": false,
  "createdAt": "回應字串",
  "updatedAt": "回應字串"
}
```

***

### 更新 SQL 資料庫 <a href="#sql" id="sql"></a>

PUT `/api/v1/sql-databases/{id}/`

#### 參數

| 參數名稱 | 必填 | 類型     | 說明                                           |
| ---- | -- | ------ | -------------------------------------------- |
| `id` | ✅  | string | A UUID string identifying this SQL Database. |

#### 請求內容

**請求參數**

| 欄位            | 類型             | 必填 | 說明                                                                                                                                            |
| ------------- | -------------- | -- | --------------------------------------------------------------------------------------------------------------------------------------------- |
| name          | string         | 是  | Display name for this database connection                                                                                                     |
| description   | string         | 否  | Description of the database and its purpose                                                                                                   |
| databaseUrl   | string         | 否  | Connection string for external databases. Not required for MaiAgent type as it uses the system default.                                       |
| includeTables | object         | 否  | Optional list of tables to include. Format: {"tables": \["table1", "table2"]}. For MaiAgent type, this is auto-populated from uploaded files. |
| isActive      | boolean        | 否  | When disabled, this database will not be used in Text-to-SQL queries                                                                          |
| chatbots      | array\[IdName] | 否  |                                                                                                                                               |
| groups        | array\[IdName] | 否  |                                                                                                                                               |

**請求結構範例**

```typescript
{
  "name": string // Display name for this database connection
  "description"?: string // Description of the database and its purpose (非必填)
  "databaseUrl"?: string // Connection string for external databases. Not required for MaiAgent type as it uses the system default. (非必填)
  "includeTables"?: object // Optional list of tables to include. Format: {"tables": ["table1", "table2"]}. For MaiAgent type, this is auto-populated from uploaded files. (非必填)
  "isActive"?: boolean // When disabled, this database will not be used in Text-to-SQL queries (非必填)
  "chatbots"?: [ // 非必填
    {
      "id": string (uuid)
    }
  ]
  "groups"?: [ // 非必填
    {
      "id": string (uuid)
    }
  ]
}
```

**請求範例值**

```json
{
  "name": "範例名稱",
  "description": "範例字串",
  "databaseUrl": "範例字串",
  "includeTables": null,
  "isActive": true,
  "chatbots": [
    {
      "id": "550e8400-e29b-41d4-a716-446655440000"
    }
  ],
  "groups": [
    {
      "id": "550e8400-e29b-41d4-a716-446655440000"
    }
  ]
}
```

#### 程式碼範例

{% tabs %}
{% tab title="Shell/Bash" %}

```bash
# 呼叫 API 示例 (Shell)
curl -X PUT "https://api.maiagent.ai/api/v1/sql-databases/550e8400-e29b-41d4-a716-446655440000/" \
  -H "Authorization: Api-Key YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "範例名稱",
    "description": "範例字串",
    "databaseUrl": "範例字串",
    "includeTables": null,
    "isActive": true,
    "chatbots": [
      {
        "id": "550e8400-e29b-41d4-a716-446655440000"
      }
    ],
    "groups": [
      {
        "id": "550e8400-e29b-41d4-a716-446655440000"
      }
    ]
  }'

# 請確認在執行前替換 YOUR_API_KEY 並核對請求資料。
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
const axios = require('axios');

// 設定請求標頭
const config = {
  headers: {
    'Authorization': 'Api-Key YOUR_API_KEY',
    'Content-Type': 'application/json'
  }
};

// 請求內容 (payload)
const data = {
    "name": "範例名稱",
    "description": "範例字串",
    "databaseUrl": "範例字串",
    "includeTables": null,
    "isActive": true,
    "chatbots": [
      {
        "id": "550e8400-e29b-41d4-a716-446655440000"
      }
    ],
    "groups": [
      {
        "id": "550e8400-e29b-41d4-a716-446655440000"
      }
    ]
  };

axios.put("https://api.maiagent.ai/api/v1/sql-databases/550e8400-e29b-41d4-a716-446655440000/", data, config)
  .then(response => {
    console.log('成功取得回應:');
    console.log(response.data);
  })
  .catch(error => {
    console.error('請求發生錯誤:');
    console.error(error.response?.data || error.message);
  });
```

{% endtab %}

{% tab title="Python" %}

```python
import requests

url = "https://api.maiagent.ai/api/v1/sql-databases/550e8400-e29b-41d4-a716-446655440000/"
headers = {
    "Authorization": "Api-Key YOUR_API_KEY",
    "Content-Type": "application/json"
}

# 請求內容 (payload)
data = {
      "name": "範例名稱",
      "description": "範例字串",
      "databaseUrl": "範例字串",
      "includeTables": null,
      "isActive": true,
      "chatbots": [
        {
          "id": "550e8400-e29b-41d4-a716-446655440000"
        }
      ],
      "groups": [
        {
          "id": "550e8400-e29b-41d4-a716-446655440000"
        }
      ]
    }

response = requests.put(url, json=data, headers=headers)
try:
    print("成功取得回應:")
    print(response.json())
except Exception as e:
    print("請求發生錯誤:", e)
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php
require 'vendor/autoload.php';

$client = new GuzzleHttp\Client();

try {
    $response = $client->put("https://api.maiagent.ai/api/v1/sql-databases/550e8400-e29b-41d4-a716-446655440000/", [
        'headers' => [
            'Authorization' => 'Api-Key YOUR_API_KEY',
            'Content-Type' => 'application/json'
        ],
        'json' => {
            "name": "範例名稱",
            "description": "範例字串",
            "databaseUrl": "範例字串",
            "includeTables": null,
            "isActive": true,
            "chatbots": [
                {
                    "id": "550e8400-e29b-41d4-a716-446655440000"
                }
            ],
            "groups": [
                {
                    "id": "550e8400-e29b-41d4-a716-446655440000"
                }
            ]
        }
    ]);
    
    $data = json_decode($response->getBody(), true);
    echo "成功取得回應:\n";
    print_r($data);
} catch (Exception $e) {
    echo '請求發生錯誤: ' . $e->getMessage();
}
?>
```

{% endtab %}
{% endtabs %}

#### 回應內容

**狀態碼: 200**

**回應結構範例**

```typescript
{
  "id": string (uuid)
  "name": string // Display name for this database connection
  "description"?: string // Description of the database and its purpose (非必填)
  "databaseType":  // Type of database: PostgreSQL, MySQL, MSSQL, Oracle, or MaiAgent

* `postgresql` - PostgreSQL
* `mysql` - MySQL
* `maiagent` - MaiAgent
* `oracle` - Oracle
* `mssql` - MSSQL
  {
  }
  "databaseUrl"?: string // Connection string for external databases. Not required for MaiAgent type as it uses the system default. (非必填)
  "includeTables"?: object // Optional list of tables to include. Format: {"tables": ["table1", "table2"]}. For MaiAgent type, this is auto-populated from uploaded files. (非必填)
  "isActive"?: boolean // When disabled, this database will not be used in Text-to-SQL queries (非必填)
  "status": 
  {
  }
  "deletedAt": string (timestamp)
  "tables": [
    {
      "id": string (uuid)
      "tableName": string // Name of the table in the database
      "description"?: string // Description of the table and its data for better Text-to-SQL understanding (非必填)
      "status": 
      {
      }
      "errorMessage": string // Error details if table creation or deletion failed
      "sourceFile": 
      {
        "id": string (uuid)
        "name": string
        "isFromKnowledgeBase": boolean // Determine if the source file originated from a knowledge base upload.

Returns True if the file was uploaded via knowledge base,
False if uploaded directly to the database.
      }
      "columns": [
        {
          "id": string (uuid)
          "columnName": string
          "columnType"?: string // Data type of the column (e.g., VARCHAR, INTEGER, TIMESTAMP) (非必填)
          "description"?: string // Description of the column for better Text-to-SQL understanding (非必填)
          "isPrimaryKey"?: boolean // 非必填
          "isNullable"?: boolean // 非必填
          "createdAt": string (timestamp)
          "updatedAt": string (timestamp)
        }
      ]
      "createdAt": string (timestamp)
      "updatedAt": string (timestamp)
    }
  ]
  "chatbots": [
    {
      "id": string (uuid)
      "name": string
    }
  ]
  "groups": [
    {
      "id": string (uuid)
      "name": string
    }
  ]
  "canUpdate": boolean // Return whether the current user can update this resource.
  "canDelete": boolean // Return whether the current user can delete this resource.
  "createdAt": string (timestamp)
  "updatedAt": string (timestamp)
}
```

**回應範例值**

```json
{
  "id": "550e8400-e29b-41d4-a716-446655440000",
  "name": "回應字串",
  "description": "回應字串",
  "databaseType": {},
  "databaseUrl": "回應字串",
  "includeTables": null,
  "isActive": false,
  "status": {},
  "deletedAt": "回應字串",
  "tables": [
    {
      "id": "550e8400-e29b-41d4-a716-446655440000",
      "tableName": "回應字串",
      "description": "回應字串",
      "status": {},
      "errorMessage": "回應字串",
      "sourceFile": {
        "id": "550e8400-e29b-41d4-a716-446655440000",
        "name": "回應字串",
        "isFromKnowledgeBase": false
      },
      "columns": [
        {
          "id": "550e8400-e29b-41d4-a716-446655440000",
          "columnName": "回應字串",
          "columnType": "回應字串",
          "description": "回應字串",
          "isPrimaryKey": false,
          "isNullable": false,
          "createdAt": "回應字串",
          "updatedAt": "回應字串"
        }
      ],
      "createdAt": "回應字串",
      "updatedAt": "回應字串"
    }
  ],
  "chatbots": [
    {
      "id": "550e8400-e29b-41d4-a716-446655440000",
      "name": "回應字串"
    }
  ],
  "groups": [
    {
      "id": "550e8400-e29b-41d4-a716-446655440000",
      "name": "回應字串"
    }
  ],
  "canUpdate": false,
  "canDelete": false,
  "createdAt": "回應字串",
  "updatedAt": "回應字串"
}
```

***

### 部分更新 SQL 資料庫 <a href="#sql" id="sql"></a>

PATCH `/api/sql-databases/{id}/`

#### 參數

| 參數名稱 | 必填 | 類型     | 說明                                           |
| ---- | -- | ------ | -------------------------------------------- |
| `id` | ✅  | string | A UUID string identifying this SQL Database. |

#### 請求內容

**請求參數**

| 欄位            | 類型             | 必填 | 說明                                                                                                                                            |
| ------------- | -------------- | -- | --------------------------------------------------------------------------------------------------------------------------------------------- |
| name          | string         | 否  | Display name for this database connection                                                                                                     |
| description   | string         | 否  | Description of the database and its purpose                                                                                                   |
| databaseUrl   | string         | 否  | Connection string for external databases. Not required for MaiAgent type as it uses the system default.                                       |
| includeTables | object         | 否  | Optional list of tables to include. Format: {"tables": \["table1", "table2"]}. For MaiAgent type, this is auto-populated from uploaded files. |
| isActive      | boolean        | 否  | When disabled, this database will not be used in Text-to-SQL queries                                                                          |
| chatbots      | array\[IdName] | 否  |                                                                                                                                               |
| groups        | array\[IdName] | 否  |                                                                                                                                               |

**請求結構範例**

```typescript
{
  "name"?: string // Display name for this database connection (非必填)
  "description"?: string // Description of the database and its purpose (非必填)
  "databaseUrl"?: string // Connection string for external databases. Not required for MaiAgent type as it uses the system default. (非必填)
  "includeTables"?: object // Optional list of tables to include. Format: {"tables": ["table1", "table2"]}. For MaiAgent type, this is auto-populated from uploaded files. (非必填)
  "isActive"?: boolean // When disabled, this database will not be used in Text-to-SQL queries (非必填)
  "chatbots"?: [ // 非必填
    {
      "id": string (uuid)
    }
  ]
  "groups"?: [ // 非必填
    {
      "id": string (uuid)
    }
  ]
}
```

**請求範例值**

```json
{
  "name": "範例名稱",
  "description": "範例字串",
  "databaseUrl": "範例字串",
  "includeTables": null,
  "isActive": true,
  "chatbots": [
    {
      "id": "550e8400-e29b-41d4-a716-446655440000"
    }
  ],
  "groups": [
    {
      "id": "550e8400-e29b-41d4-a716-446655440000"
    }
  ]
}
```

#### 程式碼範例

{% tabs %}
{% tab title="Shell/Bash" %}

```bash
# 呼叫 API 示例 (Shell)
curl -X PATCH "https://api.maiagent.ai/api/sql-databases/550e8400-e29b-41d4-a716-446655440000/" \
  -H "Authorization: Api-Key YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "範例名稱",
    "description": "範例字串",
    "databaseUrl": "範例字串",
    "includeTables": null,
    "isActive": true,
    "chatbots": [
      {
        "id": "550e8400-e29b-41d4-a716-446655440000"
      }
    ],
    "groups": [
      {
        "id": "550e8400-e29b-41d4-a716-446655440000"
      }
    ]
  }'

# 請確認在執行前替換 YOUR_API_KEY 並核對請求資料。
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
const axios = require('axios');

// 設定請求標頭
const config = {
  headers: {
    'Authorization': 'Api-Key YOUR_API_KEY',
    'Content-Type': 'application/json'
  }
};

// 請求內容 (payload)
const data = {
    "name": "範例名稱",
    "description": "範例字串",
    "databaseUrl": "範例字串",
    "includeTables": null,
    "isActive": true,
    "chatbots": [
      {
        "id": "550e8400-e29b-41d4-a716-446655440000"
      }
    ],
    "groups": [
      {
        "id": "550e8400-e29b-41d4-a716-446655440000"
      }
    ]
  };

axios.patch("https://api.maiagent.ai/api/sql-databases/550e8400-e29b-41d4-a716-446655440000/", data, config)
  .then(response => {
    console.log('成功取得回應:');
    console.log(response.data);
  })
  .catch(error => {
    console.error('請求發生錯誤:');
    console.error(error.response?.data || error.message);
  });
```

{% endtab %}

{% tab title="Python" %}

```python
import requests

url = "https://api.maiagent.ai/api/sql-databases/550e8400-e29b-41d4-a716-446655440000/"
headers = {
    "Authorization": "Api-Key YOUR_API_KEY",
    "Content-Type": "application/json"
}

# 請求內容 (payload)
data = {
      "name": "範例名稱",
      "description": "範例字串",
      "databaseUrl": "範例字串",
      "includeTables": null,
      "isActive": true,
      "chatbots": [
        {
          "id": "550e8400-e29b-41d4-a716-446655440000"
        }
      ],
      "groups": [
        {
          "id": "550e8400-e29b-41d4-a716-446655440000"
        }
      ]
    }

response = requests.patch(url, json=data, headers=headers)
try:
    print("成功取得回應:")
    print(response.json())
except Exception as e:
    print("請求發生錯誤:", e)
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php
require 'vendor/autoload.php';

$client = new GuzzleHttp\Client();

try {
    $response = $client->patch("https://api.maiagent.ai/api/sql-databases/550e8400-e29b-41d4-a716-446655440000/", [
        'headers' => [
            'Authorization' => 'Api-Key YOUR_API_KEY',
            'Content-Type' => 'application/json'
        ],
        'json' => {
            "name": "範例名稱",
            "description": "範例字串",
            "databaseUrl": "範例字串",
            "includeTables": null,
            "isActive": true,
            "chatbots": [
                {
                    "id": "550e8400-e29b-41d4-a716-446655440000"
                }
            ],
            "groups": [
                {
                    "id": "550e8400-e29b-41d4-a716-446655440000"
                }
            ]
        }
    ]);
    
    $data = json_decode($response->getBody(), true);
    echo "成功取得回應:\n";
    print_r($data);
} catch (Exception $e) {
    echo '請求發生錯誤: ' . $e->getMessage();
}
?>
```

{% endtab %}
{% endtabs %}

#### 回應內容

**狀態碼: 200**

**回應結構範例**

```typescript
{
  "id": string (uuid)
  "name": string // Display name for this database connection
  "description"?: string // Description of the database and its purpose (非必填)
  "databaseType":  // Type of database: PostgreSQL, MySQL, MSSQL, Oracle, or MaiAgent

* `postgresql` - PostgreSQL
* `mysql` - MySQL
* `maiagent` - MaiAgent
* `oracle` - Oracle
* `mssql` - MSSQL
  {
  }
  "databaseUrl"?: string // Connection string for external databases. Not required for MaiAgent type as it uses the system default. (非必填)
  "includeTables"?: object // Optional list of tables to include. Format: {"tables": ["table1", "table2"]}. For MaiAgent type, this is auto-populated from uploaded files. (非必填)
  "isActive"?: boolean // When disabled, this database will not be used in Text-to-SQL queries (非必填)
  "status": 
  {
  }
  "deletedAt": string (timestamp)
  "tables": [
    {
      "id": string (uuid)
      "tableName": string // Name of the table in the database
      "description"?: string // Description of the table and its data for better Text-to-SQL understanding (非必填)
      "status": 
      {
      }
      "errorMessage": string // Error details if table creation or deletion failed
      "sourceFile": 
      {
        "id": string (uuid)
        "name": string
        "isFromKnowledgeBase": boolean // Determine if the source file originated from a knowledge base upload.

Returns True if the file was uploaded via knowledge base,
False if uploaded directly to the database.
      }
      "columns": [
        {
          "id": string (uuid)
          "columnName": string
          "columnType"?: string // Data type of the column (e.g., VARCHAR, INTEGER, TIMESTAMP) (非必填)
          "description"?: string // Description of the column for better Text-to-SQL understanding (非必填)
          "isPrimaryKey"?: boolean // 非必填
          "isNullable"?: boolean // 非必填
          "createdAt": string (timestamp)
          "updatedAt": string (timestamp)
        }
      ]
      "createdAt": string (timestamp)
      "updatedAt": string (timestamp)
    }
  ]
  "chatbots": [
    {
      "id": string (uuid)
      "name": string
    }
  ]
  "groups": [
    {
      "id": string (uuid)
      "name": string
    }
  ]
  "canUpdate": boolean // Return whether the current user can update this resource.
  "canDelete": boolean // Return whether the current user can delete this resource.
  "createdAt": string (timestamp)
  "updatedAt": string (timestamp)
}
```

**回應範例值**

```json
{
  "id": "550e8400-e29b-41d4-a716-446655440000",
  "name": "回應字串",
  "description": "回應字串",
  "databaseType": {},
  "databaseUrl": "回應字串",
  "includeTables": null,
  "isActive": false,
  "status": {},
  "deletedAt": "回應字串",
  "tables": [
    {
      "id": "550e8400-e29b-41d4-a716-446655440000",
      "tableName": "回應字串",
      "description": "回應字串",
      "status": {},
      "errorMessage": "回應字串",
      "sourceFile": {
        "id": "550e8400-e29b-41d4-a716-446655440000",
        "name": "回應字串",
        "isFromKnowledgeBase": false
      },
      "columns": [
        {
          "id": "550e8400-e29b-41d4-a716-446655440000",
          "columnName": "回應字串",
          "columnType": "回應字串",
          "description": "回應字串",
          "isPrimaryKey": false,
          "isNullable": false,
          "createdAt": "回應字串",
          "updatedAt": "回應字串"
        }
      ],
      "createdAt": "回應字串",
      "updatedAt": "回應字串"
    }
  ],
  "chatbots": [
    {
      "id": "550e8400-e29b-41d4-a716-446655440000",
      "name": "回應字串"
    }
  ],
  "groups": [
    {
      "id": "550e8400-e29b-41d4-a716-446655440000",
      "name": "回應字串"
    }
  ],
  "canUpdate": false,
  "canDelete": false,
  "createdAt": "回應字串",
  "updatedAt": "回應字串"
}
```

***

### 部分更新 SQL 資料庫 <a href="#sql" id="sql"></a>

PATCH `/api/v1/sql-databases/{id}/`

#### 參數

| 參數名稱 | 必填 | 類型     | 說明                                           |
| ---- | -- | ------ | -------------------------------------------- |
| `id` | ✅  | string | A UUID string identifying this SQL Database. |

#### 請求內容

**請求參數**

| 欄位            | 類型             | 必填 | 說明                                                                                                                                            |
| ------------- | -------------- | -- | --------------------------------------------------------------------------------------------------------------------------------------------- |
| name          | string         | 否  | Display name for this database connection                                                                                                     |
| description   | string         | 否  | Description of the database and its purpose                                                                                                   |
| databaseUrl   | string         | 否  | Connection string for external databases. Not required for MaiAgent type as it uses the system default.                                       |
| includeTables | object         | 否  | Optional list of tables to include. Format: {"tables": \["table1", "table2"]}. For MaiAgent type, this is auto-populated from uploaded files. |
| isActive      | boolean        | 否  | When disabled, this database will not be used in Text-to-SQL queries                                                                          |
| chatbots      | array\[IdName] | 否  |                                                                                                                                               |
| groups        | array\[IdName] | 否  |                                                                                                                                               |

**請求結構範例**

```typescript
{
  "name"?: string // Display name for this database connection (非必填)
  "description"?: string // Description of the database and its purpose (非必填)
  "databaseUrl"?: string // Connection string for external databases. Not required for MaiAgent type as it uses the system default. (非必填)
  "includeTables"?: object // Optional list of tables to include. Format: {"tables": ["table1", "table2"]}. For MaiAgent type, this is auto-populated from uploaded files. (非必填)
  "isActive"?: boolean // When disabled, this database will not be used in Text-to-SQL queries (非必填)
  "chatbots"?: [ // 非必填
    {
      "id": string (uuid)
    }
  ]
  "groups"?: [ // 非必填
    {
      "id": string (uuid)
    }
  ]
}
```

**請求範例值**

```json
{
  "name": "範例名稱",
  "description": "範例字串",
  "databaseUrl": "範例字串",
  "includeTables": null,
  "isActive": true,
  "chatbots": [
    {
      "id": "550e8400-e29b-41d4-a716-446655440000"
    }
  ],
  "groups": [
    {
      "id": "550e8400-e29b-41d4-a716-446655440000"
    }
  ]
}
```

#### 程式碼範例

{% tabs %}
{% tab title="Shell/Bash" %}

```bash
# 呼叫 API 示例 (Shell)
curl -X PATCH "https://api.maiagent.ai/api/v1/sql-databases/550e8400-e29b-41d4-a716-446655440000/" \
  -H "Authorization: Api-Key YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "範例名稱",
    "description": "範例字串",
    "databaseUrl": "範例字串",
    "includeTables": null,
    "isActive": true,
    "chatbots": [
      {
        "id": "550e8400-e29b-41d4-a716-446655440000"
      }
    ],
    "groups": [
      {
        "id": "550e8400-e29b-41d4-a716-446655440000"
      }
    ]
  }'

# 請確認在執行前替換 YOUR_API_KEY 並核對請求資料。
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
const axios = require('axios');

// 設定請求標頭
const config = {
  headers: {
    'Authorization': 'Api-Key YOUR_API_KEY',
    'Content-Type': 'application/json'
  }
};

// 請求內容 (payload)
const data = {
    "name": "範例名稱",
    "description": "範例字串",
    "databaseUrl": "範例字串",
    "includeTables": null,
    "isActive": true,
    "chatbots": [
      {
        "id": "550e8400-e29b-41d4-a716-446655440000"
      }
    ],
    "groups": [
      {
        "id": "550e8400-e29b-41d4-a716-446655440000"
      }
    ]
  };

axios.patch("https://api.maiagent.ai/api/v1/sql-databases/550e8400-e29b-41d4-a716-446655440000/", data, config)
  .then(response => {
    console.log('成功取得回應:');
    console.log(response.data);
  })
  .catch(error => {
    console.error('請求發生錯誤:');
    console.error(error.response?.data || error.message);
  });
```

{% endtab %}

{% tab title="Python" %}

```python
import requests

url = "https://api.maiagent.ai/api/v1/sql-databases/550e8400-e29b-41d4-a716-446655440000/"
headers = {
    "Authorization": "Api-Key YOUR_API_KEY",
    "Content-Type": "application/json"
}

# 請求內容 (payload)
data = {
      "name": "範例名稱",
      "description": "範例字串",
      "databaseUrl": "範例字串",
      "includeTables": null,
      "isActive": true,
      "chatbots": [
        {
          "id": "550e8400-e29b-41d4-a716-446655440000"
        }
      ],
      "groups": [
        {
          "id": "550e8400-e29b-41d4-a716-446655440000"
        }
      ]
    }

response = requests.patch(url, json=data, headers=headers)
try:
    print("成功取得回應:")
    print(response.json())
except Exception as e:
    print("請求發生錯誤:", e)
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php
require 'vendor/autoload.php';

$client = new GuzzleHttp\Client();

try {
    $response = $client->patch("https://api.maiagent.ai/api/v1/sql-databases/550e8400-e29b-41d4-a716-446655440000/", [
        'headers' => [
            'Authorization' => 'Api-Key YOUR_API_KEY',
            'Content-Type' => 'application/json'
        ],
        'json' => {
            "name": "範例名稱",
            "description": "範例字串",
            "databaseUrl": "範例字串",
            "includeTables": null,
            "isActive": true,
            "chatbots": [
                {
                    "id": "550e8400-e29b-41d4-a716-446655440000"
                }
            ],
            "groups": [
                {
                    "id": "550e8400-e29b-41d4-a716-446655440000"
                }
            ]
        }
    ]);
    
    $data = json_decode($response->getBody(), true);
    echo "成功取得回應:\n";
    print_r($data);
} catch (Exception $e) {
    echo '請求發生錯誤: ' . $e->getMessage();
}
?>
```

{% endtab %}
{% endtabs %}

#### 回應內容

**狀態碼: 200**

**回應結構範例**

```typescript
{
  "id": string (uuid)
  "name": string // Display name for this database connection
  "description"?: string // Description of the database and its purpose (非必填)
  "databaseType":  // Type of database: PostgreSQL, MySQL, MSSQL, Oracle, or MaiAgent

* `postgresql` - PostgreSQL
* `mysql` - MySQL
* `maiagent` - MaiAgent
* `oracle` - Oracle
* `mssql` - MSSQL
  {
  }
  "databaseUrl"?: string // Connection string for external databases. Not required for MaiAgent type as it uses the system default. (非必填)
  "includeTables"?: object // Optional list of tables to include. Format: {"tables": ["table1", "table2"]}. For MaiAgent type, this is auto-populated from uploaded files. (非必填)
  "isActive"?: boolean // When disabled, this database will not be used in Text-to-SQL queries (非必填)
  "status": 
  {
  }
  "deletedAt": string (timestamp)
  "tables": [
    {
      "id": string (uuid)
      "tableName": string // Name of the table in the database
      "description"?: string // Description of the table and its data for better Text-to-SQL understanding (非必填)
      "status": 
      {
      }
      "errorMessage": string // Error details if table creation or deletion failed
      "sourceFile": 
      {
        "id": string (uuid)
        "name": string
        "isFromKnowledgeBase": boolean // Determine if the source file originated from a knowledge base upload.

Returns True if the file was uploaded via knowledge base,
False if uploaded directly to the database.
      }
      "columns": [
        {
          "id": string (uuid)
          "columnName": string
          "columnType"?: string // Data type of the column (e.g., VARCHAR, INTEGER, TIMESTAMP) (非必填)
          "description"?: string // Description of the column for better Text-to-SQL understanding (非必填)
          "isPrimaryKey"?: boolean // 非必填
          "isNullable"?: boolean // 非必填
          "createdAt": string (timestamp)
          "updatedAt": string (timestamp)
        }
      ]
      "createdAt": string (timestamp)
      "updatedAt": string (timestamp)
    }
  ]
  "chatbots": [
    {
      "id": string (uuid)
      "name": string
    }
  ]
  "groups": [
    {
      "id": string (uuid)
      "name": string
    }
  ]
  "canUpdate": boolean // Return whether the current user can update this resource.
  "canDelete": boolean // Return whether the current user can delete this resource.
  "createdAt": string (timestamp)
  "updatedAt": string (timestamp)
}
```

**回應範例值**

```json
{
  "id": "550e8400-e29b-41d4-a716-446655440000",
  "name": "回應字串",
  "description": "回應字串",
  "databaseType": {},
  "databaseUrl": "回應字串",
  "includeTables": null,
  "isActive": false,
  "status": {},
  "deletedAt": "回應字串",
  "tables": [
    {
      "id": "550e8400-e29b-41d4-a716-446655440000",
      "tableName": "回應字串",
      "description": "回應字串",
      "status": {},
      "errorMessage": "回應字串",
      "sourceFile": {
        "id": "550e8400-e29b-41d4-a716-446655440000",
        "name": "回應字串",
        "isFromKnowledgeBase": false
      },
      "columns": [
        {
          "id": "550e8400-e29b-41d4-a716-446655440000",
          "columnName": "回應字串",
          "columnType": "回應字串",
          "description": "回應字串",
          "isPrimaryKey": false,
          "isNullable": false,
          "createdAt": "回應字串",
          "updatedAt": "回應字串"
        }
      ],
      "createdAt": "回應字串",
      "updatedAt": "回應字串"
    }
  ],
  "chatbots": [
    {
      "id": "550e8400-e29b-41d4-a716-446655440000",
      "name": "回應字串"
    }
  ],
  "groups": [
    {
      "id": "550e8400-e29b-41d4-a716-446655440000",
      "name": "回應字串"
    }
  ],
  "canUpdate": false,
  "canDelete": false,
  "createdAt": "回應字串",
  "updatedAt": "回應字串"
}
```

***

### 刪除 SQL 資料庫 <a href="#sql" id="sql"></a>

DELETE `/api/sql-databases/{id}/`

#### 參數

| 參數名稱 | 必填 | 類型     | 說明                                           |
| ---- | -- | ------ | -------------------------------------------- |
| `id` | ✅  | string | A UUID string identifying this SQL Database. |

#### 程式碼範例

{% tabs %}
{% tab title="Shell/Bash" %}

```bash
# 呼叫 API 示例 (Shell)
curl -X DELETE "https://api.maiagent.ai/api/sql-databases/550e8400-e29b-41d4-a716-446655440000/" \
  -H "Authorization: Api-Key YOUR_API_KEY"

# 請確認在執行前替換 YOUR_API_KEY 並核對請求資料。
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
const axios = require('axios');

// 設定請求標頭
const config = {
  headers: {
    'Authorization': 'Api-Key YOUR_API_KEY'
  }
};

// 請求內容 (payload)
const data = null;

axios.delete("https://api.maiagent.ai/api/sql-databases/550e8400-e29b-41d4-a716-446655440000/", data, config)
  .then(response => {
    console.log('成功取得回應:');
    console.log(response.data);
  })
  .catch(error => {
    console.error('請求發生錯誤:');
    console.error(error.response?.data || error.message);
  });
```

{% endtab %}

{% tab title="Python" %}

```python
import requests

url = "https://api.maiagent.ai/api/sql-databases/550e8400-e29b-41d4-a716-446655440000/"
headers = {
    "Authorization": "Api-Key YOUR_API_KEY"
}


response = requests.delete(url, headers=headers)
try:
    print("成功取得回應:")
    print(response.json())
except Exception as e:
    print("請求發生錯誤:", e)
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php
require 'vendor/autoload.php';

$client = new GuzzleHttp\Client();

try {
    $response = $client->delete("https://api.maiagent.ai/api/sql-databases/550e8400-e29b-41d4-a716-446655440000/", [
        'headers' => [
            'Authorization' => 'Api-Key YOUR_API_KEY'
        ]
    ]);
    
    $data = json_decode($response->getBody(), true);
    echo "成功取得回應:\n";
    print_r($data);
} catch (Exception $e) {
    echo '請求發生錯誤: ' . $e->getMessage();
}
?>
```

{% endtab %}
{% endtabs %}

#### 回應內容

| 狀態碼 | 說明               |
| --- | ---------------- |
| 204 | No response body |

***

### 刪除 SQL 資料庫 <a href="#sql" id="sql"></a>

DELETE `/api/v1/sql-databases/{id}/`

#### 參數

| 參數名稱 | 必填 | 類型     | 說明                                           |
| ---- | -- | ------ | -------------------------------------------- |
| `id` | ✅  | string | A UUID string identifying this SQL Database. |

#### 程式碼範例

{% tabs %}
{% tab title="Shell/Bash" %}

```bash
# 呼叫 API 示例 (Shell)
curl -X DELETE "https://api.maiagent.ai/api/v1/sql-databases/550e8400-e29b-41d4-a716-446655440000/" \
  -H "Authorization: Api-Key YOUR_API_KEY"

# 請確認在執行前替換 YOUR_API_KEY 並核對請求資料。
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
const axios = require('axios');

// 設定請求標頭
const config = {
  headers: {
    'Authorization': 'Api-Key YOUR_API_KEY'
  }
};

// 請求內容 (payload)
const data = null;

axios.delete("https://api.maiagent.ai/api/v1/sql-databases/550e8400-e29b-41d4-a716-446655440000/", data, config)
  .then(response => {
    console.log('成功取得回應:');
    console.log(response.data);
  })
  .catch(error => {
    console.error('請求發生錯誤:');
    console.error(error.response?.data || error.message);
  });
```

{% endtab %}

{% tab title="Python" %}

```python
import requests

url = "https://api.maiagent.ai/api/v1/sql-databases/550e8400-e29b-41d4-a716-446655440000/"
headers = {
    "Authorization": "Api-Key YOUR_API_KEY"
}


response = requests.delete(url, headers=headers)
try:
    print("成功取得回應:")
    print(response.json())
except Exception as e:
    print("請求發生錯誤:", e)
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php
require 'vendor/autoload.php';

$client = new GuzzleHttp\Client();

try {
    $response = $client->delete("https://api.maiagent.ai/api/v1/sql-databases/550e8400-e29b-41d4-a716-446655440000/", [
        'headers' => [
            'Authorization' => 'Api-Key YOUR_API_KEY'
        ]
    ]);
    
    $data = json_decode($response->getBody(), true);
    echo "成功取得回應:\n";
    print_r($data);
} catch (Exception $e) {
    echo '請求發生錯誤: ' . $e->getMessage();
}
?>
```

{% endtab %}
{% endtabs %}

#### 回應內容

| 狀態碼 | 說明               |
| --- | ---------------- |
| 204 | No response body |

***

### 測試資料庫連線 <a href="#undefined" id="undefined"></a>

POST `/api/sql-databases/{id}/test-connection/`

#### 參數

| 參數名稱 | 必填 | 類型     | 說明                                           |
| ---- | -- | ------ | -------------------------------------------- |
| `id` | ✅  | string | A UUID string identifying this SQL Database. |

#### 請求內容

**請求參數**

| 欄位           | 類型                                                        | 必填 | 說明                                                                                                    |
| ------------ | --------------------------------------------------------- | -- | ----------------------------------------------------------------------------------------------------- |
| databaseType | string (enum: postgresql, mysql, maiagent, oracle, mssql) | 是  | `postgresql`: PostgreSQL ; `mysql`: MySQL ; `maiagent`: MaiAgent ; `oracle`: Oracle ; `mssql`: MSSQL; |
| databaseUrl  | string                                                    | 是  |                                                                                                       |

**請求結構範例**

```typescript
{
  "databaseType": string (enum: postgresql, mysql, maiagent, oracle, mssql) // * `postgresql` - PostgreSQL
* `mysql` - MySQL
* `maiagent` - MaiAgent
* `oracle` - Oracle
* `mssql` - MSSQL
  "databaseUrl": string
}
```

**請求範例值**

```json
{
  "databaseType": "postgresql",
  "databaseUrl": "範例字串"
}
```

#### 程式碼範例

{% tabs %}
{% tab title="Shell/Bash" %}

```bash
# 呼叫 API 示例 (Shell)
curl -X POST "https://api.maiagent.ai/api/sql-databases/550e8400-e29b-41d4-a716-446655440000/test-connection/" \
  -H "Authorization: Api-Key YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "databaseType": "postgresql",
    "databaseUrl": "範例字串"
  }'

# 請確認在執行前替換 YOUR_API_KEY 並核對請求資料。
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
const axios = require('axios');

// 設定請求標頭
const config = {
  headers: {
    'Authorization': 'Api-Key YOUR_API_KEY',
    'Content-Type': 'application/json'
  }
};

// 請求內容 (payload)
const data = {
    "databaseType": "postgresql",
    "databaseUrl": "範例字串"
  };

axios.post("https://api.maiagent.ai/api/sql-databases/550e8400-e29b-41d4-a716-446655440000/test-connection/", data, config)
  .then(response => {
    console.log('成功取得回應:');
    console.log(response.data);
  })
  .catch(error => {
    console.error('請求發生錯誤:');
    console.error(error.response?.data || error.message);
  });
```

{% endtab %}

{% tab title="Python" %}

```python
import requests

url = "https://api.maiagent.ai/api/sql-databases/550e8400-e29b-41d4-a716-446655440000/test-connection/"
headers = {
    "Authorization": "Api-Key YOUR_API_KEY",
    "Content-Type": "application/json"
}

# 請求內容 (payload)
data = {
      "databaseType": "postgresql",
      "databaseUrl": "範例字串"
    }

response = requests.post(url, json=data, headers=headers)
try:
    print("成功取得回應:")
    print(response.json())
except Exception as e:
    print("請求發生錯誤:", e)
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php
require 'vendor/autoload.php';

$client = new GuzzleHttp\Client();

try {
    $response = $client->post("https://api.maiagent.ai/api/sql-databases/550e8400-e29b-41d4-a716-446655440000/test-connection/", [
        'headers' => [
            'Authorization' => 'Api-Key YOUR_API_KEY',
            'Content-Type' => 'application/json'
        ],
        'json' => {
            "databaseType": "postgresql",
            "databaseUrl": "範例字串"
        }
    ]);
    
    $data = json_decode($response->getBody(), true);
    echo "成功取得回應:\n";
    print_r($data);
} catch (Exception $e) {
    echo '請求發生錯誤: ' . $e->getMessage();
}
?>
```

{% endtab %}
{% endtabs %}

#### 回應內容

**狀態碼: 200**

**回應結構範例**

```typescript
{
  "success"?: boolean // 非必填
  "message"?: string // 非必填
}
```

**回應範例值**

```json
{
  "success": false,
  "message": "回應字串"
}
```

***

### 測試資料庫連線 <a href="#undefined" id="undefined"></a>

POST `/api/v1/sql-databases/{id}/test-connection/`

#### 參數

| 參數名稱 | 必填 | 類型     | 說明                                           |
| ---- | -- | ------ | -------------------------------------------- |
| `id` | ✅  | string | A UUID string identifying this SQL Database. |

#### 請求內容

**請求參數**

| 欄位           | 類型                                                        | 必填 | 說明                                                                                                    |
| ------------ | --------------------------------------------------------- | -- | ----------------------------------------------------------------------------------------------------- |
| databaseType | string (enum: postgresql, mysql, maiagent, oracle, mssql) | 是  | `postgresql`: PostgreSQL ; `mysql`: MySQL ; `maiagent`: MaiAgent ; `oracle`: Oracle ; `mssql`: MSSQL; |
| databaseUrl  | string                                                    | 是  |                                                                                                       |

**請求結構範例**

```typescript
{
  "databaseType": string (enum: postgresql, mysql, maiagent, oracle, mssql) // * `postgresql` - PostgreSQL
* `mysql` - MySQL
* `maiagent` - MaiAgent
* `oracle` - Oracle
* `mssql` - MSSQL
  "databaseUrl": string
}
```

**請求範例值**

```json
{
  "databaseType": "postgresql",
  "databaseUrl": "範例字串"
}
```

#### 程式碼範例

{% tabs %}
{% tab title="Shell/Bash" %}

```bash
# 呼叫 API 示例 (Shell)
curl -X POST "https://api.maiagent.ai/api/v1/sql-databases/550e8400-e29b-41d4-a716-446655440000/test-connection/" \
  -H "Authorization: Api-Key YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "databaseType": "postgresql",
    "databaseUrl": "範例字串"
  }'

# 請確認在執行前替換 YOUR_API_KEY 並核對請求資料。
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
const axios = require('axios');

// 設定請求標頭
const config = {
  headers: {
    'Authorization': 'Api-Key YOUR_API_KEY',
    'Content-Type': 'application/json'
  }
};

// 請求內容 (payload)
const data = {
    "databaseType": "postgresql",
    "databaseUrl": "範例字串"
  };

axios.post("https://api.maiagent.ai/api/v1/sql-databases/550e8400-e29b-41d4-a716-446655440000/test-connection/", data, config)
  .then(response => {
    console.log('成功取得回應:');
    console.log(response.data);
  })
  .catch(error => {
    console.error('請求發生錯誤:');
    console.error(error.response?.data || error.message);
  });
```

{% endtab %}

{% tab title="Python" %}

```python
import requests

url = "https://api.maiagent.ai/api/v1/sql-databases/550e8400-e29b-41d4-a716-446655440000/test-connection/"
headers = {
    "Authorization": "Api-Key YOUR_API_KEY",
    "Content-Type": "application/json"
}

# 請求內容 (payload)
data = {
      "databaseType": "postgresql",
      "databaseUrl": "範例字串"
    }

response = requests.post(url, json=data, headers=headers)
try:
    print("成功取得回應:")
    print(response.json())
except Exception as e:
    print("請求發生錯誤:", e)
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php
require 'vendor/autoload.php';

$client = new GuzzleHttp\Client();

try {
    $response = $client->post("https://api.maiagent.ai/api/v1/sql-databases/550e8400-e29b-41d4-a716-446655440000/test-connection/", [
        'headers' => [
            'Authorization' => 'Api-Key YOUR_API_KEY',
            'Content-Type' => 'application/json'
        ],
        'json' => {
            "databaseType": "postgresql",
            "databaseUrl": "範例字串"
        }
    ]);
    
    $data = json_decode($response->getBody(), true);
    echo "成功取得回應:\n";
    print_r($data);
} catch (Exception $e) {
    echo '請求發生錯誤: ' . $e->getMessage();
}
?>
```

{% endtab %}
{% endtabs %}

#### 回應內容

**狀態碼: 200**

**回應結構範例**

```typescript
{
  "success"?: boolean // 非必填
  "message"?: string // 非必填
}
```

**回應範例值**

```json
{
  "success": false,
  "message": "回應字串"
}
```

***

### 上傳檔案至資料庫 <a href="#undefined" id="undefined"></a>

POST `/api/sql-databases/{id}/upload-files/`

#### 參數

| 參數名稱 | 必填 | 類型     | 說明                                           |
| ---- | -- | ------ | -------------------------------------------- |
| `id` | ✅  | string | A UUID string identifying this SQL Database. |

#### 請求內容

**請求參數**

| 欄位    | 類型             | 必填 | 說明 |
| ----- | -------------- | -- | -- |
| files | array\[object] | 是  |    |

**請求結構範例**

```typescript
{
  "files": [
    {
      "file": string // File path from presigned URL upload (e.g., media/chatbotfiles/xxx/file.csv)
      "filename": string // Original filename
      "size": integer // File size in bytes
    }
  ]
}
```

**請求範例值**

```json
{
  "files": [
    {
      "file": "media/chatbotfiles/xxx/data.csv",
      "filename": "data.csv",
      "size": 1024
    },
    {
      "file": "media/chatbotfiles/xxx/report.xlsx",
      "filename": "report.xlsx",
      "size": 2048
    }
  ]
}
```

#### 程式碼範例

{% tabs %}
{% tab title="Shell/Bash" %}

```bash
# 呼叫 API 示例 (Shell)
curl -X POST "https://api.maiagent.ai/api/sql-databases/550e8400-e29b-41d4-a716-446655440000/upload-files/" \
  -H "Authorization: Api-Key YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "files": [
      {
        "file": "media/chatbotfiles/xxx/data.csv",
        "filename": "data.csv",
        "size": 1024
      },
      {
        "file": "media/chatbotfiles/xxx/report.xlsx",
        "filename": "report.xlsx",
        "size": 2048
      }
    ]
  }'

# 請確認在執行前替換 YOUR_API_KEY 並核對請求資料。
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
const axios = require('axios');

// 設定請求標頭
const config = {
  headers: {
    'Authorization': 'Api-Key YOUR_API_KEY',
    'Content-Type': 'application/json'
  }
};

// 請求內容 (payload)
const data = {
    "files": [
      {
        "file": "media/chatbotfiles/xxx/data.csv",
        "filename": "data.csv",
        "size": 1024
      },
      {
        "file": "media/chatbotfiles/xxx/report.xlsx",
        "filename": "report.xlsx",
        "size": 2048
      }
    ]
  };

axios.post("https://api.maiagent.ai/api/sql-databases/550e8400-e29b-41d4-a716-446655440000/upload-files/", data, config)
  .then(response => {
    console.log('成功取得回應:');
    console.log(response.data);
  })
  .catch(error => {
    console.error('請求發生錯誤:');
    console.error(error.response?.data || error.message);
  });
```

{% endtab %}

{% tab title="Python" %}

```python
import requests

url = "https://api.maiagent.ai/api/sql-databases/550e8400-e29b-41d4-a716-446655440000/upload-files/"
headers = {
    "Authorization": "Api-Key YOUR_API_KEY",
    "Content-Type": "application/json"
}

# 請求內容 (payload)
data = {
      "files": [
        {
          "file": "media/chatbotfiles/xxx/data.csv",
          "filename": "data.csv",
          "size": 1024
        },
        {
          "file": "media/chatbotfiles/xxx/report.xlsx",
          "filename": "report.xlsx",
          "size": 2048
        }
      ]
    }

response = requests.post(url, json=data, headers=headers)
try:
    print("成功取得回應:")
    print(response.json())
except Exception as e:
    print("請求發生錯誤:", e)
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php
require 'vendor/autoload.php';

$client = new GuzzleHttp\Client();

try {
    $response = $client->post("https://api.maiagent.ai/api/sql-databases/550e8400-e29b-41d4-a716-446655440000/upload-files/", [
        'headers' => [
            'Authorization' => 'Api-Key YOUR_API_KEY',
            'Content-Type' => 'application/json'
        ],
        'json' => {
            "files": [
                {
                    "file": "media/chatbotfiles/xxx/data.csv",
                    "filename": "data.csv",
                    "size": 1024
                },
                {
                    "file": "media/chatbotfiles/xxx/report.xlsx",
                    "filename": "report.xlsx",
                    "size": 2048
                }
            ]
        }
    ]);
    
    $data = json_decode($response->getBody(), true);
    echo "成功取得回應:\n";
    print_r($data);
} catch (Exception $e) {
    echo '請求發生錯誤: ' . $e->getMessage();
}
?>
```

{% endtab %}
{% endtabs %}

#### 回應內容

**狀態碼: 201**

**回應結構範例**

```typescript
{
  "message"?: string // 非必填
  "filesCount"?: integer // 非必填
  "fileIds"?: [ // 非必填
    string (uuid)
  ]
}
```

**回應範例值**

```json
{
  "message": "回應字串",
  "filesCount": 456,
  "fileIds": [
    "550e8400-e29b-41d4-a716-446655440000"
  ]
}
```

***

### 上傳檔案至資料庫 <a href="#undefined" id="undefined"></a>

POST `/api/v1/sql-databases/{id}/upload-files/`

#### 參數

| 參數名稱 | 必填 | 類型     | 說明                                           |
| ---- | -- | ------ | -------------------------------------------- |
| `id` | ✅  | string | A UUID string identifying this SQL Database. |

#### 請求內容

**請求參數**

| 欄位    | 類型             | 必填 | 說明 |
| ----- | -------------- | -- | -- |
| files | array\[object] | 是  |    |

**請求結構範例**

```typescript
{
  "files": [
    {
      "file": string // File path from presigned URL upload (e.g., media/chatbotfiles/xxx/file.csv)
      "filename": string // Original filename
      "size": integer // File size in bytes
    }
  ]
}
```

**請求範例值**

```json
{
  "files": [
    {
      "file": "media/chatbotfiles/xxx/data.csv",
      "filename": "data.csv",
      "size": 1024
    },
    {
      "file": "media/chatbotfiles/xxx/report.xlsx",
      "filename": "report.xlsx",
      "size": 2048
    }
  ]
}
```

#### 程式碼範例

{% tabs %}
{% tab title="Shell/Bash" %}

```bash
# 呼叫 API 示例 (Shell)
curl -X POST "https://api.maiagent.ai/api/v1/sql-databases/550e8400-e29b-41d4-a716-446655440000/upload-files/" \
  -H "Authorization: Api-Key YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "files": [
      {
        "file": "media/chatbotfiles/xxx/data.csv",
        "filename": "data.csv",
        "size": 1024
      },
      {
        "file": "media/chatbotfiles/xxx/report.xlsx",
        "filename": "report.xlsx",
        "size": 2048
      }
    ]
  }'

# 請確認在執行前替換 YOUR_API_KEY 並核對請求資料。
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
const axios = require('axios');

// 設定請求標頭
const config = {
  headers: {
    'Authorization': 'Api-Key YOUR_API_KEY',
    'Content-Type': 'application/json'
  }
};

// 請求內容 (payload)
const data = {
    "files": [
      {
        "file": "media/chatbotfiles/xxx/data.csv",
        "filename": "data.csv",
        "size": 1024
      },
      {
        "file": "media/chatbotfiles/xxx/report.xlsx",
        "filename": "report.xlsx",
        "size": 2048
      }
    ]
  };

axios.post("https://api.maiagent.ai/api/v1/sql-databases/550e8400-e29b-41d4-a716-446655440000/upload-files/", data, config)
  .then(response => {
    console.log('成功取得回應:');
    console.log(response.data);
  })
  .catch(error => {
    console.error('請求發生錯誤:');
    console.error(error.response?.data || error.message);
  });
```

{% endtab %}

{% tab title="Python" %}

```python
import requests

url = "https://api.maiagent.ai/api/v1/sql-databases/550e8400-e29b-41d4-a716-446655440000/upload-files/"
headers = {
    "Authorization": "Api-Key YOUR_API_KEY",
    "Content-Type": "application/json"
}

# 請求內容 (payload)
data = {
      "files": [
        {
          "file": "media/chatbotfiles/xxx/data.csv",
          "filename": "data.csv",
          "size": 1024
        },
        {
          "file": "media/chatbotfiles/xxx/report.xlsx",
          "filename": "report.xlsx",
          "size": 2048
        }
      ]
    }

response = requests.post(url, json=data, headers=headers)
try:
    print("成功取得回應:")
    print(response.json())
except Exception as e:
    print("請求發生錯誤:", e)
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php
require 'vendor/autoload.php';

$client = new GuzzleHttp\Client();

try {
    $response = $client->post("https://api.maiagent.ai/api/v1/sql-databases/550e8400-e29b-41d4-a716-446655440000/upload-files/", [
        'headers' => [
            'Authorization' => 'Api-Key YOUR_API_KEY',
            'Content-Type' => 'application/json'
        ],
        'json' => {
            "files": [
                {
                    "file": "media/chatbotfiles/xxx/data.csv",
                    "filename": "data.csv",
                    "size": 1024
                },
                {
                    "file": "media/chatbotfiles/xxx/report.xlsx",
                    "filename": "report.xlsx",
                    "size": 2048
                }
            ]
        }
    ]);
    
    $data = json_decode($response->getBody(), true);
    echo "成功取得回應:\n";
    print_r($data);
} catch (Exception $e) {
    echo '請求發生錯誤: ' . $e->getMessage();
}
?>
```

{% endtab %}
{% endtabs %}

#### 回應內容

**狀態碼: 201**

**回應結構範例**

```typescript
{
  "message"?: string // 非必填
  "filesCount"?: integer // 非必填
  "fileIds"?: [ // 非必填
    string (uuid)
  ]
}
```

**回應範例值**

```json
{
  "message": "回應字串",
  "filesCount": 456,
  "fileIds": [
    "550e8400-e29b-41d4-a716-446655440000"
  ]
}
```

***

### 批量刪除 SQL 資料庫 <a href="#sql" id="sql"></a>

POST `/api/sql-databases/batch-delete/`

#### 請求內容

**請求參數**

| 欄位  | 類型             | 必填 | 說明 |
| --- | -------------- | -- | -- |
| ids | array\[string] | 是  |    |

**請求結構範例**

```typescript
{
  "ids": [
    string (uuid)
  ]
}
```

**請求範例值**

```json
{
  "ids": [
    "550e8400-e29b-41d4-a716-446655440000"
  ]
}
```

#### 程式碼範例

{% tabs %}
{% tab title="Shell/Bash" %}

```bash
# 呼叫 API 示例 (Shell)
curl -X POST "https://api.maiagent.ai/api/sql-databases/batch-delete/" \
  -H "Authorization: Api-Key YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "ids": [
      "550e8400-e29b-41d4-a716-446655440000"
    ]
  }'

# 請確認在執行前替換 YOUR_API_KEY 並核對請求資料。
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
const axios = require('axios');

// 設定請求標頭
const config = {
  headers: {
    'Authorization': 'Api-Key YOUR_API_KEY',
    'Content-Type': 'application/json'
  }
};

// 請求內容 (payload)
const data = {
    "ids": [
      "550e8400-e29b-41d4-a716-446655440000"
    ]
  };

axios.post("https://api.maiagent.ai/api/sql-databases/batch-delete/", data, config)
  .then(response => {
    console.log('成功取得回應:');
    console.log(response.data);
  })
  .catch(error => {
    console.error('請求發生錯誤:');
    console.error(error.response?.data || error.message);
  });
```

{% endtab %}

{% tab title="Python" %}

```python
import requests

url = "https://api.maiagent.ai/api/sql-databases/batch-delete/"
headers = {
    "Authorization": "Api-Key YOUR_API_KEY",
    "Content-Type": "application/json"
}

# 請求內容 (payload)
data = {
      "ids": [
        "550e8400-e29b-41d4-a716-446655440000"
      ]
    }

response = requests.post(url, json=data, headers=headers)
try:
    print("成功取得回應:")
    print(response.json())
except Exception as e:
    print("請求發生錯誤:", e)
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php
require 'vendor/autoload.php';

$client = new GuzzleHttp\Client();

try {
    $response = $client->post("https://api.maiagent.ai/api/sql-databases/batch-delete/", [
        'headers' => [
            'Authorization' => 'Api-Key YOUR_API_KEY',
            'Content-Type' => 'application/json'
        ],
        'json' => {
            "ids": [
                "550e8400-e29b-41d4-a716-446655440000"
            ]
        }
    ]);
    
    $data = json_decode($response->getBody(), true);
    echo "成功取得回應:\n";
    print_r($data);
} catch (Exception $e) {
    echo '請求發生錯誤: ' . $e->getMessage();
}
?>
```

{% endtab %}
{% endtabs %}

#### 回應內容

| 狀態碼 | 說明               |
| --- | ---------------- |
| 204 | No response body |

***

### 批量刪除 SQL 資料庫 <a href="#sql" id="sql"></a>

POST `/api/v1/sql-databases/batch-delete/`

#### 請求內容

**請求參數**

| 欄位  | 類型             | 必填 | 說明 |
| --- | -------------- | -- | -- |
| ids | array\[string] | 是  |    |

**請求結構範例**

```typescript
{
  "ids": [
    string (uuid)
  ]
}
```

**請求範例值**

```json
{
  "ids": [
    "550e8400-e29b-41d4-a716-446655440000"
  ]
}
```

#### 程式碼範例

{% tabs %}
{% tab title="Shell/Bash" %}

```bash
# 呼叫 API 示例 (Shell)
curl -X POST "https://api.maiagent.ai/api/v1/sql-databases/batch-delete/" \
  -H "Authorization: Api-Key YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "ids": [
      "550e8400-e29b-41d4-a716-446655440000"
    ]
  }'

# 請確認在執行前替換 YOUR_API_KEY 並核對請求資料。
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
const axios = require('axios');

// 設定請求標頭
const config = {
  headers: {
    'Authorization': 'Api-Key YOUR_API_KEY',
    'Content-Type': 'application/json'
  }
};

// 請求內容 (payload)
const data = {
    "ids": [
      "550e8400-e29b-41d4-a716-446655440000"
    ]
  };

axios.post("https://api.maiagent.ai/api/v1/sql-databases/batch-delete/", data, config)
  .then(response => {
    console.log('成功取得回應:');
    console.log(response.data);
  })
  .catch(error => {
    console.error('請求發生錯誤:');
    console.error(error.response?.data || error.message);
  });
```

{% endtab %}

{% tab title="Python" %}

```python
import requests

url = "https://api.maiagent.ai/api/v1/sql-databases/batch-delete/"
headers = {
    "Authorization": "Api-Key YOUR_API_KEY",
    "Content-Type": "application/json"
}

# 請求內容 (payload)
data = {
      "ids": [
        "550e8400-e29b-41d4-a716-446655440000"
      ]
    }

response = requests.post(url, json=data, headers=headers)
try:
    print("成功取得回應:")
    print(response.json())
except Exception as e:
    print("請求發生錯誤:", e)
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php
require 'vendor/autoload.php';

$client = new GuzzleHttp\Client();

try {
    $response = $client->post("https://api.maiagent.ai/api/v1/sql-databases/batch-delete/", [
        'headers' => [
            'Authorization' => 'Api-Key YOUR_API_KEY',
            'Content-Type' => 'application/json'
        ],
        'json' => {
            "ids": [
                "550e8400-e29b-41d4-a716-446655440000"
            ]
        }
    ]);
    
    $data = json_decode($response->getBody(), true);
    echo "成功取得回應:\n";
    print_r($data);
} catch (Exception $e) {
    echo '請求發生錯誤: ' . $e->getMessage();
}
?>
```

{% endtab %}
{% endtabs %}

#### 回應內容

| 狀態碼 | 說明               |
| --- | ---------------- |
| 204 | No response body |

***

### 列出資料表 <a href="#undefined" id="undefined"></a>

GET `/api/sql-databases/{sqlDatabasePk}/tables/`

#### 參數

| 參數名稱            | 必填 | 類型      | 說明                                                                                                                                                      |
| --------------- | -- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `sqlDatabasePk` | ✅  | string  |                                                                                                                                                         |
| `page`          | ❌  | integer | A page number within the paginated result set.                                                                                                          |
| `pageSize`      | ❌  | integer | Number of results to return per page.                                                                                                                   |
| `query`         | ❌  | string  |                                                                                                                                                         |
| `status`        | ❌  | string  | \`pending\`: Pending ; \`processing\`: Processing ; \`success\`: Success ; \`failed\`: Failed ; \`dropping\`: Dropping ; \`drop\_failed\`: Drop Failed; |

#### 程式碼範例

{% tabs %}
{% tab title="Shell/Bash" %}

```bash
# 呼叫 API 示例 (Shell)
curl -X GET "https://api.maiagent.ai/api/sql-databases/{sqlDatabasePk}/tables/?page=1&pageSize=1&query=example&status=drop_failed" \
  -H "Authorization: Api-Key YOUR_API_KEY"

# 請確認在執行前替換 YOUR_API_KEY 並核對請求資料。
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
const axios = require('axios');

// 設定請求標頭
const config = {
  headers: {
    'Authorization': 'Api-Key YOUR_API_KEY'
  }
};

axios.get("https://api.maiagent.ai/api/sql-databases/{sqlDatabasePk}/tables/?page=1&pageSize=1&query=example&status=drop_failed", config)
  .then(response => {
    console.log('成功取得回應:');
    console.log(response.data);
  })
  .catch(error => {
    console.error('請求發生錯誤:');
    console.error(error.response?.data || error.message);
  });
```

{% endtab %}

{% tab title="Python" %}

```python
import requests

url = "https://api.maiagent.ai/api/sql-databases/{sqlDatabasePk}/tables/?page=1&pageSize=1&query=example&status=drop_failed"
headers = {
    "Authorization": "Api-Key YOUR_API_KEY"
}


response = requests.get(url, headers=headers)
try:
    print("成功取得回應:")
    print(response.json())
except Exception as e:
    print("請求發生錯誤:", e)
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php
require 'vendor/autoload.php';

$client = new GuzzleHttp\Client();

try {
    $response = $client->get("https://api.maiagent.ai/api/sql-databases/{sqlDatabasePk}/tables/?page=1&pageSize=1&query=example&status=drop_failed", [
        'headers' => [
            'Authorization' => 'Api-Key YOUR_API_KEY'
        ]
    ]);
    
    $data = json_decode($response->getBody(), true);
    echo "成功取得回應:\n";
    print_r($data);
} catch (Exception $e) {
    echo '請求發生錯誤: ' . $e->getMessage();
}
?>
```

{% endtab %}
{% endtabs %}

#### 回應內容

**狀態碼: 200**

**回應結構範例**

```typescript
{
  "count": integer
  "next"?: string (uri) // 非必填
  "previous"?: string (uri) // 非必填
  "results": [
    {
      "id": string (uuid)
      "tableName": string // Name of the table in the database
      "description"?: string // Description of the table and its data for better Text-to-SQL understanding (非必填)
      "status": 
      {
      }
      "errorMessage": string // Error details if table creation or deletion failed
      "sourceFile": 
      {
        "id": string (uuid)
        "name": string
        "isFromKnowledgeBase": boolean // Determine if the source file originated from a knowledge base upload.

Returns True if the file was uploaded via knowledge base,
False if uploaded directly to the database.
      }
      "columns": [
        {
          "id": string (uuid)
          "columnName": string
          "columnType"?: string // Data type of the column (e.g., VARCHAR, INTEGER, TIMESTAMP) (非必填)
          "description"?: string // Description of the column for better Text-to-SQL understanding (非必填)
          "isPrimaryKey"?: boolean // 非必填
          "isNullable"?: boolean // 非必填
          "createdAt": string (timestamp)
          "updatedAt": string (timestamp)
        }
      ]
      "createdAt": string (timestamp)
      "updatedAt": string (timestamp)
    }
  ]
}
```

**回應範例值**

```json
{
  "count": 123,
  "next": "http://api.example.org/accounts/?page=4",
  "previous": "http://api.example.org/accounts/?page=2",
  "results": [
    {
      "id": "550e8400-e29b-41d4-a716-446655440000",
      "tableName": "回應字串",
      "description": "回應字串",
      "status": {},
      "errorMessage": "回應字串",
      "sourceFile": {
        "id": "550e8400-e29b-41d4-a716-446655440000",
        "name": "回應字串",
        "isFromKnowledgeBase": false
      },
      "columns": [
        {
          "id": "550e8400-e29b-41d4-a716-446655440000",
          "columnName": "回應字串",
          "columnType": "回應字串",
          "description": "回應字串",
          "isPrimaryKey": false,
          "isNullable": false,
          "createdAt": "回應字串",
          "updatedAt": "回應字串"
        }
      ],
      "createdAt": "回應字串",
      "updatedAt": "回應字串"
    }
  ]
}
```

***

### 列出資料表 <a href="#undefined" id="undefined"></a>

GET `/api/v1/sql-databases/{sqlDatabasePk}/tables/`

#### 參數

| 參數名稱            | 必填 | 類型      | 說明                                                                                                                                                      |
| --------------- | -- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `sqlDatabasePk` | ✅  | string  |                                                                                                                                                         |
| `page`          | ❌  | integer | A page number within the paginated result set.                                                                                                          |
| `pageSize`      | ❌  | integer | Number of results to return per page.                                                                                                                   |
| `query`         | ❌  | string  |                                                                                                                                                         |
| `status`        | ❌  | string  | \`pending\`: Pending ; \`processing\`: Processing ; \`success\`: Success ; \`failed\`: Failed ; \`dropping\`: Dropping ; \`drop\_failed\`: Drop Failed; |

#### 程式碼範例

{% tabs %}
{% tab title="Shell/Bash" %}

```bash
# 呼叫 API 示例 (Shell)
curl -X GET "https://api.maiagent.ai/api/v1/sql-databases/{sqlDatabasePk}/tables/?page=1&pageSize=1&query=example&status=drop_failed" \
  -H "Authorization: Api-Key YOUR_API_KEY"

# 請確認在執行前替換 YOUR_API_KEY 並核對請求資料。
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
const axios = require('axios');

// 設定請求標頭
const config = {
  headers: {
    'Authorization': 'Api-Key YOUR_API_KEY'
  }
};

axios.get("https://api.maiagent.ai/api/v1/sql-databases/{sqlDatabasePk}/tables/?page=1&pageSize=1&query=example&status=drop_failed", config)
  .then(response => {
    console.log('成功取得回應:');
    console.log(response.data);
  })
  .catch(error => {
    console.error('請求發生錯誤:');
    console.error(error.response?.data || error.message);
  });
```

{% endtab %}

{% tab title="Python" %}

```python
import requests

url = "https://api.maiagent.ai/api/v1/sql-databases/{sqlDatabasePk}/tables/?page=1&pageSize=1&query=example&status=drop_failed"
headers = {
    "Authorization": "Api-Key YOUR_API_KEY"
}


response = requests.get(url, headers=headers)
try:
    print("成功取得回應:")
    print(response.json())
except Exception as e:
    print("請求發生錯誤:", e)
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php
require 'vendor/autoload.php';

$client = new GuzzleHttp\Client();

try {
    $response = $client->get("https://api.maiagent.ai/api/v1/sql-databases/{sqlDatabasePk}/tables/?page=1&pageSize=1&query=example&status=drop_failed", [
        'headers' => [
            'Authorization' => 'Api-Key YOUR_API_KEY'
        ]
    ]);
    
    $data = json_decode($response->getBody(), true);
    echo "成功取得回應:\n";
    print_r($data);
} catch (Exception $e) {
    echo '請求發生錯誤: ' . $e->getMessage();
}
?>
```

{% endtab %}
{% endtabs %}

#### 回應內容

**狀態碼: 200**

**回應結構範例**

```typescript
{
  "count": integer
  "next"?: string (uri) // 非必填
  "previous"?: string (uri) // 非必填
  "results": [
    {
      "id": string (uuid)
      "tableName": string // Name of the table in the database
      "description"?: string // Description of the table and its data for better Text-to-SQL understanding (非必填)
      "status": 
      {
      }
      "errorMessage": string // Error details if table creation or deletion failed
      "sourceFile": 
      {
        "id": string (uuid)
        "name": string
        "isFromKnowledgeBase": boolean // Determine if the source file originated from a knowledge base upload.

Returns True if the file was uploaded via knowledge base,
False if uploaded directly to the database.
      }
      "columns": [
        {
          "id": string (uuid)
          "columnName": string
          "columnType"?: string // Data type of the column (e.g., VARCHAR, INTEGER, TIMESTAMP) (非必填)
          "description"?: string // Description of the column for better Text-to-SQL understanding (非必填)
          "isPrimaryKey"?: boolean // 非必填
          "isNullable"?: boolean // 非必填
          "createdAt": string (timestamp)
          "updatedAt": string (timestamp)
        }
      ]
      "createdAt": string (timestamp)
      "updatedAt": string (timestamp)
    }
  ]
}
```

**回應範例值**

```json
{
  "count": 123,
  "next": "http://api.example.org/accounts/?page=4",
  "previous": "http://api.example.org/accounts/?page=2",
  "results": [
    {
      "id": "550e8400-e29b-41d4-a716-446655440000",
      "tableName": "回應字串",
      "description": "回應字串",
      "status": {},
      "errorMessage": "回應字串",
      "sourceFile": {
        "id": "550e8400-e29b-41d4-a716-446655440000",
        "name": "回應字串",
        "isFromKnowledgeBase": false
      },
      "columns": [
        {
          "id": "550e8400-e29b-41d4-a716-446655440000",
          "columnName": "回應字串",
          "columnType": "回應字串",
          "description": "回應字串",
          "isPrimaryKey": false,
          "isNullable": false,
          "createdAt": "回應字串",
          "updatedAt": "回應字串"
        }
      ],
      "createdAt": "回應字串",
      "updatedAt": "回應字串"
    }
  ]
}
```

***

### 建立資料表 <a href="#undefined" id="undefined"></a>

POST `/api/sql-databases/{sqlDatabasePk}/tables/`

#### 參數

| 參數名稱            | 必填 | 類型     | 說明 |
| --------------- | -- | ------ | -- |
| `sqlDatabasePk` | ✅  | string |    |

#### 請求內容

**請求參數**

| 欄位          | 類型     | 必填 | 說明                                                                         |
| ----------- | ------ | -- | -------------------------------------------------------------------------- |
| tableName   | string | 是  | Name of the table in the database                                          |
| description | string | 否  | Description of the table and its data for better Text-to-SQL understanding |

**請求結構範例**

```typescript
{
  "tableName": string // Name of the table in the database
  "description"?: string // Description of the table and its data for better Text-to-SQL understanding (非必填)
}
```

**請求範例值**

```json
{
  "tableName": "範例字串",
  "description": "範例字串"
}
```

#### 程式碼範例

{% tabs %}
{% tab title="Shell/Bash" %}

```bash
# 呼叫 API 示例 (Shell)
curl -X POST "https://api.maiagent.ai/api/sql-databases/{sqlDatabasePk}/tables/" \
  -H "Authorization: Api-Key YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "tableName": "範例字串",
    "description": "範例字串"
  }'

# 請確認在執行前替換 YOUR_API_KEY 並核對請求資料。
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
const axios = require('axios');

// 設定請求標頭
const config = {
  headers: {
    'Authorization': 'Api-Key YOUR_API_KEY',
    'Content-Type': 'application/json'
  }
};

// 請求內容 (payload)
const data = {
    "tableName": "範例字串",
    "description": "範例字串"
  };

axios.post("https://api.maiagent.ai/api/sql-databases/{sqlDatabasePk}/tables/", data, config)
  .then(response => {
    console.log('成功取得回應:');
    console.log(response.data);
  })
  .catch(error => {
    console.error('請求發生錯誤:');
    console.error(error.response?.data || error.message);
  });
```

{% endtab %}

{% tab title="Python" %}

```python
import requests

url = "https://api.maiagent.ai/api/sql-databases/{sqlDatabasePk}/tables/"
headers = {
    "Authorization": "Api-Key YOUR_API_KEY",
    "Content-Type": "application/json"
}

# 請求內容 (payload)
data = {
      "tableName": "範例字串",
      "description": "範例字串"
    }

response = requests.post(url, json=data, headers=headers)
try:
    print("成功取得回應:")
    print(response.json())
except Exception as e:
    print("請求發生錯誤:", e)
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php
require 'vendor/autoload.php';

$client = new GuzzleHttp\Client();

try {
    $response = $client->post("https://api.maiagent.ai/api/sql-databases/{sqlDatabasePk}/tables/", [
        'headers' => [
            'Authorization' => 'Api-Key YOUR_API_KEY',
            'Content-Type' => 'application/json'
        ],
        'json' => {
            "tableName": "範例字串",
            "description": "範例字串"
        }
    ]);
    
    $data = json_decode($response->getBody(), true);
    echo "成功取得回應:\n";
    print_r($data);
} catch (Exception $e) {
    echo '請求發生錯誤: ' . $e->getMessage();
}
?>
```

{% endtab %}
{% endtabs %}

#### 回應內容

**狀態碼: 201**

**回應結構範例**

```typescript
{
  "id": string (uuid)
  "tableName": string // Name of the table in the database
  "description"?: string // Description of the table and its data for better Text-to-SQL understanding (非必填)
  "status": 
  {
  }
  "errorMessage": string // Error details if table creation or deletion failed
  "sourceFile": 
  {
    "id": string (uuid)
    "name": string
    "isFromKnowledgeBase": boolean // Determine if the source file originated from a knowledge base upload.

Returns True if the file was uploaded via knowledge base,
False if uploaded directly to the database.
  }
  "columns": [
    {
      "id": string (uuid)
      "columnName": string
      "columnType"?: string // Data type of the column (e.g., VARCHAR, INTEGER, TIMESTAMP) (非必填)
      "description"?: string // Description of the column for better Text-to-SQL understanding (非必填)
      "isPrimaryKey"?: boolean // 非必填
      "isNullable"?: boolean // 非必填
      "createdAt": string (timestamp)
      "updatedAt": string (timestamp)
    }
  ]
  "createdAt": string (timestamp)
  "updatedAt": string (timestamp)
}
```

**回應範例值**

```json
{
  "id": "550e8400-e29b-41d4-a716-446655440000",
  "tableName": "回應字串",
  "description": "回應字串",
  "status": {},
  "errorMessage": "回應字串",
  "sourceFile": {
    "id": "550e8400-e29b-41d4-a716-446655440000",
    "name": "回應字串",
    "isFromKnowledgeBase": false
  },
  "columns": [
    {
      "id": "550e8400-e29b-41d4-a716-446655440000",
      "columnName": "回應字串",
      "columnType": "回應字串",
      "description": "回應字串",
      "isPrimaryKey": false,
      "isNullable": false,
      "createdAt": "回應字串",
      "updatedAt": "回應字串"
    }
  ],
  "createdAt": "回應字串",
  "updatedAt": "回應字串"
}
```

***

### 建立資料表 <a href="#undefined" id="undefined"></a>

POST `/api/v1/sql-databases/{sqlDatabasePk}/tables/`

#### 參數

| 參數名稱            | 必填 | 類型     | 說明 |
| --------------- | -- | ------ | -- |
| `sqlDatabasePk` | ✅  | string |    |

#### 請求內容

**請求參數**

| 欄位          | 類型     | 必填 | 說明                                                                         |
| ----------- | ------ | -- | -------------------------------------------------------------------------- |
| tableName   | string | 是  | Name of the table in the database                                          |
| description | string | 否  | Description of the table and its data for better Text-to-SQL understanding |

**請求結構範例**

```typescript
{
  "tableName": string // Name of the table in the database
  "description"?: string // Description of the table and its data for better Text-to-SQL understanding (非必填)
}
```

**請求範例值**

```json
{
  "tableName": "範例字串",
  "description": "範例字串"
}
```

#### 程式碼範例

{% tabs %}
{% tab title="Shell/Bash" %}

```bash
# 呼叫 API 示例 (Shell)
curl -X POST "https://api.maiagent.ai/api/v1/sql-databases/{sqlDatabasePk}/tables/" \
  -H "Authorization: Api-Key YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "tableName": "範例字串",
    "description": "範例字串"
  }'

# 請確認在執行前替換 YOUR_API_KEY 並核對請求資料。
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
const axios = require('axios');

// 設定請求標頭
const config = {
  headers: {
    'Authorization': 'Api-Key YOUR_API_KEY',
    'Content-Type': 'application/json'
  }
};

// 請求內容 (payload)
const data = {
    "tableName": "範例字串",
    "description": "範例字串"
  };

axios.post("https://api.maiagent.ai/api/v1/sql-databases/{sqlDatabasePk}/tables/", data, config)
  .then(response => {
    console.log('成功取得回應:');
    console.log(response.data);
  })
  .catch(error => {
    console.error('請求發生錯誤:');
    console.error(error.response?.data || error.message);
  });
```

{% endtab %}

{% tab title="Python" %}

```python
import requests

url = "https://api.maiagent.ai/api/v1/sql-databases/{sqlDatabasePk}/tables/"
headers = {
    "Authorization": "Api-Key YOUR_API_KEY",
    "Content-Type": "application/json"
}

# 請求內容 (payload)
data = {
      "tableName": "範例字串",
      "description": "範例字串"
    }

response = requests.post(url, json=data, headers=headers)
try:
    print("成功取得回應:")
    print(response.json())
except Exception as e:
    print("請求發生錯誤:", e)
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php
require 'vendor/autoload.php';

$client = new GuzzleHttp\Client();

try {
    $response = $client->post("https://api.maiagent.ai/api/v1/sql-databases/{sqlDatabasePk}/tables/", [
        'headers' => [
            'Authorization' => 'Api-Key YOUR_API_KEY',
            'Content-Type' => 'application/json'
        ],
        'json' => {
            "tableName": "範例字串",
            "description": "範例字串"
        }
    ]);
    
    $data = json_decode($response->getBody(), true);
    echo "成功取得回應:\n";
    print_r($data);
} catch (Exception $e) {
    echo '請求發生錯誤: ' . $e->getMessage();
}
?>
```

{% endtab %}
{% endtabs %}

#### 回應內容

**狀態碼: 201**

**回應結構範例**

```typescript
{
  "id": string (uuid)
  "tableName": string // Name of the table in the database
  "description"?: string // Description of the table and its data for better Text-to-SQL understanding (非必填)
  "status": 
  {
  }
  "errorMessage": string // Error details if table creation or deletion failed
  "sourceFile": 
  {
    "id": string (uuid)
    "name": string
    "isFromKnowledgeBase": boolean // Determine if the source file originated from a knowledge base upload.

Returns True if the file was uploaded via knowledge base,
False if uploaded directly to the database.
  }
  "columns": [
    {
      "id": string (uuid)
      "columnName": string
      "columnType"?: string // Data type of the column (e.g., VARCHAR, INTEGER, TIMESTAMP) (非必填)
      "description"?: string // Description of the column for better Text-to-SQL understanding (非必填)
      "isPrimaryKey"?: boolean // 非必填
      "isNullable"?: boolean // 非必填
      "createdAt": string (timestamp)
      "updatedAt": string (timestamp)
    }
  ]
  "createdAt": string (timestamp)
  "updatedAt": string (timestamp)
}
```

**回應範例值**

```json
{
  "id": "550e8400-e29b-41d4-a716-446655440000",
  "tableName": "回應字串",
  "description": "回應字串",
  "status": {},
  "errorMessage": "回應字串",
  "sourceFile": {
    "id": "550e8400-e29b-41d4-a716-446655440000",
    "name": "回應字串",
    "isFromKnowledgeBase": false
  },
  "columns": [
    {
      "id": "550e8400-e29b-41d4-a716-446655440000",
      "columnName": "回應字串",
      "columnType": "回應字串",
      "description": "回應字串",
      "isPrimaryKey": false,
      "isNullable": false,
      "createdAt": "回應字串",
      "updatedAt": "回應字串"
    }
  ],
  "createdAt": "回應字串",
  "updatedAt": "回應字串"
}
```

***

### 取得特定資料表 <a href="#undefined" id="undefined"></a>

GET `/api/sql-databases/{sqlDatabasePk}/tables/{id}/`

#### 參數

| 參數名稱            | 必填 | 類型     | 說明                                             |
| --------------- | -- | ------ | ---------------------------------------------- |
| `id`            | ✅  | string | A UUID string identifying this Database Table. |
| `sqlDatabasePk` | ✅  | string |                                                |

#### 程式碼範例

{% tabs %}
{% tab title="Shell/Bash" %}

```bash
# 呼叫 API 示例 (Shell)
curl -X GET "https://api.maiagent.ai/api/sql-databases/{sqlDatabasePk}/tables/550e8400-e29b-41d4-a716-446655440000/" \
  -H "Authorization: Api-Key YOUR_API_KEY"

# 請確認在執行前替換 YOUR_API_KEY 並核對請求資料。
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
const axios = require('axios');

// 設定請求標頭
const config = {
  headers: {
    'Authorization': 'Api-Key YOUR_API_KEY'
  }
};

axios.get("https://api.maiagent.ai/api/sql-databases/{sqlDatabasePk}/tables/550e8400-e29b-41d4-a716-446655440000/", config)
  .then(response => {
    console.log('成功取得回應:');
    console.log(response.data);
  })
  .catch(error => {
    console.error('請求發生錯誤:');
    console.error(error.response?.data || error.message);
  });
```

{% endtab %}

{% tab title="Python" %}

```python
import requests

url = "https://api.maiagent.ai/api/sql-databases/{sqlDatabasePk}/tables/550e8400-e29b-41d4-a716-446655440000/"
headers = {
    "Authorization": "Api-Key YOUR_API_KEY"
}


response = requests.get(url, headers=headers)
try:
    print("成功取得回應:")
    print(response.json())
except Exception as e:
    print("請求發生錯誤:", e)
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php
require 'vendor/autoload.php';

$client = new GuzzleHttp\Client();

try {
    $response = $client->get("https://api.maiagent.ai/api/sql-databases/{sqlDatabasePk}/tables/550e8400-e29b-41d4-a716-446655440000/", [
        'headers' => [
            'Authorization' => 'Api-Key YOUR_API_KEY'
        ]
    ]);
    
    $data = json_decode($response->getBody(), true);
    echo "成功取得回應:\n";
    print_r($data);
} catch (Exception $e) {
    echo '請求發生錯誤: ' . $e->getMessage();
}
?>
```

{% endtab %}
{% endtabs %}

#### 回應內容

**狀態碼: 200**

**回應結構範例**

```typescript
{
  "id": string (uuid)
  "tableName": string // Name of the table in the database
  "description"?: string // Description of the table and its data for better Text-to-SQL understanding (非必填)
  "status": 
  {
  }
  "errorMessage": string // Error details if table creation or deletion failed
  "sourceFile": 
  {
    "id": string (uuid)
    "name": string
    "isFromKnowledgeBase": boolean // Determine if the source file originated from a knowledge base upload.

Returns True if the file was uploaded via knowledge base,
False if uploaded directly to the database.
  }
  "columns": [
    {
      "id": string (uuid)
      "columnName": string
      "columnType"?: string // Data type of the column (e.g., VARCHAR, INTEGER, TIMESTAMP) (非必填)
      "description"?: string // Description of the column for better Text-to-SQL understanding (非必填)
      "isPrimaryKey"?: boolean // 非必填
      "isNullable"?: boolean // 非必填
      "createdAt": string (timestamp)
      "updatedAt": string (timestamp)
    }
  ]
  "createdAt": string (timestamp)
  "updatedAt": string (timestamp)
}
```

**回應範例值**

```json
{
  "id": "550e8400-e29b-41d4-a716-446655440000",
  "tableName": "回應字串",
  "description": "回應字串",
  "status": {},
  "errorMessage": "回應字串",
  "sourceFile": {
    "id": "550e8400-e29b-41d4-a716-446655440000",
    "name": "回應字串",
    "isFromKnowledgeBase": false
  },
  "columns": [
    {
      "id": "550e8400-e29b-41d4-a716-446655440000",
      "columnName": "回應字串",
      "columnType": "回應字串",
      "description": "回應字串",
      "isPrimaryKey": false,
      "isNullable": false,
      "createdAt": "回應字串",
      "updatedAt": "回應字串"
    }
  ],
  "createdAt": "回應字串",
  "updatedAt": "回應字串"
}
```

***

### 取得特定資料表 <a href="#undefined" id="undefined"></a>

GET `/api/v1/sql-databases/{sqlDatabasePk}/tables/{id}/`

#### 參數

| 參數名稱            | 必填 | 類型     | 說明                                             |
| --------------- | -- | ------ | ---------------------------------------------- |
| `id`            | ✅  | string | A UUID string identifying this Database Table. |
| `sqlDatabasePk` | ✅  | string |                                                |

#### 程式碼範例

{% tabs %}
{% tab title="Shell/Bash" %}

```bash
# 呼叫 API 示例 (Shell)
curl -X GET "https://api.maiagent.ai/api/v1/sql-databases/{sqlDatabasePk}/tables/550e8400-e29b-41d4-a716-446655440000/" \
  -H "Authorization: Api-Key YOUR_API_KEY"

# 請確認在執行前替換 YOUR_API_KEY 並核對請求資料。
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
const axios = require('axios');

// 設定請求標頭
const config = {
  headers: {
    'Authorization': 'Api-Key YOUR_API_KEY'
  }
};

axios.get("https://api.maiagent.ai/api/v1/sql-databases/{sqlDatabasePk}/tables/550e8400-e29b-41d4-a716-446655440000/", config)
  .then(response => {
    console.log('成功取得回應:');
    console.log(response.data);
  })
  .catch(error => {
    console.error('請求發生錯誤:');
    console.error(error.response?.data || error.message);
  });
```

{% endtab %}

{% tab title="Python" %}

```python
import requests

url = "https://api.maiagent.ai/api/v1/sql-databases/{sqlDatabasePk}/tables/550e8400-e29b-41d4-a716-446655440000/"
headers = {
    "Authorization": "Api-Key YOUR_API_KEY"
}


response = requests.get(url, headers=headers)
try:
    print("成功取得回應:")
    print(response.json())
except Exception as e:
    print("請求發生錯誤:", e)
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php
require 'vendor/autoload.php';

$client = new GuzzleHttp\Client();

try {
    $response = $client->get("https://api.maiagent.ai/api/v1/sql-databases/{sqlDatabasePk}/tables/550e8400-e29b-41d4-a716-446655440000/", [
        'headers' => [
            'Authorization' => 'Api-Key YOUR_API_KEY'
        ]
    ]);
    
    $data = json_decode($response->getBody(), true);
    echo "成功取得回應:\n";
    print_r($data);
} catch (Exception $e) {
    echo '請求發生錯誤: ' . $e->getMessage();
}
?>
```

{% endtab %}
{% endtabs %}

#### 回應內容

**狀態碼: 200**

**回應結構範例**

```typescript
{
  "id": string (uuid)
  "tableName": string // Name of the table in the database
  "description"?: string // Description of the table and its data for better Text-to-SQL understanding (非必填)
  "status": 
  {
  }
  "errorMessage": string // Error details if table creation or deletion failed
  "sourceFile": 
  {
    "id": string (uuid)
    "name": string
    "isFromKnowledgeBase": boolean // Determine if the source file originated from a knowledge base upload.

Returns True if the file was uploaded via knowledge base,
False if uploaded directly to the database.
  }
  "columns": [
    {
      "id": string (uuid)
      "columnName": string
      "columnType"?: string // Data type of the column (e.g., VARCHAR, INTEGER, TIMESTAMP) (非必填)
      "description"?: string // Description of the column for better Text-to-SQL understanding (非必填)
      "isPrimaryKey"?: boolean // 非必填
      "isNullable"?: boolean // 非必填
      "createdAt": string (timestamp)
      "updatedAt": string (timestamp)
    }
  ]
  "createdAt": string (timestamp)
  "updatedAt": string (timestamp)
}
```

**回應範例值**

```json
{
  "id": "550e8400-e29b-41d4-a716-446655440000",
  "tableName": "回應字串",
  "description": "回應字串",
  "status": {},
  "errorMessage": "回應字串",
  "sourceFile": {
    "id": "550e8400-e29b-41d4-a716-446655440000",
    "name": "回應字串",
    "isFromKnowledgeBase": false
  },
  "columns": [
    {
      "id": "550e8400-e29b-41d4-a716-446655440000",
      "columnName": "回應字串",
      "columnType": "回應字串",
      "description": "回應字串",
      "isPrimaryKey": false,
      "isNullable": false,
      "createdAt": "回應字串",
      "updatedAt": "回應字串"
    }
  ],
  "createdAt": "回應字串",
  "updatedAt": "回應字串"
}
```

***

### 更新資料表 <a href="#undefined" id="undefined"></a>

PUT `/api/sql-databases/{sqlDatabasePk}/tables/{id}/`

#### 參數

| 參數名稱            | 必填 | 類型     | 說明                                             |
| --------------- | -- | ------ | ---------------------------------------------- |
| `id`            | ✅  | string | A UUID string identifying this Database Table. |
| `sqlDatabasePk` | ✅  | string |                                                |

#### 請求內容

**請求參數**

| 欄位          | 類型     | 必填 | 說明                                                                         |
| ----------- | ------ | -- | -------------------------------------------------------------------------- |
| tableName   | string | 是  | Name of the table in the database                                          |
| description | string | 否  | Description of the table and its data for better Text-to-SQL understanding |

**請求結構範例**

```typescript
{
  "tableName": string // Name of the table in the database
  "description"?: string // Description of the table and its data for better Text-to-SQL understanding (非必填)
}
```

**請求範例值**

```json
{
  "tableName": "範例字串",
  "description": "範例字串"
}
```

#### 程式碼範例

{% tabs %}
{% tab title="Shell/Bash" %}

```bash
# 呼叫 API 示例 (Shell)
curl -X PUT "https://api.maiagent.ai/api/sql-databases/{sqlDatabasePk}/tables/550e8400-e29b-41d4-a716-446655440000/" \
  -H "Authorization: Api-Key YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "tableName": "範例字串",
    "description": "範例字串"
  }'

# 請確認在執行前替換 YOUR_API_KEY 並核對請求資料。
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
const axios = require('axios');

// 設定請求標頭
const config = {
  headers: {
    'Authorization': 'Api-Key YOUR_API_KEY',
    'Content-Type': 'application/json'
  }
};

// 請求內容 (payload)
const data = {
    "tableName": "範例字串",
    "description": "範例字串"
  };

axios.put("https://api.maiagent.ai/api/sql-databases/{sqlDatabasePk}/tables/550e8400-e29b-41d4-a716-446655440000/", data, config)
  .then(response => {
    console.log('成功取得回應:');
    console.log(response.data);
  })
  .catch(error => {
    console.error('請求發生錯誤:');
    console.error(error.response?.data || error.message);
  });
```

{% endtab %}

{% tab title="Python" %}

```python
import requests

url = "https://api.maiagent.ai/api/sql-databases/{sqlDatabasePk}/tables/550e8400-e29b-41d4-a716-446655440000/"
headers = {
    "Authorization": "Api-Key YOUR_API_KEY",
    "Content-Type": "application/json"
}

# 請求內容 (payload)
data = {
      "tableName": "範例字串",
      "description": "範例字串"
    }

response = requests.put(url, json=data, headers=headers)
try:
    print("成功取得回應:")
    print(response.json())
except Exception as e:
    print("請求發生錯誤:", e)
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php
require 'vendor/autoload.php';

$client = new GuzzleHttp\Client();

try {
    $response = $client->put("https://api.maiagent.ai/api/sql-databases/{sqlDatabasePk}/tables/550e8400-e29b-41d4-a716-446655440000/", [
        'headers' => [
            'Authorization' => 'Api-Key YOUR_API_KEY',
            'Content-Type' => 'application/json'
        ],
        'json' => {
            "tableName": "範例字串",
            "description": "範例字串"
        }
    ]);
    
    $data = json_decode($response->getBody(), true);
    echo "成功取得回應:\n";
    print_r($data);
} catch (Exception $e) {
    echo '請求發生錯誤: ' . $e->getMessage();
}
?>
```

{% endtab %}
{% endtabs %}

#### 回應內容

**狀態碼: 200**

**回應結構範例**

```typescript
{
  "id": string (uuid)
  "tableName": string // Name of the table in the database
  "description"?: string // Description of the table and its data for better Text-to-SQL understanding (非必填)
  "status": 
  {
  }
  "errorMessage": string // Error details if table creation or deletion failed
  "sourceFile": 
  {
    "id": string (uuid)
    "name": string
    "isFromKnowledgeBase": boolean // Determine if the source file originated from a knowledge base upload.

Returns True if the file was uploaded via knowledge base,
False if uploaded directly to the database.
  }
  "columns": [
    {
      "id": string (uuid)
      "columnName": string
      "columnType"?: string // Data type of the column (e.g., VARCHAR, INTEGER, TIMESTAMP) (非必填)
      "description"?: string // Description of the column for better Text-to-SQL understanding (非必填)
      "isPrimaryKey"?: boolean // 非必填
      "isNullable"?: boolean // 非必填
      "createdAt": string (timestamp)
      "updatedAt": string (timestamp)
    }
  ]
  "createdAt": string (timestamp)
  "updatedAt": string (timestamp)
}
```

**回應範例值**

```json
{
  "id": "550e8400-e29b-41d4-a716-446655440000",
  "tableName": "回應字串",
  "description": "回應字串",
  "status": {},
  "errorMessage": "回應字串",
  "sourceFile": {
    "id": "550e8400-e29b-41d4-a716-446655440000",
    "name": "回應字串",
    "isFromKnowledgeBase": false
  },
  "columns": [
    {
      "id": "550e8400-e29b-41d4-a716-446655440000",
      "columnName": "回應字串",
      "columnType": "回應字串",
      "description": "回應字串",
      "isPrimaryKey": false,
      "isNullable": false,
      "createdAt": "回應字串",
      "updatedAt": "回應字串"
    }
  ],
  "createdAt": "回應字串",
  "updatedAt": "回應字串"
}
```

***

### 更新資料表 <a href="#undefined" id="undefined"></a>

PUT `/api/v1/sql-databases/{sqlDatabasePk}/tables/{id}/`

#### 參數

| 參數名稱            | 必填 | 類型     | 說明                                             |
| --------------- | -- | ------ | ---------------------------------------------- |
| `id`            | ✅  | string | A UUID string identifying this Database Table. |
| `sqlDatabasePk` | ✅  | string |                                                |

#### 請求內容

**請求參數**

| 欄位          | 類型     | 必填 | 說明                                                                         |
| ----------- | ------ | -- | -------------------------------------------------------------------------- |
| tableName   | string | 是  | Name of the table in the database                                          |
| description | string | 否  | Description of the table and its data for better Text-to-SQL understanding |

**請求結構範例**

```typescript
{
  "tableName": string // Name of the table in the database
  "description"?: string // Description of the table and its data for better Text-to-SQL understanding (非必填)
}
```

**請求範例值**

```json
{
  "tableName": "範例字串",
  "description": "範例字串"
}
```

#### 程式碼範例

{% tabs %}
{% tab title="Shell/Bash" %}

```bash
# 呼叫 API 示例 (Shell)
curl -X PUT "https://api.maiagent.ai/api/v1/sql-databases/{sqlDatabasePk}/tables/550e8400-e29b-41d4-a716-446655440000/" \
  -H "Authorization: Api-Key YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "tableName": "範例字串",
    "description": "範例字串"
  }'

# 請確認在執行前替換 YOUR_API_KEY 並核對請求資料。
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
const axios = require('axios');

// 設定請求標頭
const config = {
  headers: {
    'Authorization': 'Api-Key YOUR_API_KEY',
    'Content-Type': 'application/json'
  }
};

// 請求內容 (payload)
const data = {
    "tableName": "範例字串",
    "description": "範例字串"
  };

axios.put("https://api.maiagent.ai/api/v1/sql-databases/{sqlDatabasePk}/tables/550e8400-e29b-41d4-a716-446655440000/", data, config)
  .then(response => {
    console.log('成功取得回應:');
    console.log(response.data);
  })
  .catch(error => {
    console.error('請求發生錯誤:');
    console.error(error.response?.data || error.message);
  });
```

{% endtab %}

{% tab title="Python" %}

```python
import requests

url = "https://api.maiagent.ai/api/v1/sql-databases/{sqlDatabasePk}/tables/550e8400-e29b-41d4-a716-446655440000/"
headers = {
    "Authorization": "Api-Key YOUR_API_KEY",
    "Content-Type": "application/json"
}

# 請求內容 (payload)
data = {
      "tableName": "範例字串",
      "description": "範例字串"
    }

response = requests.put(url, json=data, headers=headers)
try:
    print("成功取得回應:")
    print(response.json())
except Exception as e:
    print("請求發生錯誤:", e)
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php
require 'vendor/autoload.php';

$client = new GuzzleHttp\Client();

try {
    $response = $client->put("https://api.maiagent.ai/api/v1/sql-databases/{sqlDatabasePk}/tables/550e8400-e29b-41d4-a716-446655440000/", [
        'headers' => [
            'Authorization' => 'Api-Key YOUR_API_KEY',
            'Content-Type' => 'application/json'
        ],
        'json' => {
            "tableName": "範例字串",
            "description": "範例字串"
        }
    ]);
    
    $data = json_decode($response->getBody(), true);
    echo "成功取得回應:\n";
    print_r($data);
} catch (Exception $e) {
    echo '請求發生錯誤: ' . $e->getMessage();
}
?>
```

{% endtab %}
{% endtabs %}

#### 回應內容

**狀態碼: 200**

**回應結構範例**

```typescript
{
  "id": string (uuid)
  "tableName": string // Name of the table in the database
  "description"?: string // Description of the table and its data for better Text-to-SQL understanding (非必填)
  "status": 
  {
  }
  "errorMessage": string // Error details if table creation or deletion failed
  "sourceFile": 
  {
    "id": string (uuid)
    "name": string
    "isFromKnowledgeBase": boolean // Determine if the source file originated from a knowledge base upload.

Returns True if the file was uploaded via knowledge base,
False if uploaded directly to the database.
  }
  "columns": [
    {
      "id": string (uuid)
      "columnName": string
      "columnType"?: string // Data type of the column (e.g., VARCHAR, INTEGER, TIMESTAMP) (非必填)
      "description"?: string // Description of the column for better Text-to-SQL understanding (非必填)
      "isPrimaryKey"?: boolean // 非必填
      "isNullable"?: boolean // 非必填
      "createdAt": string (timestamp)
      "updatedAt": string (timestamp)
    }
  ]
  "createdAt": string (timestamp)
  "updatedAt": string (timestamp)
}
```

**回應範例值**

```json
{
  "id": "550e8400-e29b-41d4-a716-446655440000",
  "tableName": "回應字串",
  "description": "回應字串",
  "status": {},
  "errorMessage": "回應字串",
  "sourceFile": {
    "id": "550e8400-e29b-41d4-a716-446655440000",
    "name": "回應字串",
    "isFromKnowledgeBase": false
  },
  "columns": [
    {
      "id": "550e8400-e29b-41d4-a716-446655440000",
      "columnName": "回應字串",
      "columnType": "回應字串",
      "description": "回應字串",
      "isPrimaryKey": false,
      "isNullable": false,
      "createdAt": "回應字串",
      "updatedAt": "回應字串"
    }
  ],
  "createdAt": "回應字串",
  "updatedAt": "回應字串"
}
```

***

### 部分更新資料表 <a href="#undefined" id="undefined"></a>

PATCH `/api/sql-databases/{sqlDatabasePk}/tables/{id}/`

#### 參數

| 參數名稱            | 必填 | 類型     | 說明                                             |
| --------------- | -- | ------ | ---------------------------------------------- |
| `id`            | ✅  | string | A UUID string identifying this Database Table. |
| `sqlDatabasePk` | ✅  | string |                                                |

#### 請求內容

**請求參數**

| 欄位          | 類型     | 必填 | 說明                                                                         |
| ----------- | ------ | -- | -------------------------------------------------------------------------- |
| tableName   | string | 否  | Name of the table in the database                                          |
| description | string | 否  | Description of the table and its data for better Text-to-SQL understanding |

**請求結構範例**

```typescript
{
  "tableName"?: string // Name of the table in the database (非必填)
  "description"?: string // Description of the table and its data for better Text-to-SQL understanding (非必填)
}
```

**請求範例值**

```json
{
  "tableName": "範例字串",
  "description": "範例字串"
}
```

#### 程式碼範例

{% tabs %}
{% tab title="Shell/Bash" %}

```bash
# 呼叫 API 示例 (Shell)
curl -X PATCH "https://api.maiagent.ai/api/sql-databases/{sqlDatabasePk}/tables/550e8400-e29b-41d4-a716-446655440000/" \
  -H "Authorization: Api-Key YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "tableName": "範例字串",
    "description": "範例字串"
  }'

# 請確認在執行前替換 YOUR_API_KEY 並核對請求資料。
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
const axios = require('axios');

// 設定請求標頭
const config = {
  headers: {
    'Authorization': 'Api-Key YOUR_API_KEY',
    'Content-Type': 'application/json'
  }
};

// 請求內容 (payload)
const data = {
    "tableName": "範例字串",
    "description": "範例字串"
  };

axios.patch("https://api.maiagent.ai/api/sql-databases/{sqlDatabasePk}/tables/550e8400-e29b-41d4-a716-446655440000/", data, config)
  .then(response => {
    console.log('成功取得回應:');
    console.log(response.data);
  })
  .catch(error => {
    console.error('請求發生錯誤:');
    console.error(error.response?.data || error.message);
  });
```

{% endtab %}

{% tab title="Python" %}

```python
import requests

url = "https://api.maiagent.ai/api/sql-databases/{sqlDatabasePk}/tables/550e8400-e29b-41d4-a716-446655440000/"
headers = {
    "Authorization": "Api-Key YOUR_API_KEY",
    "Content-Type": "application/json"
}

# 請求內容 (payload)
data = {
      "tableName": "範例字串",
      "description": "範例字串"
    }

response = requests.patch(url, json=data, headers=headers)
try:
    print("成功取得回應:")
    print(response.json())
except Exception as e:
    print("請求發生錯誤:", e)
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php
require 'vendor/autoload.php';

$client = new GuzzleHttp\Client();

try {
    $response = $client->patch("https://api.maiagent.ai/api/sql-databases/{sqlDatabasePk}/tables/550e8400-e29b-41d4-a716-446655440000/", [
        'headers' => [
            'Authorization' => 'Api-Key YOUR_API_KEY',
            'Content-Type' => 'application/json'
        ],
        'json' => {
            "tableName": "範例字串",
            "description": "範例字串"
        }
    ]);
    
    $data = json_decode($response->getBody(), true);
    echo "成功取得回應:\n";
    print_r($data);
} catch (Exception $e) {
    echo '請求發生錯誤: ' . $e->getMessage();
}
?>
```

{% endtab %}
{% endtabs %}

#### 回應內容

**狀態碼: 200**

**回應結構範例**

```typescript
{
  "id": string (uuid)
  "tableName": string // Name of the table in the database
  "description"?: string // Description of the table and its data for better Text-to-SQL understanding (非必填)
  "status": 
  {
  }
  "errorMessage": string // Error details if table creation or deletion failed
  "sourceFile": 
  {
    "id": string (uuid)
    "name": string
    "isFromKnowledgeBase": boolean // Determine if the source file originated from a knowledge base upload.

Returns True if the file was uploaded via knowledge base,
False if uploaded directly to the database.
  }
  "columns": [
    {
      "id": string (uuid)
      "columnName": string
      "columnType"?: string // Data type of the column (e.g., VARCHAR, INTEGER, TIMESTAMP) (非必填)
      "description"?: string // Description of the column for better Text-to-SQL understanding (非必填)
      "isPrimaryKey"?: boolean // 非必填
      "isNullable"?: boolean // 非必填
      "createdAt": string (timestamp)
      "updatedAt": string (timestamp)
    }
  ]
  "createdAt": string (timestamp)
  "updatedAt": string (timestamp)
}
```

**回應範例值**

```json
{
  "id": "550e8400-e29b-41d4-a716-446655440000",
  "tableName": "回應字串",
  "description": "回應字串",
  "status": {},
  "errorMessage": "回應字串",
  "sourceFile": {
    "id": "550e8400-e29b-41d4-a716-446655440000",
    "name": "回應字串",
    "isFromKnowledgeBase": false
  },
  "columns": [
    {
      "id": "550e8400-e29b-41d4-a716-446655440000",
      "columnName": "回應字串",
      "columnType": "回應字串",
      "description": "回應字串",
      "isPrimaryKey": false,
      "isNullable": false,
      "createdAt": "回應字串",
      "updatedAt": "回應字串"
    }
  ],
  "createdAt": "回應字串",
  "updatedAt": "回應字串"
}
```

***

### 部分更新資料表 <a href="#undefined" id="undefined"></a>

PATCH `/api/v1/sql-databases/{sqlDatabasePk}/tables/{id}/`

#### 參數

| 參數名稱            | 必填 | 類型     | 說明                                             |
| --------------- | -- | ------ | ---------------------------------------------- |
| `id`            | ✅  | string | A UUID string identifying this Database Table. |
| `sqlDatabasePk` | ✅  | string |                                                |

#### 請求內容

**請求參數**

| 欄位          | 類型     | 必填 | 說明                                                                         |
| ----------- | ------ | -- | -------------------------------------------------------------------------- |
| tableName   | string | 否  | Name of the table in the database                                          |
| description | string | 否  | Description of the table and its data for better Text-to-SQL understanding |

**請求結構範例**

```typescript
{
  "tableName"?: string // Name of the table in the database (非必填)
  "description"?: string // Description of the table and its data for better Text-to-SQL understanding (非必填)
}
```

**請求範例值**

```json
{
  "tableName": "範例字串",
  "description": "範例字串"
}
```

#### 程式碼範例

{% tabs %}
{% tab title="Shell/Bash" %}

```bash
# 呼叫 API 示例 (Shell)
curl -X PATCH "https://api.maiagent.ai/api/v1/sql-databases/{sqlDatabasePk}/tables/550e8400-e29b-41d4-a716-446655440000/" \
  -H "Authorization: Api-Key YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "tableName": "範例字串",
    "description": "範例字串"
  }'

# 請確認在執行前替換 YOUR_API_KEY 並核對請求資料。
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
const axios = require('axios');

// 設定請求標頭
const config = {
  headers: {
    'Authorization': 'Api-Key YOUR_API_KEY',
    'Content-Type': 'application/json'
  }
};

// 請求內容 (payload)
const data = {
    "tableName": "範例字串",
    "description": "範例字串"
  };

axios.patch("https://api.maiagent.ai/api/v1/sql-databases/{sqlDatabasePk}/tables/550e8400-e29b-41d4-a716-446655440000/", data, config)
  .then(response => {
    console.log('成功取得回應:');
    console.log(response.data);
  })
  .catch(error => {
    console.error('請求發生錯誤:');
    console.error(error.response?.data || error.message);
  });
```

{% endtab %}

{% tab title="Python" %}

```python
import requests

url = "https://api.maiagent.ai/api/v1/sql-databases/{sqlDatabasePk}/tables/550e8400-e29b-41d4-a716-446655440000/"
headers = {
    "Authorization": "Api-Key YOUR_API_KEY",
    "Content-Type": "application/json"
}

# 請求內容 (payload)
data = {
      "tableName": "範例字串",
      "description": "範例字串"
    }

response = requests.patch(url, json=data, headers=headers)
try:
    print("成功取得回應:")
    print(response.json())
except Exception as e:
    print("請求發生錯誤:", e)
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php
require 'vendor/autoload.php';

$client = new GuzzleHttp\Client();

try {
    $response = $client->patch("https://api.maiagent.ai/api/v1/sql-databases/{sqlDatabasePk}/tables/550e8400-e29b-41d4-a716-446655440000/", [
        'headers' => [
            'Authorization' => 'Api-Key YOUR_API_KEY',
            'Content-Type' => 'application/json'
        ],
        'json' => {
            "tableName": "範例字串",
            "description": "範例字串"
        }
    ]);
    
    $data = json_decode($response->getBody(), true);
    echo "成功取得回應:\n";
    print_r($data);
} catch (Exception $e) {
    echo '請求發生錯誤: ' . $e->getMessage();
}
?>
```

{% endtab %}
{% endtabs %}

#### 回應內容

**狀態碼: 200**

**回應結構範例**

```typescript
{
  "id": string (uuid)
  "tableName": string // Name of the table in the database
  "description"?: string // Description of the table and its data for better Text-to-SQL understanding (非必填)
  "status": 
  {
  }
  "errorMessage": string // Error details if table creation or deletion failed
  "sourceFile": 
  {
    "id": string (uuid)
    "name": string
    "isFromKnowledgeBase": boolean // Determine if the source file originated from a knowledge base upload.

Returns True if the file was uploaded via knowledge base,
False if uploaded directly to the database.
  }
  "columns": [
    {
      "id": string (uuid)
      "columnName": string
      "columnType"?: string // Data type of the column (e.g., VARCHAR, INTEGER, TIMESTAMP) (非必填)
      "description"?: string // Description of the column for better Text-to-SQL understanding (非必填)
      "isPrimaryKey"?: boolean // 非必填
      "isNullable"?: boolean // 非必填
      "createdAt": string (timestamp)
      "updatedAt": string (timestamp)
    }
  ]
  "createdAt": string (timestamp)
  "updatedAt": string (timestamp)
}
```

**回應範例值**

```json
{
  "id": "550e8400-e29b-41d4-a716-446655440000",
  "tableName": "回應字串",
  "description": "回應字串",
  "status": {},
  "errorMessage": "回應字串",
  "sourceFile": {
    "id": "550e8400-e29b-41d4-a716-446655440000",
    "name": "回應字串",
    "isFromKnowledgeBase": false
  },
  "columns": [
    {
      "id": "550e8400-e29b-41d4-a716-446655440000",
      "columnName": "回應字串",
      "columnType": "回應字串",
      "description": "回應字串",
      "isPrimaryKey": false,
      "isNullable": false,
      "createdAt": "回應字串",
      "updatedAt": "回應字串"
    }
  ],
  "createdAt": "回應字串",
  "updatedAt": "回應字串"
}
```

***

### 刪除資料表 <a href="#undefined" id="undefined"></a>

DELETE `/api/sql-databases/{sqlDatabasePk}/tables/{id}/`

#### 參數

| 參數名稱            | 必填 | 類型     | 說明                                             |
| --------------- | -- | ------ | ---------------------------------------------- |
| `id`            | ✅  | string | A UUID string identifying this Database Table. |
| `sqlDatabasePk` | ✅  | string |                                                |

#### 程式碼範例

{% tabs %}
{% tab title="Shell/Bash" %}

```bash
# 呼叫 API 示例 (Shell)
curl -X DELETE "https://api.maiagent.ai/api/sql-databases/{sqlDatabasePk}/tables/550e8400-e29b-41d4-a716-446655440000/" \
  -H "Authorization: Api-Key YOUR_API_KEY"

# 請確認在執行前替換 YOUR_API_KEY 並核對請求資料。
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
const axios = require('axios');

// 設定請求標頭
const config = {
  headers: {
    'Authorization': 'Api-Key YOUR_API_KEY'
  }
};

// 請求內容 (payload)
const data = null;

axios.delete("https://api.maiagent.ai/api/sql-databases/{sqlDatabasePk}/tables/550e8400-e29b-41d4-a716-446655440000/", data, config)
  .then(response => {
    console.log('成功取得回應:');
    console.log(response.data);
  })
  .catch(error => {
    console.error('請求發生錯誤:');
    console.error(error.response?.data || error.message);
  });
```

{% endtab %}

{% tab title="Python" %}

```python
import requests

url = "https://api.maiagent.ai/api/sql-databases/{sqlDatabasePk}/tables/550e8400-e29b-41d4-a716-446655440000/"
headers = {
    "Authorization": "Api-Key YOUR_API_KEY"
}


response = requests.delete(url, headers=headers)
try:
    print("成功取得回應:")
    print(response.json())
except Exception as e:
    print("請求發生錯誤:", e)
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php
require 'vendor/autoload.php';

$client = new GuzzleHttp\Client();

try {
    $response = $client->delete("https://api.maiagent.ai/api/sql-databases/{sqlDatabasePk}/tables/550e8400-e29b-41d4-a716-446655440000/", [
        'headers' => [
            'Authorization' => 'Api-Key YOUR_API_KEY'
        ]
    ]);
    
    $data = json_decode($response->getBody(), true);
    echo "成功取得回應:\n";
    print_r($data);
} catch (Exception $e) {
    echo '請求發生錯誤: ' . $e->getMessage();
}
?>
```

{% endtab %}
{% endtabs %}

#### 回應內容

| 狀態碼 | 說明               |
| --- | ---------------- |
| 204 | No response body |

***

### 刪除資料表 <a href="#undefined" id="undefined"></a>

DELETE `/api/v1/sql-databases/{sqlDatabasePk}/tables/{id}/`

#### 參數

| 參數名稱            | 必填 | 類型     | 說明                                             |
| --------------- | -- | ------ | ---------------------------------------------- |
| `id`            | ✅  | string | A UUID string identifying this Database Table. |
| `sqlDatabasePk` | ✅  | string |                                                |

#### 程式碼範例

{% tabs %}
{% tab title="Shell/Bash" %}

```bash
# 呼叫 API 示例 (Shell)
curl -X DELETE "https://api.maiagent.ai/api/v1/sql-databases/{sqlDatabasePk}/tables/550e8400-e29b-41d4-a716-446655440000/" \
  -H "Authorization: Api-Key YOUR_API_KEY"

# 請確認在執行前替換 YOUR_API_KEY 並核對請求資料。
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
const axios = require('axios');

// 設定請求標頭
const config = {
  headers: {
    'Authorization': 'Api-Key YOUR_API_KEY'
  }
};

// 請求內容 (payload)
const data = null;

axios.delete("https://api.maiagent.ai/api/v1/sql-databases/{sqlDatabasePk}/tables/550e8400-e29b-41d4-a716-446655440000/", data, config)
  .then(response => {
    console.log('成功取得回應:');
    console.log(response.data);
  })
  .catch(error => {
    console.error('請求發生錯誤:');
    console.error(error.response?.data || error.message);
  });
```

{% endtab %}

{% tab title="Python" %}

```python
import requests

url = "https://api.maiagent.ai/api/v1/sql-databases/{sqlDatabasePk}/tables/550e8400-e29b-41d4-a716-446655440000/"
headers = {
    "Authorization": "Api-Key YOUR_API_KEY"
}


response = requests.delete(url, headers=headers)
try:
    print("成功取得回應:")
    print(response.json())
except Exception as e:
    print("請求發生錯誤:", e)
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php
require 'vendor/autoload.php';

$client = new GuzzleHttp\Client();

try {
    $response = $client->delete("https://api.maiagent.ai/api/v1/sql-databases/{sqlDatabasePk}/tables/550e8400-e29b-41d4-a716-446655440000/", [
        'headers' => [
            'Authorization' => 'Api-Key YOUR_API_KEY'
        ]
    ]);
    
    $data = json_decode($response->getBody(), true);
    echo "成功取得回應:\n";
    print_r($data);
} catch (Exception $e) {
    echo '請求發生錯誤: ' . $e->getMessage();
}
?>
```

{% endtab %}
{% endtabs %}

#### 回應內容

| 狀態碼 | 說明               |
| --- | ---------------- |
| 204 | No response body |

***

### 批量刪除資料表 <a href="#undefined" id="undefined"></a>

POST `/api/sql-databases/{sqlDatabasePk}/tables/batch-delete/`

#### 參數

| 參數名稱            | 必填 | 類型     | 說明 |
| --------------- | -- | ------ | -- |
| `sqlDatabasePk` | ✅  | string |    |

#### 請求內容

**請求參數**

| 欄位  | 類型             | 必填 | 說明 |
| --- | -------------- | -- | -- |
| ids | array\[string] | 是  |    |

**請求結構範例**

```typescript
{
  "ids": [
    string (uuid)
  ]
}
```

**請求範例值**

```json
{
  "ids": [
    "550e8400-e29b-41d4-a716-446655440000"
  ]
}
```

#### 程式碼範例

{% tabs %}
{% tab title="Shell/Bash" %}

```bash
# 呼叫 API 示例 (Shell)
curl -X POST "https://api.maiagent.ai/api/sql-databases/{sqlDatabasePk}/tables/batch-delete/" \
  -H "Authorization: Api-Key YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "ids": [
      "550e8400-e29b-41d4-a716-446655440000"
    ]
  }'

# 請確認在執行前替換 YOUR_API_KEY 並核對請求資料。
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
const axios = require('axios');

// 設定請求標頭
const config = {
  headers: {
    'Authorization': 'Api-Key YOUR_API_KEY',
    'Content-Type': 'application/json'
  }
};

// 請求內容 (payload)
const data = {
    "ids": [
      "550e8400-e29b-41d4-a716-446655440000"
    ]
  };

axios.post("https://api.maiagent.ai/api/sql-databases/{sqlDatabasePk}/tables/batch-delete/", data, config)
  .then(response => {
    console.log('成功取得回應:');
    console.log(response.data);
  })
  .catch(error => {
    console.error('請求發生錯誤:');
    console.error(error.response?.data || error.message);
  });
```

{% endtab %}

{% tab title="Python" %}

```python
import requests

url = "https://api.maiagent.ai/api/sql-databases/{sqlDatabasePk}/tables/batch-delete/"
headers = {
    "Authorization": "Api-Key YOUR_API_KEY",
    "Content-Type": "application/json"
}

# 請求內容 (payload)
data = {
      "ids": [
        "550e8400-e29b-41d4-a716-446655440000"
      ]
    }

response = requests.post(url, json=data, headers=headers)
try:
    print("成功取得回應:")
    print(response.json())
except Exception as e:
    print("請求發生錯誤:", e)
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php
require 'vendor/autoload.php';

$client = new GuzzleHttp\Client();

try {
    $response = $client->post("https://api.maiagent.ai/api/sql-databases/{sqlDatabasePk}/tables/batch-delete/", [
        'headers' => [
            'Authorization' => 'Api-Key YOUR_API_KEY',
            'Content-Type' => 'application/json'
        ],
        'json' => {
            "ids": [
                "550e8400-e29b-41d4-a716-446655440000"
            ]
        }
    ]);
    
    $data = json_decode($response->getBody(), true);
    echo "成功取得回應:\n";
    print_r($data);
} catch (Exception $e) {
    echo '請求發生錯誤: ' . $e->getMessage();
}
?>
```

{% endtab %}
{% endtabs %}

#### 回應內容

| 狀態碼 | 說明               |
| --- | ---------------- |
| 204 | No response body |

***

### 批量刪除資料表 <a href="#undefined" id="undefined"></a>

POST `/api/v1/sql-databases/{sqlDatabasePk}/tables/batch-delete/`

#### 參數

| 參數名稱            | 必填 | 類型     | 說明 |
| --------------- | -- | ------ | -- |
| `sqlDatabasePk` | ✅  | string |    |

#### 請求內容

**請求參數**

| 欄位  | 類型             | 必填 | 說明 |
| --- | -------------- | -- | -- |
| ids | array\[string] | 是  |    |

**請求結構範例**

```typescript
{
  "ids": [
    string (uuid)
  ]
}
```

**請求範例值**

```json
{
  "ids": [
    "550e8400-e29b-41d4-a716-446655440000"
  ]
}
```

#### 程式碼範例

{% tabs %}
{% tab title="Shell/Bash" %}

```bash
# 呼叫 API 示例 (Shell)
curl -X POST "https://api.maiagent.ai/api/v1/sql-databases/{sqlDatabasePk}/tables/batch-delete/" \
  -H "Authorization: Api-Key YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "ids": [
      "550e8400-e29b-41d4-a716-446655440000"
    ]
  }'

# 請確認在執行前替換 YOUR_API_KEY 並核對請求資料。
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
const axios = require('axios');

// 設定請求標頭
const config = {
  headers: {
    'Authorization': 'Api-Key YOUR_API_KEY',
    'Content-Type': 'application/json'
  }
};

// 請求內容 (payload)
const data = {
    "ids": [
      "550e8400-e29b-41d4-a716-446655440000"
    ]
  };

axios.post("https://api.maiagent.ai/api/v1/sql-databases/{sqlDatabasePk}/tables/batch-delete/", data, config)
  .then(response => {
    console.log('成功取得回應:');
    console.log(response.data);
  })
  .catch(error => {
    console.error('請求發生錯誤:');
    console.error(error.response?.data || error.message);
  });
```

{% endtab %}

{% tab title="Python" %}

```python
import requests

url = "https://api.maiagent.ai/api/v1/sql-databases/{sqlDatabasePk}/tables/batch-delete/"
headers = {
    "Authorization": "Api-Key YOUR_API_KEY",
    "Content-Type": "application/json"
}

# 請求內容 (payload)
data = {
      "ids": [
        "550e8400-e29b-41d4-a716-446655440000"
      ]
    }

response = requests.post(url, json=data, headers=headers)
try:
    print("成功取得回應:")
    print(response.json())
except Exception as e:
    print("請求發生錯誤:", e)
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php
require 'vendor/autoload.php';

$client = new GuzzleHttp\Client();

try {
    $response = $client->post("https://api.maiagent.ai/api/v1/sql-databases/{sqlDatabasePk}/tables/batch-delete/", [
        'headers' => [
            'Authorization' => 'Api-Key YOUR_API_KEY',
            'Content-Type' => 'application/json'
        ],
        'json' => {
            "ids": [
                "550e8400-e29b-41d4-a716-446655440000"
            ]
        }
    ]);
    
    $data = json_decode($response->getBody(), true);
    echo "成功取得回應:\n";
    print_r($data);
} catch (Exception $e) {
    echo '請求發生錯誤: ' . $e->getMessage();
}
?>
```

{% endtab %}
{% endtabs %}

#### 回應內容

| 狀態碼 | 說明               |
| --- | ---------------- |
| 204 | No response body |

***

### 列出資料欄位 <a href="#undefined" id="undefined"></a>

GET `/api/sql-databases/{sqlDatabasePk}/tables/{tablePk}/columns/`

#### 參數

| 參數名稱            | 必填 | 類型      | 說明                                             |
| --------------- | -- | ------- | ---------------------------------------------- |
| `sqlDatabasePk` | ✅  | string  |                                                |
| `tablePk`       | ✅  | string  |                                                |
| `page`          | ❌  | integer | A page number within the paginated result set. |
| `pageSize`      | ❌  | integer | Number of results to return per page.          |

#### 程式碼範例

{% tabs %}
{% tab title="Shell/Bash" %}

```bash
# 呼叫 API 示例 (Shell)
curl -X GET "https://api.maiagent.ai/api/sql-databases/{sqlDatabasePk}/tables/{tablePk}/columns/?page=1&pageSize=1" \
  -H "Authorization: Api-Key YOUR_API_KEY"

# 請確認在執行前替換 YOUR_API_KEY 並核對請求資料。
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
const axios = require('axios');

// 設定請求標頭
const config = {
  headers: {
    'Authorization': 'Api-Key YOUR_API_KEY'
  }
};

axios.get("https://api.maiagent.ai/api/sql-databases/{sqlDatabasePk}/tables/{tablePk}/columns/?page=1&pageSize=1", config)
  .then(response => {
    console.log('成功取得回應:');
    console.log(response.data);
  })
  .catch(error => {
    console.error('請求發生錯誤:');
    console.error(error.response?.data || error.message);
  });
```

{% endtab %}

{% tab title="Python" %}

```python
import requests

url = "https://api.maiagent.ai/api/sql-databases/{sqlDatabasePk}/tables/{tablePk}/columns/?page=1&pageSize=1"
headers = {
    "Authorization": "Api-Key YOUR_API_KEY"
}


response = requests.get(url, headers=headers)
try:
    print("成功取得回應:")
    print(response.json())
except Exception as e:
    print("請求發生錯誤:", e)
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php
require 'vendor/autoload.php';

$client = new GuzzleHttp\Client();

try {
    $response = $client->get("https://api.maiagent.ai/api/sql-databases/{sqlDatabasePk}/tables/{tablePk}/columns/?page=1&pageSize=1", [
        'headers' => [
            'Authorization' => 'Api-Key YOUR_API_KEY'
        ]
    ]);
    
    $data = json_decode($response->getBody(), true);
    echo "成功取得回應:\n";
    print_r($data);
} catch (Exception $e) {
    echo '請求發生錯誤: ' . $e->getMessage();
}
?>
```

{% endtab %}
{% endtabs %}

#### 回應內容

**狀態碼: 200**

**回應結構範例**

```typescript
{
  "count": integer
  "next"?: string (uri) // 非必填
  "previous"?: string (uri) // 非必填
  "results": [
    {
      "id": string (uuid)
      "columnName": string
      "columnType"?: string // Data type of the column (e.g., VARCHAR, INTEGER, TIMESTAMP) (非必填)
      "description"?: string // Description of the column for better Text-to-SQL understanding (非必填)
      "isPrimaryKey"?: boolean // 非必填
      "isNullable"?: boolean // 非必填
      "createdAt": string (timestamp)
      "updatedAt": string (timestamp)
    }
  ]
}
```

**回應範例值**

```json
{
  "count": 123,
  "next": "http://api.example.org/accounts/?page=4",
  "previous": "http://api.example.org/accounts/?page=2",
  "results": [
    {
      "id": "550e8400-e29b-41d4-a716-446655440000",
      "columnName": "回應字串",
      "columnType": "回應字串",
      "description": "回應字串",
      "isPrimaryKey": false,
      "isNullable": false,
      "createdAt": "回應字串",
      "updatedAt": "回應字串"
    }
  ]
}
```

***

### 列出資料欄位 <a href="#undefined" id="undefined"></a>

GET `/api/v1/sql-databases/{sqlDatabasePk}/tables/{tablePk}/columns/`

#### 參數

| 參數名稱            | 必填 | 類型      | 說明                                             |
| --------------- | -- | ------- | ---------------------------------------------- |
| `sqlDatabasePk` | ✅  | string  |                                                |
| `tablePk`       | ✅  | string  |                                                |
| `page`          | ❌  | integer | A page number within the paginated result set. |
| `pageSize`      | ❌  | integer | Number of results to return per page.          |

#### 程式碼範例

{% tabs %}
{% tab title="Shell/Bash" %}

```bash
# 呼叫 API 示例 (Shell)
curl -X GET "https://api.maiagent.ai/api/v1/sql-databases/{sqlDatabasePk}/tables/{tablePk}/columns/?page=1&pageSize=1" \
  -H "Authorization: Api-Key YOUR_API_KEY"

# 請確認在執行前替換 YOUR_API_KEY 並核對請求資料。
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
const axios = require('axios');

// 設定請求標頭
const config = {
  headers: {
    'Authorization': 'Api-Key YOUR_API_KEY'
  }
};

axios.get("https://api.maiagent.ai/api/v1/sql-databases/{sqlDatabasePk}/tables/{tablePk}/columns/?page=1&pageSize=1", config)
  .then(response => {
    console.log('成功取得回應:');
    console.log(response.data);
  })
  .catch(error => {
    console.error('請求發生錯誤:');
    console.error(error.response?.data || error.message);
  });
```

{% endtab %}

{% tab title="Python" %}

```python
import requests

url = "https://api.maiagent.ai/api/v1/sql-databases/{sqlDatabasePk}/tables/{tablePk}/columns/?page=1&pageSize=1"
headers = {
    "Authorization": "Api-Key YOUR_API_KEY"
}


response = requests.get(url, headers=headers)
try:
    print("成功取得回應:")
    print(response.json())
except Exception as e:
    print("請求發生錯誤:", e)
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php
require 'vendor/autoload.php';

$client = new GuzzleHttp\Client();

try {
    $response = $client->get("https://api.maiagent.ai/api/v1/sql-databases/{sqlDatabasePk}/tables/{tablePk}/columns/?page=1&pageSize=1", [
        'headers' => [
            'Authorization' => 'Api-Key YOUR_API_KEY'
        ]
    ]);
    
    $data = json_decode($response->getBody(), true);
    echo "成功取得回應:\n";
    print_r($data);
} catch (Exception $e) {
    echo '請求發生錯誤: ' . $e->getMessage();
}
?>
```

{% endtab %}
{% endtabs %}

#### 回應內容

**狀態碼: 200**

**回應結構範例**

```typescript
{
  "count": integer
  "next"?: string (uri) // 非必填
  "previous"?: string (uri) // 非必填
  "results": [
    {
      "id": string (uuid)
      "columnName": string
      "columnType"?: string // Data type of the column (e.g., VARCHAR, INTEGER, TIMESTAMP) (非必填)
      "description"?: string // Description of the column for better Text-to-SQL understanding (非必填)
      "isPrimaryKey"?: boolean // 非必填
      "isNullable"?: boolean // 非必填
      "createdAt": string (timestamp)
      "updatedAt": string (timestamp)
    }
  ]
}
```

**回應範例值**

```json
{
  "count": 123,
  "next": "http://api.example.org/accounts/?page=4",
  "previous": "http://api.example.org/accounts/?page=2",
  "results": [
    {
      "id": "550e8400-e29b-41d4-a716-446655440000",
      "columnName": "回應字串",
      "columnType": "回應字串",
      "description": "回應字串",
      "isPrimaryKey": false,
      "isNullable": false,
      "createdAt": "回應字串",
      "updatedAt": "回應字串"
    }
  ]
}
```

***

### 取得特定資料欄位 <a href="#undefined" id="undefined"></a>

GET `/api/sql-databases/{sqlDatabasePk}/tables/{tablePk}/columns/{id}/`

#### 參數

| 參數名稱            | 必填 | 類型     | 說明                                                    |
| --------------- | -- | ------ | ----------------------------------------------------- |
| `id`            | ✅  | string | A UUID string identifying this Database Table Column. |
| `sqlDatabasePk` | ✅  | string |                                                       |
| `tablePk`       | ✅  | string |                                                       |

#### 程式碼範例

{% tabs %}
{% tab title="Shell/Bash" %}

```bash
# 呼叫 API 示例 (Shell)
curl -X GET "https://api.maiagent.ai/api/sql-databases/{sqlDatabasePk}/tables/{tablePk}/columns/550e8400-e29b-41d4-a716-446655440000/" \
  -H "Authorization: Api-Key YOUR_API_KEY"

# 請確認在執行前替換 YOUR_API_KEY 並核對請求資料。
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
const axios = require('axios');

// 設定請求標頭
const config = {
  headers: {
    'Authorization': 'Api-Key YOUR_API_KEY'
  }
};

axios.get("https://api.maiagent.ai/api/sql-databases/{sqlDatabasePk}/tables/{tablePk}/columns/550e8400-e29b-41d4-a716-446655440000/", config)
  .then(response => {
    console.log('成功取得回應:');
    console.log(response.data);
  })
  .catch(error => {
    console.error('請求發生錯誤:');
    console.error(error.response?.data || error.message);
  });
```

{% endtab %}

{% tab title="Python" %}

```python
import requests

url = "https://api.maiagent.ai/api/sql-databases/{sqlDatabasePk}/tables/{tablePk}/columns/550e8400-e29b-41d4-a716-446655440000/"
headers = {
    "Authorization": "Api-Key YOUR_API_KEY"
}


response = requests.get(url, headers=headers)
try:
    print("成功取得回應:")
    print(response.json())
except Exception as e:
    print("請求發生錯誤:", e)
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php
require 'vendor/autoload.php';

$client = new GuzzleHttp\Client();

try {
    $response = $client->get("https://api.maiagent.ai/api/sql-databases/{sqlDatabasePk}/tables/{tablePk}/columns/550e8400-e29b-41d4-a716-446655440000/", [
        'headers' => [
            'Authorization' => 'Api-Key YOUR_API_KEY'
        ]
    ]);
    
    $data = json_decode($response->getBody(), true);
    echo "成功取得回應:\n";
    print_r($data);
} catch (Exception $e) {
    echo '請求發生錯誤: ' . $e->getMessage();
}
?>
```

{% endtab %}
{% endtabs %}

#### 回應內容

**狀態碼: 200**

**回應結構範例**

```typescript
{
  "id": string (uuid)
  "columnName": string
  "columnType"?: string // Data type of the column (e.g., VARCHAR, INTEGER, TIMESTAMP) (非必填)
  "description"?: string // Description of the column for better Text-to-SQL understanding (非必填)
  "isPrimaryKey"?: boolean // 非必填
  "isNullable"?: boolean // 非必填
  "createdAt": string (timestamp)
  "updatedAt": string (timestamp)
}
```

**回應範例值**

```json
{
  "id": "550e8400-e29b-41d4-a716-446655440000",
  "columnName": "回應字串",
  "columnType": "回應字串",
  "description": "回應字串",
  "isPrimaryKey": false,
  "isNullable": false,
  "createdAt": "回應字串",
  "updatedAt": "回應字串"
}
```

***

### 取得特定資料欄位 <a href="#undefined" id="undefined"></a>

GET `/api/v1/sql-databases/{sqlDatabasePk}/tables/{tablePk}/columns/{id}/`

#### 參數

| 參數名稱            | 必填 | 類型     | 說明                                                    |
| --------------- | -- | ------ | ----------------------------------------------------- |
| `id`            | ✅  | string | A UUID string identifying this Database Table Column. |
| `sqlDatabasePk` | ✅  | string |                                                       |
| `tablePk`       | ✅  | string |                                                       |

#### 程式碼範例

{% tabs %}
{% tab title="Shell/Bash" %}

```bash
# 呼叫 API 示例 (Shell)
curl -X GET "https://api.maiagent.ai/api/v1/sql-databases/{sqlDatabasePk}/tables/{tablePk}/columns/550e8400-e29b-41d4-a716-446655440000/" \
  -H "Authorization: Api-Key YOUR_API_KEY"

# 請確認在執行前替換 YOUR_API_KEY 並核對請求資料。
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
const axios = require('axios');

// 設定請求標頭
const config = {
  headers: {
    'Authorization': 'Api-Key YOUR_API_KEY'
  }
};

axios.get("https://api.maiagent.ai/api/v1/sql-databases/{sqlDatabasePk}/tables/{tablePk}/columns/550e8400-e29b-41d4-a716-446655440000/", config)
  .then(response => {
    console.log('成功取得回應:');
    console.log(response.data);
  })
  .catch(error => {
    console.error('請求發生錯誤:');
    console.error(error.response?.data || error.message);
  });
```

{% endtab %}

{% tab title="Python" %}

```python
import requests

url = "https://api.maiagent.ai/api/v1/sql-databases/{sqlDatabasePk}/tables/{tablePk}/columns/550e8400-e29b-41d4-a716-446655440000/"
headers = {
    "Authorization": "Api-Key YOUR_API_KEY"
}


response = requests.get(url, headers=headers)
try:
    print("成功取得回應:")
    print(response.json())
except Exception as e:
    print("請求發生錯誤:", e)
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php
require 'vendor/autoload.php';

$client = new GuzzleHttp\Client();

try {
    $response = $client->get("https://api.maiagent.ai/api/v1/sql-databases/{sqlDatabasePk}/tables/{tablePk}/columns/550e8400-e29b-41d4-a716-446655440000/", [
        'headers' => [
            'Authorization' => 'Api-Key YOUR_API_KEY'
        ]
    ]);
    
    $data = json_decode($response->getBody(), true);
    echo "成功取得回應:\n";
    print_r($data);
} catch (Exception $e) {
    echo '請求發生錯誤: ' . $e->getMessage();
}
?>
```

{% endtab %}
{% endtabs %}

#### 回應內容

**狀態碼: 200**

**回應結構範例**

```typescript
{
  "id": string (uuid)
  "columnName": string
  "columnType"?: string // Data type of the column (e.g., VARCHAR, INTEGER, TIMESTAMP) (非必填)
  "description"?: string // Description of the column for better Text-to-SQL understanding (非必填)
  "isPrimaryKey"?: boolean // 非必填
  "isNullable"?: boolean // 非必填
  "createdAt": string (timestamp)
  "updatedAt": string (timestamp)
}
```

**回應範例值**

```json
{
  "id": "550e8400-e29b-41d4-a716-446655440000",
  "columnName": "回應字串",
  "columnType": "回應字串",
  "description": "回應字串",
  "isPrimaryKey": false,
  "isNullable": false,
  "createdAt": "回應字串",
  "updatedAt": "回應字串"
}
```

***

### 更新資料欄位 <a href="#undefined" id="undefined"></a>

PUT `/api/sql-databases/{sqlDatabasePk}/tables/{tablePk}/columns/{id}/`

#### 參數

| 參數名稱            | 必填 | 類型     | 說明                                                    |
| --------------- | -- | ------ | ----------------------------------------------------- |
| `id`            | ✅  | string | A UUID string identifying this Database Table Column. |
| `sqlDatabasePk` | ✅  | string |                                                       |
| `tablePk`       | ✅  | string |                                                       |

#### 請求內容

**請求參數**

| 欄位           | 類型      | 必填 | 說明                                                             |
| ------------ | ------- | -- | -------------------------------------------------------------- |
| columnName   | string  | 是  |                                                                |
| columnType   | string  | 否  | Data type of the column (e.g., VARCHAR, INTEGER, TIMESTAMP)    |
| description  | string  | 否  | Description of the column for better Text-to-SQL understanding |
| isPrimaryKey | boolean | 否  |                                                                |
| isNullable   | boolean | 否  |                                                                |

**請求結構範例**

```typescript
{
  "columnName": string
  "columnType"?: string // Data type of the column (e.g., VARCHAR, INTEGER, TIMESTAMP) (非必填)
  "description"?: string // Description of the column for better Text-to-SQL understanding (非必填)
  "isPrimaryKey"?: boolean // 非必填
  "isNullable"?: boolean // 非必填
}
```

**請求範例值**

```json
{
  "columnName": "範例字串",
  "columnType": "範例字串",
  "description": "範例字串",
  "isPrimaryKey": true,
  "isNullable": true
}
```

#### 程式碼範例

{% tabs %}
{% tab title="Shell/Bash" %}

```bash
# 呼叫 API 示例 (Shell)
curl -X PUT "https://api.maiagent.ai/api/sql-databases/{sqlDatabasePk}/tables/{tablePk}/columns/550e8400-e29b-41d4-a716-446655440000/" \
  -H "Authorization: Api-Key YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "columnName": "範例字串",
    "columnType": "範例字串",
    "description": "範例字串",
    "isPrimaryKey": true,
    "isNullable": true
  }'

# 請確認在執行前替換 YOUR_API_KEY 並核對請求資料。
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
const axios = require('axios');

// 設定請求標頭
const config = {
  headers: {
    'Authorization': 'Api-Key YOUR_API_KEY',
    'Content-Type': 'application/json'
  }
};

// 請求內容 (payload)
const data = {
    "columnName": "範例字串",
    "columnType": "範例字串",
    "description": "範例字串",
    "isPrimaryKey": true,
    "isNullable": true
  };

axios.put("https://api.maiagent.ai/api/sql-databases/{sqlDatabasePk}/tables/{tablePk}/columns/550e8400-e29b-41d4-a716-446655440000/", data, config)
  .then(response => {
    console.log('成功取得回應:');
    console.log(response.data);
  })
  .catch(error => {
    console.error('請求發生錯誤:');
    console.error(error.response?.data || error.message);
  });
```

{% endtab %}

{% tab title="Python" %}

```python
import requests

url = "https://api.maiagent.ai/api/sql-databases/{sqlDatabasePk}/tables/{tablePk}/columns/550e8400-e29b-41d4-a716-446655440000/"
headers = {
    "Authorization": "Api-Key YOUR_API_KEY",
    "Content-Type": "application/json"
}

# 請求內容 (payload)
data = {
      "columnName": "範例字串",
      "columnType": "範例字串",
      "description": "範例字串",
      "isPrimaryKey": true,
      "isNullable": true
    }

response = requests.put(url, json=data, headers=headers)
try:
    print("成功取得回應:")
    print(response.json())
except Exception as e:
    print("請求發生錯誤:", e)
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php
require 'vendor/autoload.php';

$client = new GuzzleHttp\Client();

try {
    $response = $client->put("https://api.maiagent.ai/api/sql-databases/{sqlDatabasePk}/tables/{tablePk}/columns/550e8400-e29b-41d4-a716-446655440000/", [
        'headers' => [
            'Authorization' => 'Api-Key YOUR_API_KEY',
            'Content-Type' => 'application/json'
        ],
        'json' => {
            "columnName": "範例字串",
            "columnType": "範例字串",
            "description": "範例字串",
            "isPrimaryKey": true,
            "isNullable": true
        }
    ]);
    
    $data = json_decode($response->getBody(), true);
    echo "成功取得回應:\n";
    print_r($data);
} catch (Exception $e) {
    echo '請求發生錯誤: ' . $e->getMessage();
}
?>
```

{% endtab %}
{% endtabs %}

#### 回應內容

**狀態碼: 200**

**回應結構範例**

```typescript
{
  "id": string (uuid)
  "columnName": string
  "columnType"?: string // Data type of the column (e.g., VARCHAR, INTEGER, TIMESTAMP) (非必填)
  "description"?: string // Description of the column for better Text-to-SQL understanding (非必填)
  "isPrimaryKey"?: boolean // 非必填
  "isNullable"?: boolean // 非必填
  "createdAt": string (timestamp)
  "updatedAt": string (timestamp)
}
```

**回應範例值**

```json
{
  "id": "550e8400-e29b-41d4-a716-446655440000",
  "columnName": "回應字串",
  "columnType": "回應字串",
  "description": "回應字串",
  "isPrimaryKey": false,
  "isNullable": false,
  "createdAt": "回應字串",
  "updatedAt": "回應字串"
}
```

***

### 更新資料欄位 <a href="#undefined" id="undefined"></a>

PUT `/api/v1/sql-databases/{sqlDatabasePk}/tables/{tablePk}/columns/{id}/`

#### 參數

| 參數名稱            | 必填 | 類型     | 說明                                                    |
| --------------- | -- | ------ | ----------------------------------------------------- |
| `id`            | ✅  | string | A UUID string identifying this Database Table Column. |
| `sqlDatabasePk` | ✅  | string |                                                       |
| `tablePk`       | ✅  | string |                                                       |

#### 請求內容

**請求參數**

| 欄位           | 類型      | 必填 | 說明                                                             |
| ------------ | ------- | -- | -------------------------------------------------------------- |
| columnName   | string  | 是  |                                                                |
| columnType   | string  | 否  | Data type of the column (e.g., VARCHAR, INTEGER, TIMESTAMP)    |
| description  | string  | 否  | Description of the column for better Text-to-SQL understanding |
| isPrimaryKey | boolean | 否  |                                                                |
| isNullable   | boolean | 否  |                                                                |

**請求結構範例**

```typescript
{
  "columnName": string
  "columnType"?: string // Data type of the column (e.g., VARCHAR, INTEGER, TIMESTAMP) (非必填)
  "description"?: string // Description of the column for better Text-to-SQL understanding (非必填)
  "isPrimaryKey"?: boolean // 非必填
  "isNullable"?: boolean // 非必填
}
```

**請求範例值**

```json
{
  "columnName": "範例字串",
  "columnType": "範例字串",
  "description": "範例字串",
  "isPrimaryKey": true,
  "isNullable": true
}
```

#### 程式碼範例

{% tabs %}
{% tab title="Shell/Bash" %}

```bash
# 呼叫 API 示例 (Shell)
curl -X PUT "https://api.maiagent.ai/api/v1/sql-databases/{sqlDatabasePk}/tables/{tablePk}/columns/550e8400-e29b-41d4-a716-446655440000/" \
  -H "Authorization: Api-Key YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "columnName": "範例字串",
    "columnType": "範例字串",
    "description": "範例字串",
    "isPrimaryKey": true,
    "isNullable": true
  }'

# 請確認在執行前替換 YOUR_API_KEY 並核對請求資料。
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
const axios = require('axios');

// 設定請求標頭
const config = {
  headers: {
    'Authorization': 'Api-Key YOUR_API_KEY',
    'Content-Type': 'application/json'
  }
};

// 請求內容 (payload)
const data = {
    "columnName": "範例字串",
    "columnType": "範例字串",
    "description": "範例字串",
    "isPrimaryKey": true,
    "isNullable": true
  };

axios.put("https://api.maiagent.ai/api/v1/sql-databases/{sqlDatabasePk}/tables/{tablePk}/columns/550e8400-e29b-41d4-a716-446655440000/", data, config)
  .then(response => {
    console.log('成功取得回應:');
    console.log(response.data);
  })
  .catch(error => {
    console.error('請求發生錯誤:');
    console.error(error.response?.data || error.message);
  });
```

{% endtab %}

{% tab title="Python" %}

```python
import requests

url = "https://api.maiagent.ai/api/v1/sql-databases/{sqlDatabasePk}/tables/{tablePk}/columns/550e8400-e29b-41d4-a716-446655440000/"
headers = {
    "Authorization": "Api-Key YOUR_API_KEY",
    "Content-Type": "application/json"
}

# 請求內容 (payload)
data = {
      "columnName": "範例字串",
      "columnType": "範例字串",
      "description": "範例字串",
      "isPrimaryKey": true,
      "isNullable": true
    }

response = requests.put(url, json=data, headers=headers)
try:
    print("成功取得回應:")
    print(response.json())
except Exception as e:
    print("請求發生錯誤:", e)
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php
require 'vendor/autoload.php';

$client = new GuzzleHttp\Client();

try {
    $response = $client->put("https://api.maiagent.ai/api/v1/sql-databases/{sqlDatabasePk}/tables/{tablePk}/columns/550e8400-e29b-41d4-a716-446655440000/", [
        'headers' => [
            'Authorization' => 'Api-Key YOUR_API_KEY',
            'Content-Type' => 'application/json'
        ],
        'json' => {
            "columnName": "範例字串",
            "columnType": "範例字串",
            "description": "範例字串",
            "isPrimaryKey": true,
            "isNullable": true
        }
    ]);
    
    $data = json_decode($response->getBody(), true);
    echo "成功取得回應:\n";
    print_r($data);
} catch (Exception $e) {
    echo '請求發生錯誤: ' . $e->getMessage();
}
?>
```

{% endtab %}
{% endtabs %}

#### 回應內容

**狀態碼: 200**

**回應結構範例**

```typescript
{
  "id": string (uuid)
  "columnName": string
  "columnType"?: string // Data type of the column (e.g., VARCHAR, INTEGER, TIMESTAMP) (非必填)
  "description"?: string // Description of the column for better Text-to-SQL understanding (非必填)
  "isPrimaryKey"?: boolean // 非必填
  "isNullable"?: boolean // 非必填
  "createdAt": string (timestamp)
  "updatedAt": string (timestamp)
}
```

**回應範例值**

```json
{
  "id": "550e8400-e29b-41d4-a716-446655440000",
  "columnName": "回應字串",
  "columnType": "回應字串",
  "description": "回應字串",
  "isPrimaryKey": false,
  "isNullable": false,
  "createdAt": "回應字串",
  "updatedAt": "回應字串"
}
```

***

### 部分更新資料欄位 <a href="#undefined" id="undefined"></a>

PATCH `/api/sql-databases/{sqlDatabasePk}/tables/{tablePk}/columns/{id}/`

#### 參數

| 參數名稱            | 必填 | 類型     | 說明                                                    |
| --------------- | -- | ------ | ----------------------------------------------------- |
| `id`            | ✅  | string | A UUID string identifying this Database Table Column. |
| `sqlDatabasePk` | ✅  | string |                                                       |
| `tablePk`       | ✅  | string |                                                       |

#### 請求內容

**請求參數**

| 欄位           | 類型      | 必填 | 說明                                                             |
| ------------ | ------- | -- | -------------------------------------------------------------- |
| columnName   | string  | 否  |                                                                |
| columnType   | string  | 否  | Data type of the column (e.g., VARCHAR, INTEGER, TIMESTAMP)    |
| description  | string  | 否  | Description of the column for better Text-to-SQL understanding |
| isPrimaryKey | boolean | 否  |                                                                |
| isNullable   | boolean | 否  |                                                                |

**請求結構範例**

```typescript
{
  "columnName"?: string // 非必填
  "columnType"?: string // Data type of the column (e.g., VARCHAR, INTEGER, TIMESTAMP) (非必填)
  "description"?: string // Description of the column for better Text-to-SQL understanding (非必填)
  "isPrimaryKey"?: boolean // 非必填
  "isNullable"?: boolean // 非必填
}
```

**請求範例值**

```json
{
  "columnName": "範例字串",
  "columnType": "範例字串",
  "description": "範例字串",
  "isPrimaryKey": true,
  "isNullable": true
}
```

#### 程式碼範例

{% tabs %}
{% tab title="Shell/Bash" %}

```bash
# 呼叫 API 示例 (Shell)
curl -X PATCH "https://api.maiagent.ai/api/sql-databases/{sqlDatabasePk}/tables/{tablePk}/columns/550e8400-e29b-41d4-a716-446655440000/" \
  -H "Authorization: Api-Key YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "columnName": "範例字串",
    "columnType": "範例字串",
    "description": "範例字串",
    "isPrimaryKey": true,
    "isNullable": true
  }'

# 請確認在執行前替換 YOUR_API_KEY 並核對請求資料。
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
const axios = require('axios');

// 設定請求標頭
const config = {
  headers: {
    'Authorization': 'Api-Key YOUR_API_KEY',
    'Content-Type': 'application/json'
  }
};

// 請求內容 (payload)
const data = {
    "columnName": "範例字串",
    "columnType": "範例字串",
    "description": "範例字串",
    "isPrimaryKey": true,
    "isNullable": true
  };

axios.patch("https://api.maiagent.ai/api/sql-databases/{sqlDatabasePk}/tables/{tablePk}/columns/550e8400-e29b-41d4-a716-446655440000/", data, config)
  .then(response => {
    console.log('成功取得回應:');
    console.log(response.data);
  })
  .catch(error => {
    console.error('請求發生錯誤:');
    console.error(error.response?.data || error.message);
  });
```

{% endtab %}

{% tab title="Python" %}

```python
import requests

url = "https://api.maiagent.ai/api/sql-databases/{sqlDatabasePk}/tables/{tablePk}/columns/550e8400-e29b-41d4-a716-446655440000/"
headers = {
    "Authorization": "Api-Key YOUR_API_KEY",
    "Content-Type": "application/json"
}

# 請求內容 (payload)
data = {
      "columnName": "範例字串",
      "columnType": "範例字串",
      "description": "範例字串",
      "isPrimaryKey": true,
      "isNullable": true
    }

response = requests.patch(url, json=data, headers=headers)
try:
    print("成功取得回應:")
    print(response.json())
except Exception as e:
    print("請求發生錯誤:", e)
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php
require 'vendor/autoload.php';

$client = new GuzzleHttp\Client();

try {
    $response = $client->patch("https://api.maiagent.ai/api/sql-databases/{sqlDatabasePk}/tables/{tablePk}/columns/550e8400-e29b-41d4-a716-446655440000/", [
        'headers' => [
            'Authorization' => 'Api-Key YOUR_API_KEY',
            'Content-Type' => 'application/json'
        ],
        'json' => {
            "columnName": "範例字串",
            "columnType": "範例字串",
            "description": "範例字串",
            "isPrimaryKey": true,
            "isNullable": true
        }
    ]);
    
    $data = json_decode($response->getBody(), true);
    echo "成功取得回應:\n";
    print_r($data);
} catch (Exception $e) {
    echo '請求發生錯誤: ' . $e->getMessage();
}
?>
```

{% endtab %}
{% endtabs %}

#### 回應內容

**狀態碼: 200**

**回應結構範例**

```typescript
{
  "id": string (uuid)
  "columnName": string
  "columnType"?: string // Data type of the column (e.g., VARCHAR, INTEGER, TIMESTAMP) (非必填)
  "description"?: string // Description of the column for better Text-to-SQL understanding (非必填)
  "isPrimaryKey"?: boolean // 非必填
  "isNullable"?: boolean // 非必填
  "createdAt": string (timestamp)
  "updatedAt": string (timestamp)
}
```

**回應範例值**

```json
{
  "id": "550e8400-e29b-41d4-a716-446655440000",
  "columnName": "回應字串",
  "columnType": "回應字串",
  "description": "回應字串",
  "isPrimaryKey": false,
  "isNullable": false,
  "createdAt": "回應字串",
  "updatedAt": "回應字串"
}
```

***

### 部分更新資料欄位 <a href="#undefined" id="undefined"></a>

PATCH `/api/v1/sql-databases/{sqlDatabasePk}/tables/{tablePk}/columns/{id}/`

#### 參數

| 參數名稱            | 必填 | 類型     | 說明                                                    |
| --------------- | -- | ------ | ----------------------------------------------------- |
| `id`            | ✅  | string | A UUID string identifying this Database Table Column. |
| `sqlDatabasePk` | ✅  | string |                                                       |
| `tablePk`       | ✅  | string |                                                       |

#### 請求內容

**請求參數**

| 欄位           | 類型      | 必填 | 說明                                                             |
| ------------ | ------- | -- | -------------------------------------------------------------- |
| columnName   | string  | 否  |                                                                |
| columnType   | string  | 否  | Data type of the column (e.g., VARCHAR, INTEGER, TIMESTAMP)    |
| description  | string  | 否  | Description of the column for better Text-to-SQL understanding |
| isPrimaryKey | boolean | 否  |                                                                |
| isNullable   | boolean | 否  |                                                                |

**請求結構範例**

```typescript
{
  "columnName"?: string // 非必填
  "columnType"?: string // Data type of the column (e.g., VARCHAR, INTEGER, TIMESTAMP) (非必填)
  "description"?: string // Description of the column for better Text-to-SQL understanding (非必填)
  "isPrimaryKey"?: boolean // 非必填
  "isNullable"?: boolean // 非必填
}
```

**請求範例值**

```json
{
  "columnName": "範例字串",
  "columnType": "範例字串",
  "description": "範例字串",
  "isPrimaryKey": true,
  "isNullable": true
}
```

#### 程式碼範例

{% tabs %}
{% tab title="Shell/Bash" %}

```bash
# 呼叫 API 示例 (Shell)
curl -X PATCH "https://api.maiagent.ai/api/v1/sql-databases/{sqlDatabasePk}/tables/{tablePk}/columns/550e8400-e29b-41d4-a716-446655440000/" \
  -H "Authorization: Api-Key YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "columnName": "範例字串",
    "columnType": "範例字串",
    "description": "範例字串",
    "isPrimaryKey": true,
    "isNullable": true
  }'

# 請確認在執行前替換 YOUR_API_KEY 並核對請求資料。
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
const axios = require('axios');

// 設定請求標頭
const config = {
  headers: {
    'Authorization': 'Api-Key YOUR_API_KEY',
    'Content-Type': 'application/json'
  }
};

// 請求內容 (payload)
const data = {
    "columnName": "範例字串",
    "columnType": "範例字串",
    "description": "範例字串",
    "isPrimaryKey": true,
    "isNullable": true
  };

axios.patch("https://api.maiagent.ai/api/v1/sql-databases/{sqlDatabasePk}/tables/{tablePk}/columns/550e8400-e29b-41d4-a716-446655440000/", data, config)
  .then(response => {
    console.log('成功取得回應:');
    console.log(response.data);
  })
  .catch(error => {
    console.error('請求發生錯誤:');
    console.error(error.response?.data || error.message);
  });
```

{% endtab %}

{% tab title="Python" %}

```python
import requests

url = "https://api.maiagent.ai/api/v1/sql-databases/{sqlDatabasePk}/tables/{tablePk}/columns/550e8400-e29b-41d4-a716-446655440000/"
headers = {
    "Authorization": "Api-Key YOUR_API_KEY",
    "Content-Type": "application/json"
}

# 請求內容 (payload)
data = {
      "columnName": "範例字串",
      "columnType": "範例字串",
      "description": "範例字串",
      "isPrimaryKey": true,
      "isNullable": true
    }

response = requests.patch(url, json=data, headers=headers)
try:
    print("成功取得回應:")
    print(response.json())
except Exception as e:
    print("請求發生錯誤:", e)
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php
require 'vendor/autoload.php';

$client = new GuzzleHttp\Client();

try {
    $response = $client->patch("https://api.maiagent.ai/api/v1/sql-databases/{sqlDatabasePk}/tables/{tablePk}/columns/550e8400-e29b-41d4-a716-446655440000/", [
        'headers' => [
            'Authorization' => 'Api-Key YOUR_API_KEY',
            'Content-Type' => 'application/json'
        ],
        'json' => {
            "columnName": "範例字串",
            "columnType": "範例字串",
            "description": "範例字串",
            "isPrimaryKey": true,
            "isNullable": true
        }
    ]);
    
    $data = json_decode($response->getBody(), true);
    echo "成功取得回應:\n";
    print_r($data);
} catch (Exception $e) {
    echo '請求發生錯誤: ' . $e->getMessage();
}
?>
```

{% endtab %}
{% endtabs %}

#### 回應內容

**狀態碼: 200**

**回應結構範例**

```typescript
{
  "id": string (uuid)
  "columnName": string
  "columnType"?: string // Data type of the column (e.g., VARCHAR, INTEGER, TIMESTAMP) (非必填)
  "description"?: string // Description of the column for better Text-to-SQL understanding (非必填)
  "isPrimaryKey"?: boolean // 非必填
  "isNullable"?: boolean // 非必填
  "createdAt": string (timestamp)
  "updatedAt": string (timestamp)
}
```

**回應範例值**

```json
{
  "id": "550e8400-e29b-41d4-a716-446655440000",
  "columnName": "回應字串",
  "columnType": "回應字串",
  "description": "回應字串",
  "isPrimaryKey": false,
  "isNullable": false,
  "createdAt": "回應字串",
  "updatedAt": "回應字串"
}
```

***

### 測試資料庫連線（通用） <a href="#undefined" id="undefined"></a>

POST `/api/database-connection/test/`

#### 請求內容

**請求參數**

| 欄位           | 類型     | 必填 | 說明                                                                                                        |
| ------------ | ------ | -- | --------------------------------------------------------------------------------------------------------- |
| databaseType | object | 是  | 資料庫類型（不包含 MaiAgent 內部使用類型） `postgresql`: PostgreSQL ; `mysql`: MySQL ; `oracle`: Oracle ; `mssql`: MSSQL; |
| databaseUrl  | string | 是  | 資料庫連線字串                                                                                                   |

**請求結構範例**

```typescript
{
  "databaseType":  // 資料庫類型（不包含 MaiAgent 內部使用類型）

* `postgresql` - PostgreSQL
* `mysql` - MySQL
* `oracle` - Oracle
* `mssql` - MSSQL
  {
  }
  "databaseUrl": string // 資料庫連線字串
}
```

**請求範例值**

```json
{
  "database_type": "postgresql",
  "database_url": "postgresql://user:password@localhost:5432/dbname"
}
```

#### 程式碼範例

{% tabs %}
{% tab title="Shell/Bash" %}

```bash
# 呼叫 API 示例 (Shell)
curl -X POST "https://api.maiagent.ai/api/database-connection/test/" \
  -H "Authorization: Api-Key YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "database_type": "postgresql",
    "database_url": "postgresql://user:password@localhost:5432/dbname"
  }'

# 請確認在執行前替換 YOUR_API_KEY 並核對請求資料。
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
const axios = require('axios');

// 設定請求標頭
const config = {
  headers: {
    'Authorization': 'Api-Key YOUR_API_KEY',
    'Content-Type': 'application/json'
  }
};

// 請求內容 (payload)
const data = {
    "database_type": "postgresql",
    "database_url": "postgresql://user:password@localhost:5432/dbname"
  };

axios.post("https://api.maiagent.ai/api/database-connection/test/", data, config)
  .then(response => {
    console.log('成功取得回應:');
    console.log(response.data);
  })
  .catch(error => {
    console.error('請求發生錯誤:');
    console.error(error.response?.data || error.message);
  });
```

{% endtab %}

{% tab title="Python" %}

```python
import requests

url = "https://api.maiagent.ai/api/database-connection/test/"
headers = {
    "Authorization": "Api-Key YOUR_API_KEY",
    "Content-Type": "application/json"
}

# 請求內容 (payload)
data = {
      "database_type": "postgresql",
      "database_url": "postgresql://user:password@localhost:5432/dbname"
    }

response = requests.post(url, json=data, headers=headers)
try:
    print("成功取得回應:")
    print(response.json())
except Exception as e:
    print("請求發生錯誤:", e)
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php
require 'vendor/autoload.php';

$client = new GuzzleHttp\Client();

try {
    $response = $client->post("https://api.maiagent.ai/api/database-connection/test/", [
        'headers' => [
            'Authorization' => 'Api-Key YOUR_API_KEY',
            'Content-Type' => 'application/json'
        ],
        'json' => {
            "database_type": "postgresql",
            "database_url": "postgresql://user:password@localhost:5432/dbname"
        }
    ]);
    
    $data = json_decode($response->getBody(), true);
    echo "成功取得回應:\n";
    print_r($data);
} catch (Exception $e) {
    echo '請求發生錯誤: ' . $e->getMessage();
}
?>
```

{% endtab %}
{% endtabs %}

#### 回應內容

**狀態碼: 200**

**回應結構範例**

```typescript
{
  "status":  // 連線狀態

* `success` - success
* `failed` - failed
  {
  }
  "responseTime"?: number (double) // 回應時間（秒） (非必填)
  "message"?: string // 成功訊息 (非必填)
  "errorMessage"?: string // 錯誤訊息 (非必填)
}
```

**回應範例值**

```json
{
  "status": "success",
  "response_time": 0.123,
  "message": "成功連接到 PostgreSQL 資料庫"
}
```

**狀態碼: 400**

**回應結構範例**

```typescript
{
  "detail"?: string // 非必填
}
```

**回應範例值**

```json
{
  "status": "success",
  "response_time": 0.123,
  "message": "成功連接到 PostgreSQL 資料庫"
}
```

***

### 測試資料庫連線（通用） <a href="#undefined" id="undefined"></a>

POST `/api/v1/database-connection/test/`

#### 請求內容

**請求參數**

| 欄位           | 類型     | 必填 | 說明                                                                                                        |
| ------------ | ------ | -- | --------------------------------------------------------------------------------------------------------- |
| databaseType | object | 是  | 資料庫類型（不包含 MaiAgent 內部使用類型） `postgresql`: PostgreSQL ; `mysql`: MySQL ; `oracle`: Oracle ; `mssql`: MSSQL; |
| databaseUrl  | string | 是  | 資料庫連線字串                                                                                                   |

**請求結構範例**

```typescript
{
  "databaseType":  // 資料庫類型（不包含 MaiAgent 內部使用類型）

* `postgresql` - PostgreSQL
* `mysql` - MySQL
* `oracle` - Oracle
* `mssql` - MSSQL
  {
  }
  "databaseUrl": string // 資料庫連線字串
}
```

**請求範例值**

```json
{
  "database_type": "postgresql",
  "database_url": "postgresql://user:password@localhost:5432/dbname"
}
```

#### 程式碼範例

{% tabs %}
{% tab title="Shell/Bash" %}

```bash
# 呼叫 API 示例 (Shell)
curl -X POST "https://api.maiagent.ai/api/v1/database-connection/test/" \
  -H "Authorization: Api-Key YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "database_type": "postgresql",
    "database_url": "postgresql://user:password@localhost:5432/dbname"
  }'

# 請確認在執行前替換 YOUR_API_KEY 並核對請求資料。
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
const axios = require('axios');

// 設定請求標頭
const config = {
  headers: {
    'Authorization': 'Api-Key YOUR_API_KEY',
    'Content-Type': 'application/json'
  }
};

// 請求內容 (payload)
const data = {
    "database_type": "postgresql",
    "database_url": "postgresql://user:password@localhost:5432/dbname"
  };

axios.post("https://api.maiagent.ai/api/v1/database-connection/test/", data, config)
  .then(response => {
    console.log('成功取得回應:');
    console.log(response.data);
  })
  .catch(error => {
    console.error('請求發生錯誤:');
    console.error(error.response?.data || error.message);
  });
```

{% endtab %}

{% tab title="Python" %}

```python
import requests

url = "https://api.maiagent.ai/api/v1/database-connection/test/"
headers = {
    "Authorization": "Api-Key YOUR_API_KEY",
    "Content-Type": "application/json"
}

# 請求內容 (payload)
data = {
      "database_type": "postgresql",
      "database_url": "postgresql://user:password@localhost:5432/dbname"
    }

response = requests.post(url, json=data, headers=headers)
try:
    print("成功取得回應:")
    print(response.json())
except Exception as e:
    print("請求發生錯誤:", e)
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php
require 'vendor/autoload.php';

$client = new GuzzleHttp\Client();

try {
    $response = $client->post("https://api.maiagent.ai/api/v1/database-connection/test/", [
        'headers' => [
            'Authorization' => 'Api-Key YOUR_API_KEY',
            'Content-Type' => 'application/json'
        ],
        'json' => {
            "database_type": "postgresql",
            "database_url": "postgresql://user:password@localhost:5432/dbname"
        }
    ]);
    
    $data = json_decode($response->getBody(), true);
    echo "成功取得回應:\n";
    print_r($data);
} catch (Exception $e) {
    echo '請求發生錯誤: ' . $e->getMessage();
}
?>
```

{% endtab %}
{% endtabs %}

#### 回應內容

**狀態碼: 200**

**回應結構範例**

```typescript
{
  "status":  // 連線狀態

* `success` - success
* `failed` - failed
  {
  }
  "responseTime"?: number (double) // 回應時間（秒） (非必填)
  "message"?: string // 成功訊息 (非必填)
  "errorMessage"?: string // 錯誤訊息 (非必填)
}
```

**回應範例值**

```json
{
  "status": "success",
  "response_time": 0.123,
  "message": "成功連接到 PostgreSQL 資料庫"
}
```

**狀態碼: 400**

**回應結構範例**

```typescript
{
  "detail"?: string // 非必填
}
```

**回應範例值**

```json
{
  "status": "success",
  "response_time": 0.123,
  "message": "成功連接到 PostgreSQL 資料庫"
}
```

***

### 列出資料庫連線字串範例 <a href="#undefined" id="undefined"></a>

GET `/api/database-examples/`

#### 程式碼範例

{% tabs %}
{% tab title="Shell/Bash" %}

```bash
# 呼叫 API 示例 (Shell)
curl -X GET "https://api.maiagent.ai/api/database-examples/" \
  -H "Authorization: Api-Key YOUR_API_KEY"

# 請確認在執行前替換 YOUR_API_KEY 並核對請求資料。
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
const axios = require('axios');

// 設定請求標頭
const config = {
  headers: {
    'Authorization': 'Api-Key YOUR_API_KEY'
  }
};

axios.get("https://api.maiagent.ai/api/database-examples/", config)
  .then(response => {
    console.log('成功取得回應:');
    console.log(response.data);
  })
  .catch(error => {
    console.error('請求發生錯誤:');
    console.error(error.response?.data || error.message);
  });
```

{% endtab %}

{% tab title="Python" %}

```python
import requests

url = "https://api.maiagent.ai/api/database-examples/"
headers = {
    "Authorization": "Api-Key YOUR_API_KEY"
}


response = requests.get(url, headers=headers)
try:
    print("成功取得回應:")
    print(response.json())
except Exception as e:
    print("請求發生錯誤:", e)
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php
require 'vendor/autoload.php';

$client = new GuzzleHttp\Client();

try {
    $response = $client->get("https://api.maiagent.ai/api/database-examples/", [
        'headers' => [
            'Authorization' => 'Api-Key YOUR_API_KEY'
        ]
    ]);
    
    $data = json_decode($response->getBody(), true);
    echo "成功取得回應:\n";
    print_r($data);
} catch (Exception $e) {
    echo '請求發生錯誤: ' . $e->getMessage();
}
?>
```

{% endtab %}
{% endtabs %}

#### 回應內容

**狀態碼: 200**

**回應結構範例**

```typescript
[
  {
    "databaseType"?:  // 資料庫類型選項

* `postgresql` - PostgreSQL
* `mysql` - MySQL
* `maiagent` - MaiAgent
* `oracle` - Oracle
* `mssql` - MSSQL (非必填)
    {
    }
    "databaseTypeExample": string // 例如：postgresql://db_user:db_password@db_ip:db_port/db_name
  }
]
```

**回應範例值**

```json
[
  {
    "databaseType": {},
    "databaseTypeExample": "回應字串"
  }
]
```

**狀態碼: 401**

**回應結構範例**

```typescript
{
  "detail"?: string // 非必填
}
```

**回應範例值**

```json
{
  "detail": "回應字串"
}
```

***

### 列出資料庫連線字串範例 <a href="#undefined" id="undefined"></a>

GET `/api/v1/database-examples/`

#### 程式碼範例

{% tabs %}
{% tab title="Shell/Bash" %}

```bash
# 呼叫 API 示例 (Shell)
curl -X GET "https://api.maiagent.ai/api/v1/database-examples/" \
  -H "Authorization: Api-Key YOUR_API_KEY"

# 請確認在執行前替換 YOUR_API_KEY 並核對請求資料。
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
const axios = require('axios');

// 設定請求標頭
const config = {
  headers: {
    'Authorization': 'Api-Key YOUR_API_KEY'
  }
};

axios.get("https://api.maiagent.ai/api/v1/database-examples/", config)
  .then(response => {
    console.log('成功取得回應:');
    console.log(response.data);
  })
  .catch(error => {
    console.error('請求發生錯誤:');
    console.error(error.response?.data || error.message);
  });
```

{% endtab %}

{% tab title="Python" %}

```python
import requests

url = "https://api.maiagent.ai/api/v1/database-examples/"
headers = {
    "Authorization": "Api-Key YOUR_API_KEY"
}


response = requests.get(url, headers=headers)
try:
    print("成功取得回應:")
    print(response.json())
except Exception as e:
    print("請求發生錯誤:", e)
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php
require 'vendor/autoload.php';

$client = new GuzzleHttp\Client();

try {
    $response = $client->get("https://api.maiagent.ai/api/v1/database-examples/", [
        'headers' => [
            'Authorization' => 'Api-Key YOUR_API_KEY'
        ]
    ]);
    
    $data = json_decode($response->getBody(), true);
    echo "成功取得回應:\n";
    print_r($data);
} catch (Exception $e) {
    echo '請求發生錯誤: ' . $e->getMessage();
}
?>
```

{% endtab %}
{% endtabs %}

#### 回應內容

**狀態碼: 200**

**回應結構範例**

```typescript
[
  {
    "databaseType"?:  // 資料庫類型選項

* `postgresql` - PostgreSQL
* `mysql` - MySQL
* `maiagent` - MaiAgent
* `oracle` - Oracle
* `mssql` - MSSQL (非必填)
    {
    }
    "databaseTypeExample": string // 例如：postgresql://db_user:db_password@db_ip:db_port/db_name
  }
]
```

**回應範例值**

```json
[
  {
    "databaseType": {},
    "databaseTypeExample": "回應字串"
  }
]
```

**狀態碼: 401**

**回應結構範例**

```typescript
{
  "detail"?: string // 非必填
}
```

**回應範例值**

```json
{
  "detail": "回應字串"
}
```

***

### 取得特定連線字串範例 <a href="#undefined" id="undefined"></a>

GET `/api/database-examples/{id}/`

#### 參數

| 參數名稱 | 必填 | 類型     | 說明                                      |
| ---- | -- | ------ | --------------------------------------- |
| `id` | ✅  | string | A UUID string identifying this 資料庫連線範例. |

#### 程式碼範例

{% tabs %}
{% tab title="Shell/Bash" %}

```bash
# 呼叫 API 示例 (Shell)
curl -X GET "https://api.maiagent.ai/api/database-examples/550e8400-e29b-41d4-a716-446655440000/" \
  -H "Authorization: Api-Key YOUR_API_KEY"

# 請確認在執行前替換 YOUR_API_KEY 並核對請求資料。
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
const axios = require('axios');

// 設定請求標頭
const config = {
  headers: {
    'Authorization': 'Api-Key YOUR_API_KEY'
  }
};

axios.get("https://api.maiagent.ai/api/database-examples/550e8400-e29b-41d4-a716-446655440000/", config)
  .then(response => {
    console.log('成功取得回應:');
    console.log(response.data);
  })
  .catch(error => {
    console.error('請求發生錯誤:');
    console.error(error.response?.data || error.message);
  });
```

{% endtab %}

{% tab title="Python" %}

```python
import requests

url = "https://api.maiagent.ai/api/database-examples/550e8400-e29b-41d4-a716-446655440000/"
headers = {
    "Authorization": "Api-Key YOUR_API_KEY"
}


response = requests.get(url, headers=headers)
try:
    print("成功取得回應:")
    print(response.json())
except Exception as e:
    print("請求發生錯誤:", e)
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php
require 'vendor/autoload.php';

$client = new GuzzleHttp\Client();

try {
    $response = $client->get("https://api.maiagent.ai/api/database-examples/550e8400-e29b-41d4-a716-446655440000/", [
        'headers' => [
            'Authorization' => 'Api-Key YOUR_API_KEY'
        ]
    ]);
    
    $data = json_decode($response->getBody(), true);
    echo "成功取得回應:\n";
    print_r($data);
} catch (Exception $e) {
    echo '請求發生錯誤: ' . $e->getMessage();
}
?>
```

{% endtab %}
{% endtabs %}

#### 回應內容

**狀態碼: 200**

**回應結構範例**

```typescript
{
  "databaseType"?:  // 資料庫類型選項

* `postgresql` - PostgreSQL
* `mysql` - MySQL
* `maiagent` - MaiAgent
* `oracle` - Oracle
* `mssql` - MSSQL (非必填)
  {
  }
  "databaseTypeExample": string // 例如：postgresql://db_user:db_password@db_ip:db_port/db_name
}
```

**回應範例值**

```json
{
  "databaseType": {},
  "databaseTypeExample": "回應字串"
}
```

***

### 取得特定連線字串範例 <a href="#undefined" id="undefined"></a>

GET `/api/v1/database-examples/{id}/`

#### 參數

| 參數名稱 | 必填 | 類型     | 說明                                      |
| ---- | -- | ------ | --------------------------------------- |
| `id` | ✅  | string | A UUID string identifying this 資料庫連線範例. |

#### 程式碼範例

{% tabs %}
{% tab title="Shell/Bash" %}

```bash
# 呼叫 API 示例 (Shell)
curl -X GET "https://api.maiagent.ai/api/v1/database-examples/550e8400-e29b-41d4-a716-446655440000/" \
  -H "Authorization: Api-Key YOUR_API_KEY"

# 請確認在執行前替換 YOUR_API_KEY 並核對請求資料。
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
const axios = require('axios');

// 設定請求標頭
const config = {
  headers: {
    'Authorization': 'Api-Key YOUR_API_KEY'
  }
};

axios.get("https://api.maiagent.ai/api/v1/database-examples/550e8400-e29b-41d4-a716-446655440000/", config)
  .then(response => {
    console.log('成功取得回應:');
    console.log(response.data);
  })
  .catch(error => {
    console.error('請求發生錯誤:');
    console.error(error.response?.data || error.message);
  });
```

{% endtab %}

{% tab title="Python" %}

```python
import requests

url = "https://api.maiagent.ai/api/v1/database-examples/550e8400-e29b-41d4-a716-446655440000/"
headers = {
    "Authorization": "Api-Key YOUR_API_KEY"
}


response = requests.get(url, headers=headers)
try:
    print("成功取得回應:")
    print(response.json())
except Exception as e:
    print("請求發生錯誤:", e)
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php
require 'vendor/autoload.php';

$client = new GuzzleHttp\Client();

try {
    $response = $client->get("https://api.maiagent.ai/api/v1/database-examples/550e8400-e29b-41d4-a716-446655440000/", [
        'headers' => [
            'Authorization' => 'Api-Key YOUR_API_KEY'
        ]
    ]);
    
    $data = json_decode($response->getBody(), true);
    echo "成功取得回應:\n";
    print_r($data);
} catch (Exception $e) {
    echo '請求發生錯誤: ' . $e->getMessage();
}
?>
```

{% endtab %}
{% endtabs %}

#### 回應內容

**狀態碼: 200**

**回應結構範例**

```typescript
{
  "databaseType"?:  // 資料庫類型選項

* `postgresql` - PostgreSQL
* `mysql` - MySQL
* `maiagent` - MaiAgent
* `oracle` - Oracle
* `mssql` - MSSQL (非必填)
  {
  }
  "databaseTypeExample": string // 例如：postgresql://db_user:db_password@db_ip:db_port/db_name
}
```

**回應範例值**

```json
{
  "databaseType": {},
  "databaseTypeExample": "回應字串"
}
```

***

### 列出 AI 助理的資料庫配置 <a href="#ai" id="ai"></a>

GET `/api/chatbots/{chatbotPk}/databases/`

#### 參數

| 參數名稱        | 必填 | 類型      | 說明                                             |
| ----------- | -- | ------- | ---------------------------------------------- |
| `chatbotPk` | ✅  | string  | A UUID string identifying this Chatbot ID      |
| `page`      | ❌  | integer | A page number within the paginated result set. |
| `pageSize`  | ❌  | integer | Number of results to return per page.          |

#### 程式碼範例

{% tabs %}
{% tab title="Shell/Bash" %}

```bash
# 呼叫 API 示例 (Shell)
curl -X GET "https://api.maiagent.ai/api/chatbots/550e8400-e29b-41d4-a716-446655440000/databases/?page=1&pageSize=1" \
  -H "Authorization: Api-Key YOUR_API_KEY"

# 請確認在執行前替換 YOUR_API_KEY 並核對請求資料。
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
const axios = require('axios');

// 設定請求標頭
const config = {
  headers: {
    'Authorization': 'Api-Key YOUR_API_KEY'
  }
};

axios.get("https://api.maiagent.ai/api/chatbots/550e8400-e29b-41d4-a716-446655440000/databases/?page=1&pageSize=1", config)
  .then(response => {
    console.log('成功取得回應:');
    console.log(response.data);
  })
  .catch(error => {
    console.error('請求發生錯誤:');
    console.error(error.response?.data || error.message);
  });
```

{% endtab %}

{% tab title="Python" %}

```python
import requests

url = "https://api.maiagent.ai/api/chatbots/550e8400-e29b-41d4-a716-446655440000/databases/?page=1&pageSize=1"
headers = {
    "Authorization": "Api-Key YOUR_API_KEY"
}


response = requests.get(url, headers=headers)
try:
    print("成功取得回應:")
    print(response.json())
except Exception as e:
    print("請求發生錯誤:", e)
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php
require 'vendor/autoload.php';

$client = new GuzzleHttp\Client();

try {
    $response = $client->get("https://api.maiagent.ai/api/chatbots/550e8400-e29b-41d4-a716-446655440000/databases/?page=1&pageSize=1", [
        'headers' => [
            'Authorization' => 'Api-Key YOUR_API_KEY'
        ]
    ]);
    
    $data = json_decode($response->getBody(), true);
    echo "成功取得回應:\n";
    print_r($data);
} catch (Exception $e) {
    echo '請求發生錯誤: ' . $e->getMessage();
}
?>
```

{% endtab %}
{% endtabs %}

#### 回應內容

**狀態碼: 200**

**回應結構範例**

```typescript
{
  "count": integer
  "next"?: string (uri) // 非必填
  "previous"?: string (uri) // 非必填
  "results": [
    {
      "id": string (uuid)
      "name": string // 顯示用的名稱，例如：主要業務DB、分析DB
      "databaseType":  // 資料庫類型選項，有 MySQL、PostgreSQL、MSSQL、Oracle、MaiAgent

* `postgresql` - PostgreSQL
* `mysql` - MySQL
* `maiagent` - MaiAgent
* `oracle` - Oracle
* `mssql` - MSSQL
      {
      }
      "databaseUrl": string // 資料庫連線字串
      "includeTables"?: object // 指定要查詢的資料表列表，格式: {"tables": ["table1", "table2"]}。MaiAgent 類型會自動從上傳的檔案中取得，不需要手動設定 (非必填)
      "isActive"?: boolean // 停用後將不會在 Text-to-SQL 查詢中使用此資料庫 (非必填)
      "createdAt": string (timestamp)
      "updatedAt": string (timestamp)
    }
  ]
}
```

**回應範例值**

```json
{
  "count": 123,
  "next": "http://api.example.org/accounts/?page=4",
  "previous": "http://api.example.org/accounts/?page=2",
  "results": [
    {
      "id": "550e8400-e29b-41d4-a716-446655440000",
      "name": "回應字串",
      "databaseType": {},
      "databaseUrl": "回應字串",
      "includeTables": null,
      "isActive": false,
      "createdAt": "回應字串",
      "updatedAt": "回應字串"
    }
  ]
}
```

***

### 列出 AI 助理的資料庫配置 <a href="#ai" id="ai"></a>

GET `/api/v1/chatbots/{chatbotPk}/databases/`

#### 參數

| 參數名稱        | 必填 | 類型      | 說明                                             |
| ----------- | -- | ------- | ---------------------------------------------- |
| `chatbotPk` | ✅  | string  | A UUID string identifying this Chatbot ID      |
| `page`      | ❌  | integer | A page number within the paginated result set. |
| `pageSize`  | ❌  | integer | Number of results to return per page.          |

#### 程式碼範例

{% tabs %}
{% tab title="Shell/Bash" %}

```bash
# 呼叫 API 示例 (Shell)
curl -X GET "https://api.maiagent.ai/api/v1/chatbots/550e8400-e29b-41d4-a716-446655440000/databases/?page=1&pageSize=1" \
  -H "Authorization: Api-Key YOUR_API_KEY"

# 請確認在執行前替換 YOUR_API_KEY 並核對請求資料。
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
const axios = require('axios');

// 設定請求標頭
const config = {
  headers: {
    'Authorization': 'Api-Key YOUR_API_KEY'
  }
};

axios.get("https://api.maiagent.ai/api/v1/chatbots/550e8400-e29b-41d4-a716-446655440000/databases/?page=1&pageSize=1", config)
  .then(response => {
    console.log('成功取得回應:');
    console.log(response.data);
  })
  .catch(error => {
    console.error('請求發生錯誤:');
    console.error(error.response?.data || error.message);
  });
```

{% endtab %}

{% tab title="Python" %}

```python
import requests

url = "https://api.maiagent.ai/api/v1/chatbots/550e8400-e29b-41d4-a716-446655440000/databases/?page=1&pageSize=1"
headers = {
    "Authorization": "Api-Key YOUR_API_KEY"
}


response = requests.get(url, headers=headers)
try:
    print("成功取得回應:")
    print(response.json())
except Exception as e:
    print("請求發生錯誤:", e)
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php
require 'vendor/autoload.php';

$client = new GuzzleHttp\Client();

try {
    $response = $client->get("https://api.maiagent.ai/api/v1/chatbots/550e8400-e29b-41d4-a716-446655440000/databases/?page=1&pageSize=1", [
        'headers' => [
            'Authorization' => 'Api-Key YOUR_API_KEY'
        ]
    ]);
    
    $data = json_decode($response->getBody(), true);
    echo "成功取得回應:\n";
    print_r($data);
} catch (Exception $e) {
    echo '請求發生錯誤: ' . $e->getMessage();
}
?>
```

{% endtab %}
{% endtabs %}

#### 回應內容

**狀態碼: 200**

**回應結構範例**

```typescript
{
  "count": integer
  "next"?: string (uri) // 非必填
  "previous"?: string (uri) // 非必填
  "results": [
    {
      "id": string (uuid)
      "name": string // 顯示用的名稱，例如：主要業務DB、分析DB
      "databaseType":  // 資料庫類型選項，有 MySQL、PostgreSQL、MSSQL、Oracle、MaiAgent

* `postgresql` - PostgreSQL
* `mysql` - MySQL
* `maiagent` - MaiAgent
* `oracle` - Oracle
* `mssql` - MSSQL
      {
      }
      "databaseUrl": string // 資料庫連線字串
      "includeTables"?: object // 指定要查詢的資料表列表，格式: {"tables": ["table1", "table2"]}。MaiAgent 類型會自動從上傳的檔案中取得，不需要手動設定 (非必填)
      "isActive"?: boolean // 停用後將不會在 Text-to-SQL 查詢中使用此資料庫 (非必填)
      "createdAt": string (timestamp)
      "updatedAt": string (timestamp)
    }
  ]
}
```

**回應範例值**

```json
{
  "count": 123,
  "next": "http://api.example.org/accounts/?page=4",
  "previous": "http://api.example.org/accounts/?page=2",
  "results": [
    {
      "id": "550e8400-e29b-41d4-a716-446655440000",
      "name": "回應字串",
      "databaseType": {},
      "databaseUrl": "回應字串",
      "includeTables": null,
      "isActive": false,
      "createdAt": "回應字串",
      "updatedAt": "回應字串"
    }
  ]
}
```

***

### 新增 AI 助理的資料庫配置 <a href="#ai" id="ai"></a>

POST `/api/chatbots/{chatbotPk}/databases/`

#### 參數

| 參數名稱        | 必填 | 類型     | 說明                                        |
| ----------- | -- | ------ | ----------------------------------------- |
| `chatbotPk` | ✅  | string | A UUID string identifying this Chatbot ID |

#### 請求內容

**請求參數**

| 欄位            | 類型      | 必填 | 說明                                                                                                                                                     |
| ------------- | ------- | -- | ------------------------------------------------------------------------------------------------------------------------------------------------------ |
| name          | string  | 是  | 顯示用的名稱，例如：主要業務DB、分析DB                                                                                                                                  |
| databaseType  | object  | 是  | 資料庫類型選項，有 MySQL、PostgreSQL、MSSQL、Oracle、MaiAgent `postgresql`: PostgreSQL ; `mysql`: MySQL ; `maiagent`: MaiAgent ; `oracle`: Oracle ; `mssql`: MSSQL; |
| databaseUrl   | string  | 是  | 資料庫連線字串                                                                                                                                                |
| includeTables | object  | 否  | 指定要查詢的資料表列表，格式: {"tables": \["table1", "table2"]}。MaiAgent 類型會自動從上傳的檔案中取得，不需要手動設定                                                                      |
| isActive      | boolean | 否  | 停用後將不會在 Text-to-SQL 查詢中使用此資料庫                                                                                                                          |

**請求結構範例**

```typescript
{
  "name": string // 顯示用的名稱，例如：主要業務DB、分析DB
  "databaseType":  // 資料庫類型選項，有 MySQL、PostgreSQL、MSSQL、Oracle、MaiAgent

* `postgresql` - PostgreSQL
* `mysql` - MySQL
* `maiagent` - MaiAgent
* `oracle` - Oracle
* `mssql` - MSSQL
  {
  }
  "databaseUrl": string // 資料庫連線字串
  "includeTables"?: object // 指定要查詢的資料表列表，格式: {"tables": ["table1", "table2"]}。MaiAgent 類型會自動從上傳的檔案中取得，不需要手動設定 (非必填)
  "isActive"?: boolean // 停用後將不會在 Text-to-SQL 查詢中使用此資料庫 (非必填)
}
```

**請求範例值**

```json
{
  "name": "範例名稱",
  "databaseType": {},
  "databaseUrl": "範例字串",
  "includeTables": null,
  "isActive": true
}
```

#### 程式碼範例

{% tabs %}
{% tab title="Shell/Bash" %}

```bash
# 呼叫 API 示例 (Shell)
curl -X POST "https://api.maiagent.ai/api/chatbots/550e8400-e29b-41d4-a716-446655440000/databases/" \
  -H "Authorization: Api-Key YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "範例名稱",
    "databaseType": {},
    "databaseUrl": "範例字串",
    "includeTables": null,
    "isActive": true
  }'

# 請確認在執行前替換 YOUR_API_KEY 並核對請求資料。
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
const axios = require('axios');

// 設定請求標頭
const config = {
  headers: {
    'Authorization': 'Api-Key YOUR_API_KEY',
    'Content-Type': 'application/json'
  }
};

// 請求內容 (payload)
const data = {
    "name": "範例名稱",
    "databaseType": {},
    "databaseUrl": "範例字串",
    "includeTables": null,
    "isActive": true
  };

axios.post("https://api.maiagent.ai/api/chatbots/550e8400-e29b-41d4-a716-446655440000/databases/", data, config)
  .then(response => {
    console.log('成功取得回應:');
    console.log(response.data);
  })
  .catch(error => {
    console.error('請求發生錯誤:');
    console.error(error.response?.data || error.message);
  });
```

{% endtab %}

{% tab title="Python" %}

```python
import requests

url = "https://api.maiagent.ai/api/chatbots/550e8400-e29b-41d4-a716-446655440000/databases/"
headers = {
    "Authorization": "Api-Key YOUR_API_KEY",
    "Content-Type": "application/json"
}

# 請求內容 (payload)
data = {
      "name": "範例名稱",
      "databaseType": {},
      "databaseUrl": "範例字串",
      "includeTables": null,
      "isActive": true
    }

response = requests.post(url, json=data, headers=headers)
try:
    print("成功取得回應:")
    print(response.json())
except Exception as e:
    print("請求發生錯誤:", e)
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php
require 'vendor/autoload.php';

$client = new GuzzleHttp\Client();

try {
    $response = $client->post("https://api.maiagent.ai/api/chatbots/550e8400-e29b-41d4-a716-446655440000/databases/", [
        'headers' => [
            'Authorization' => 'Api-Key YOUR_API_KEY',
            'Content-Type' => 'application/json'
        ],
        'json' => {
            "name": "範例名稱",
            "databaseType": {},
            "databaseUrl": "範例字串",
            "includeTables": null,
            "isActive": true
        }
    ]);
    
    $data = json_decode($response->getBody(), true);
    echo "成功取得回應:\n";
    print_r($data);
} catch (Exception $e) {
    echo '請求發生錯誤: ' . $e->getMessage();
}
?>
```

{% endtab %}
{% endtabs %}

#### 回應內容

**狀態碼: 201**

**回應結構範例**

```typescript
{
  "id": string (uuid)
  "name": string // 顯示用的名稱，例如：主要業務DB、分析DB
  "databaseType":  // 資料庫類型選項，有 MySQL、PostgreSQL、MSSQL、Oracle、MaiAgent

* `postgresql` - PostgreSQL
* `mysql` - MySQL
* `maiagent` - MaiAgent
* `oracle` - Oracle
* `mssql` - MSSQL
  {
  }
  "databaseUrl": string // 資料庫連線字串
  "includeTables"?: object // 指定要查詢的資料表列表，格式: {"tables": ["table1", "table2"]}。MaiAgent 類型會自動從上傳的檔案中取得，不需要手動設定 (非必填)
  "isActive"?: boolean // 停用後將不會在 Text-to-SQL 查詢中使用此資料庫 (非必填)
  "createdAt": string (timestamp)
  "updatedAt": string (timestamp)
}
```

**回應範例值**

```json
{
  "id": "550e8400-e29b-41d4-a716-446655440000",
  "name": "回應字串",
  "databaseType": {},
  "databaseUrl": "回應字串",
  "includeTables": null,
  "isActive": false,
  "createdAt": "回應字串",
  "updatedAt": "回應字串"
}
```

***

### 新增 AI 助理的資料庫配置 <a href="#ai" id="ai"></a>

POST `/api/v1/chatbots/{chatbotPk}/databases/`

#### 參數

| 參數名稱        | 必填 | 類型     | 說明                                        |
| ----------- | -- | ------ | ----------------------------------------- |
| `chatbotPk` | ✅  | string | A UUID string identifying this Chatbot ID |

#### 請求內容

**請求參數**

| 欄位            | 類型      | 必填 | 說明                                                                                                                                                     |
| ------------- | ------- | -- | ------------------------------------------------------------------------------------------------------------------------------------------------------ |
| name          | string  | 是  | 顯示用的名稱，例如：主要業務DB、分析DB                                                                                                                                  |
| databaseType  | object  | 是  | 資料庫類型選項，有 MySQL、PostgreSQL、MSSQL、Oracle、MaiAgent `postgresql`: PostgreSQL ; `mysql`: MySQL ; `maiagent`: MaiAgent ; `oracle`: Oracle ; `mssql`: MSSQL; |
| databaseUrl   | string  | 是  | 資料庫連線字串                                                                                                                                                |
| includeTables | object  | 否  | 指定要查詢的資料表列表，格式: {"tables": \["table1", "table2"]}。MaiAgent 類型會自動從上傳的檔案中取得，不需要手動設定                                                                      |
| isActive      | boolean | 否  | 停用後將不會在 Text-to-SQL 查詢中使用此資料庫                                                                                                                          |

**請求結構範例**

```typescript
{
  "name": string // 顯示用的名稱，例如：主要業務DB、分析DB
  "databaseType":  // 資料庫類型選項，有 MySQL、PostgreSQL、MSSQL、Oracle、MaiAgent

* `postgresql` - PostgreSQL
* `mysql` - MySQL
* `maiagent` - MaiAgent
* `oracle` - Oracle
* `mssql` - MSSQL
  {
  }
  "databaseUrl": string // 資料庫連線字串
  "includeTables"?: object // 指定要查詢的資料表列表，格式: {"tables": ["table1", "table2"]}。MaiAgent 類型會自動從上傳的檔案中取得，不需要手動設定 (非必填)
  "isActive"?: boolean // 停用後將不會在 Text-to-SQL 查詢中使用此資料庫 (非必填)
}
```

**請求範例值**

```json
{
  "name": "範例名稱",
  "databaseType": {},
  "databaseUrl": "範例字串",
  "includeTables": null,
  "isActive": true
}
```

#### 程式碼範例

{% tabs %}
{% tab title="Shell/Bash" %}

```bash
# 呼叫 API 示例 (Shell)
curl -X POST "https://api.maiagent.ai/api/v1/chatbots/550e8400-e29b-41d4-a716-446655440000/databases/" \
  -H "Authorization: Api-Key YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "範例名稱",
    "databaseType": {},
    "databaseUrl": "範例字串",
    "includeTables": null,
    "isActive": true
  }'

# 請確認在執行前替換 YOUR_API_KEY 並核對請求資料。
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
const axios = require('axios');

// 設定請求標頭
const config = {
  headers: {
    'Authorization': 'Api-Key YOUR_API_KEY',
    'Content-Type': 'application/json'
  }
};

// 請求內容 (payload)
const data = {
    "name": "範例名稱",
    "databaseType": {},
    "databaseUrl": "範例字串",
    "includeTables": null,
    "isActive": true
  };

axios.post("https://api.maiagent.ai/api/v1/chatbots/550e8400-e29b-41d4-a716-446655440000/databases/", data, config)
  .then(response => {
    console.log('成功取得回應:');
    console.log(response.data);
  })
  .catch(error => {
    console.error('請求發生錯誤:');
    console.error(error.response?.data || error.message);
  });
```

{% endtab %}

{% tab title="Python" %}

```python
import requests

url = "https://api.maiagent.ai/api/v1/chatbots/550e8400-e29b-41d4-a716-446655440000/databases/"
headers = {
    "Authorization": "Api-Key YOUR_API_KEY",
    "Content-Type": "application/json"
}

# 請求內容 (payload)
data = {
      "name": "範例名稱",
      "databaseType": {},
      "databaseUrl": "範例字串",
      "includeTables": null,
      "isActive": true
    }

response = requests.post(url, json=data, headers=headers)
try:
    print("成功取得回應:")
    print(response.json())
except Exception as e:
    print("請求發生錯誤:", e)
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php
require 'vendor/autoload.php';

$client = new GuzzleHttp\Client();

try {
    $response = $client->post("https://api.maiagent.ai/api/v1/chatbots/550e8400-e29b-41d4-a716-446655440000/databases/", [
        'headers' => [
            'Authorization' => 'Api-Key YOUR_API_KEY',
            'Content-Type' => 'application/json'
        ],
        'json' => {
            "name": "範例名稱",
            "databaseType": {},
            "databaseUrl": "範例字串",
            "includeTables": null,
            "isActive": true
        }
    ]);
    
    $data = json_decode($response->getBody(), true);
    echo "成功取得回應:\n";
    print_r($data);
} catch (Exception $e) {
    echo '請求發生錯誤: ' . $e->getMessage();
}
?>
```

{% endtab %}
{% endtabs %}

#### 回應內容

**狀態碼: 201**

**回應結構範例**

```typescript
{
  "id": string (uuid)
  "name": string // 顯示用的名稱，例如：主要業務DB、分析DB
  "databaseType":  // 資料庫類型選項，有 MySQL、PostgreSQL、MSSQL、Oracle、MaiAgent

* `postgresql` - PostgreSQL
* `mysql` - MySQL
* `maiagent` - MaiAgent
* `oracle` - Oracle
* `mssql` - MSSQL
  {
  }
  "databaseUrl": string // 資料庫連線字串
  "includeTables"?: object // 指定要查詢的資料表列表，格式: {"tables": ["table1", "table2"]}。MaiAgent 類型會自動從上傳的檔案中取得，不需要手動設定 (非必填)
  "isActive"?: boolean // 停用後將不會在 Text-to-SQL 查詢中使用此資料庫 (非必填)
  "createdAt": string (timestamp)
  "updatedAt": string (timestamp)
}
```

**回應範例值**

```json
{
  "id": "550e8400-e29b-41d4-a716-446655440000",
  "name": "回應字串",
  "databaseType": {},
  "databaseUrl": "回應字串",
  "includeTables": null,
  "isActive": false,
  "createdAt": "回應字串",
  "updatedAt": "回應字串"
}
```

***

### 取得特定資料庫配置 <a href="#undefined" id="undefined"></a>

GET `/api/chatbots/{chatbotPk}/databases/{id}/`

#### 參數

| 參數名稱        | 必填 | 類型     | 說明                                            |
| ----------- | -- | ------ | --------------------------------------------- |
| `chatbotPk` | ✅  | string | A UUID string identifying this Chatbot ID     |
| `id`        | ✅  | string | A UUID string identifying this Chatbot 資料庫配置. |

#### 程式碼範例

{% tabs %}
{% tab title="Shell/Bash" %}

```bash
# 呼叫 API 示例 (Shell)
curl -X GET "https://api.maiagent.ai/api/chatbots/550e8400-e29b-41d4-a716-446655440000/databases/550e8400-e29b-41d4-a716-446655440000/" \
  -H "Authorization: Api-Key YOUR_API_KEY"

# 請確認在執行前替換 YOUR_API_KEY 並核對請求資料。
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
const axios = require('axios');

// 設定請求標頭
const config = {
  headers: {
    'Authorization': 'Api-Key YOUR_API_KEY'
  }
};

axios.get("https://api.maiagent.ai/api/chatbots/550e8400-e29b-41d4-a716-446655440000/databases/550e8400-e29b-41d4-a716-446655440000/", config)
  .then(response => {
    console.log('成功取得回應:');
    console.log(response.data);
  })
  .catch(error => {
    console.error('請求發生錯誤:');
    console.error(error.response?.data || error.message);
  });
```

{% endtab %}

{% tab title="Python" %}

```python
import requests

url = "https://api.maiagent.ai/api/chatbots/550e8400-e29b-41d4-a716-446655440000/databases/550e8400-e29b-41d4-a716-446655440000/"
headers = {
    "Authorization": "Api-Key YOUR_API_KEY"
}


response = requests.get(url, headers=headers)
try:
    print("成功取得回應:")
    print(response.json())
except Exception as e:
    print("請求發生錯誤:", e)
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php
require 'vendor/autoload.php';

$client = new GuzzleHttp\Client();

try {
    $response = $client->get("https://api.maiagent.ai/api/chatbots/550e8400-e29b-41d4-a716-446655440000/databases/550e8400-e29b-41d4-a716-446655440000/", [
        'headers' => [
            'Authorization' => 'Api-Key YOUR_API_KEY'
        ]
    ]);
    
    $data = json_decode($response->getBody(), true);
    echo "成功取得回應:\n";
    print_r($data);
} catch (Exception $e) {
    echo '請求發生錯誤: ' . $e->getMessage();
}
?>
```

{% endtab %}
{% endtabs %}

#### 回應內容

**狀態碼: 200**

**回應結構範例**

```typescript
{
  "id": string (uuid)
  "name": string // 顯示用的名稱，例如：主要業務DB、分析DB
  "databaseType":  // 資料庫類型選項，有 MySQL、PostgreSQL、MSSQL、Oracle、MaiAgent

* `postgresql` - PostgreSQL
* `mysql` - MySQL
* `maiagent` - MaiAgent
* `oracle` - Oracle
* `mssql` - MSSQL
  {
  }
  "databaseUrl": string // 資料庫連線字串
  "includeTables"?: object // 指定要查詢的資料表列表，格式: {"tables": ["table1", "table2"]}。MaiAgent 類型會自動從上傳的檔案中取得，不需要手動設定 (非必填)
  "isActive"?: boolean // 停用後將不會在 Text-to-SQL 查詢中使用此資料庫 (非必填)
  "createdAt": string (timestamp)
  "updatedAt": string (timestamp)
}
```

**回應範例值**

```json
{
  "id": "550e8400-e29b-41d4-a716-446655440000",
  "name": "回應字串",
  "databaseType": {},
  "databaseUrl": "回應字串",
  "includeTables": null,
  "isActive": false,
  "createdAt": "回應字串",
  "updatedAt": "回應字串"
}
```

***

### 取得特定資料庫配置 <a href="#undefined" id="undefined"></a>

GET `/api/v1/chatbots/{chatbotPk}/databases/{id}/`

#### 參數

| 參數名稱        | 必填 | 類型     | 說明                                            |
| ----------- | -- | ------ | --------------------------------------------- |
| `chatbotPk` | ✅  | string | A UUID string identifying this Chatbot ID     |
| `id`        | ✅  | string | A UUID string identifying this Chatbot 資料庫配置. |

#### 程式碼範例

{% tabs %}
{% tab title="Shell/Bash" %}

```bash
# 呼叫 API 示例 (Shell)
curl -X GET "https://api.maiagent.ai/api/v1/chatbots/550e8400-e29b-41d4-a716-446655440000/databases/550e8400-e29b-41d4-a716-446655440000/" \
  -H "Authorization: Api-Key YOUR_API_KEY"

# 請確認在執行前替換 YOUR_API_KEY 並核對請求資料。
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
const axios = require('axios');

// 設定請求標頭
const config = {
  headers: {
    'Authorization': 'Api-Key YOUR_API_KEY'
  }
};

axios.get("https://api.maiagent.ai/api/v1/chatbots/550e8400-e29b-41d4-a716-446655440000/databases/550e8400-e29b-41d4-a716-446655440000/", config)
  .then(response => {
    console.log('成功取得回應:');
    console.log(response.data);
  })
  .catch(error => {
    console.error('請求發生錯誤:');
    console.error(error.response?.data || error.message);
  });
```

{% endtab %}

{% tab title="Python" %}

```python
import requests

url = "https://api.maiagent.ai/api/v1/chatbots/550e8400-e29b-41d4-a716-446655440000/databases/550e8400-e29b-41d4-a716-446655440000/"
headers = {
    "Authorization": "Api-Key YOUR_API_KEY"
}


response = requests.get(url, headers=headers)
try:
    print("成功取得回應:")
    print(response.json())
except Exception as e:
    print("請求發生錯誤:", e)
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php
require 'vendor/autoload.php';

$client = new GuzzleHttp\Client();

try {
    $response = $client->get("https://api.maiagent.ai/api/v1/chatbots/550e8400-e29b-41d4-a716-446655440000/databases/550e8400-e29b-41d4-a716-446655440000/", [
        'headers' => [
            'Authorization' => 'Api-Key YOUR_API_KEY'
        ]
    ]);
    
    $data = json_decode($response->getBody(), true);
    echo "成功取得回應:\n";
    print_r($data);
} catch (Exception $e) {
    echo '請求發生錯誤: ' . $e->getMessage();
}
?>
```

{% endtab %}
{% endtabs %}

#### 回應內容

**狀態碼: 200**

**回應結構範例**

```typescript
{
  "id": string (uuid)
  "name": string // 顯示用的名稱，例如：主要業務DB、分析DB
  "databaseType":  // 資料庫類型選項，有 MySQL、PostgreSQL、MSSQL、Oracle、MaiAgent

* `postgresql` - PostgreSQL
* `mysql` - MySQL
* `maiagent` - MaiAgent
* `oracle` - Oracle
* `mssql` - MSSQL
  {
  }
  "databaseUrl": string // 資料庫連線字串
  "includeTables"?: object // 指定要查詢的資料表列表，格式: {"tables": ["table1", "table2"]}。MaiAgent 類型會自動從上傳的檔案中取得，不需要手動設定 (非必填)
  "isActive"?: boolean // 停用後將不會在 Text-to-SQL 查詢中使用此資料庫 (非必填)
  "createdAt": string (timestamp)
  "updatedAt": string (timestamp)
}
```

**回應範例值**

```json
{
  "id": "550e8400-e29b-41d4-a716-446655440000",
  "name": "回應字串",
  "databaseType": {},
  "databaseUrl": "回應字串",
  "includeTables": null,
  "isActive": false,
  "createdAt": "回應字串",
  "updatedAt": "回應字串"
}
```

***

### 更新資料庫配置 <a href="#undefined" id="undefined"></a>

PUT `/api/chatbots/{chatbotPk}/databases/{id}/`

#### 參數

| 參數名稱        | 必填 | 類型     | 說明                                            |
| ----------- | -- | ------ | --------------------------------------------- |
| `chatbotPk` | ✅  | string | A UUID string identifying this Chatbot ID     |
| `id`        | ✅  | string | A UUID string identifying this Chatbot 資料庫配置. |

#### 請求內容

**請求參數**

| 欄位            | 類型      | 必填 | 說明                                                                                                                                                     |
| ------------- | ------- | -- | ------------------------------------------------------------------------------------------------------------------------------------------------------ |
| name          | string  | 是  | 顯示用的名稱，例如：主要業務DB、分析DB                                                                                                                                  |
| databaseType  | object  | 是  | 資料庫類型選項，有 MySQL、PostgreSQL、MSSQL、Oracle、MaiAgent `postgresql`: PostgreSQL ; `mysql`: MySQL ; `maiagent`: MaiAgent ; `oracle`: Oracle ; `mssql`: MSSQL; |
| databaseUrl   | string  | 是  | 資料庫連線字串                                                                                                                                                |
| includeTables | object  | 否  | 指定要查詢的資料表列表，格式: {"tables": \["table1", "table2"]}。MaiAgent 類型會自動從上傳的檔案中取得，不需要手動設定                                                                      |
| isActive      | boolean | 否  | 停用後將不會在 Text-to-SQL 查詢中使用此資料庫                                                                                                                          |

**請求結構範例**

```typescript
{
  "name": string // 顯示用的名稱，例如：主要業務DB、分析DB
  "databaseType":  // 資料庫類型選項，有 MySQL、PostgreSQL、MSSQL、Oracle、MaiAgent

* `postgresql` - PostgreSQL
* `mysql` - MySQL
* `maiagent` - MaiAgent
* `oracle` - Oracle
* `mssql` - MSSQL
  {
  }
  "databaseUrl": string // 資料庫連線字串
  "includeTables"?: object // 指定要查詢的資料表列表，格式: {"tables": ["table1", "table2"]}。MaiAgent 類型會自動從上傳的檔案中取得，不需要手動設定 (非必填)
  "isActive"?: boolean // 停用後將不會在 Text-to-SQL 查詢中使用此資料庫 (非必填)
}
```

**請求範例值**

```json
{
  "name": "範例名稱",
  "databaseType": {},
  "databaseUrl": "範例字串",
  "includeTables": null,
  "isActive": true
}
```

#### 程式碼範例

{% tabs %}
{% tab title="Shell/Bash" %}

```bash
# 呼叫 API 示例 (Shell)
curl -X PUT "https://api.maiagent.ai/api/chatbots/550e8400-e29b-41d4-a716-446655440000/databases/550e8400-e29b-41d4-a716-446655440000/" \
  -H "Authorization: Api-Key YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "範例名稱",
    "databaseType": {},
    "databaseUrl": "範例字串",
    "includeTables": null,
    "isActive": true
  }'

# 請確認在執行前替換 YOUR_API_KEY 並核對請求資料。
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
const axios = require('axios');

// 設定請求標頭
const config = {
  headers: {
    'Authorization': 'Api-Key YOUR_API_KEY',
    'Content-Type': 'application/json'
  }
};

// 請求內容 (payload)
const data = {
    "name": "範例名稱",
    "databaseType": {},
    "databaseUrl": "範例字串",
    "includeTables": null,
    "isActive": true
  };

axios.put("https://api.maiagent.ai/api/chatbots/550e8400-e29b-41d4-a716-446655440000/databases/550e8400-e29b-41d4-a716-446655440000/", data, config)
  .then(response => {
    console.log('成功取得回應:');
    console.log(response.data);
  })
  .catch(error => {
    console.error('請求發生錯誤:');
    console.error(error.response?.data || error.message);
  });
```

{% endtab %}

{% tab title="Python" %}

```python
import requests

url = "https://api.maiagent.ai/api/chatbots/550e8400-e29b-41d4-a716-446655440000/databases/550e8400-e29b-41d4-a716-446655440000/"
headers = {
    "Authorization": "Api-Key YOUR_API_KEY",
    "Content-Type": "application/json"
}

# 請求內容 (payload)
data = {
      "name": "範例名稱",
      "databaseType": {},
      "databaseUrl": "範例字串",
      "includeTables": null,
      "isActive": true
    }

response = requests.put(url, json=data, headers=headers)
try:
    print("成功取得回應:")
    print(response.json())
except Exception as e:
    print("請求發生錯誤:", e)
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php
require 'vendor/autoload.php';

$client = new GuzzleHttp\Client();

try {
    $response = $client->put("https://api.maiagent.ai/api/chatbots/550e8400-e29b-41d4-a716-446655440000/databases/550e8400-e29b-41d4-a716-446655440000/", [
        'headers' => [
            'Authorization' => 'Api-Key YOUR_API_KEY',
            'Content-Type' => 'application/json'
        ],
        'json' => {
            "name": "範例名稱",
            "databaseType": {},
            "databaseUrl": "範例字串",
            "includeTables": null,
            "isActive": true
        }
    ]);
    
    $data = json_decode($response->getBody(), true);
    echo "成功取得回應:\n";
    print_r($data);
} catch (Exception $e) {
    echo '請求發生錯誤: ' . $e->getMessage();
}
?>
```

{% endtab %}
{% endtabs %}

#### 回應內容

**狀態碼: 200**

**回應結構範例**

```typescript
{
  "id": string (uuid)
  "name": string // 顯示用的名稱，例如：主要業務DB、分析DB
  "databaseType":  // 資料庫類型選項，有 MySQL、PostgreSQL、MSSQL、Oracle、MaiAgent

* `postgresql` - PostgreSQL
* `mysql` - MySQL
* `maiagent` - MaiAgent
* `oracle` - Oracle
* `mssql` - MSSQL
  {
  }
  "databaseUrl": string // 資料庫連線字串
  "includeTables"?: object // 指定要查詢的資料表列表，格式: {"tables": ["table1", "table2"]}。MaiAgent 類型會自動從上傳的檔案中取得，不需要手動設定 (非必填)
  "isActive"?: boolean // 停用後將不會在 Text-to-SQL 查詢中使用此資料庫 (非必填)
  "createdAt": string (timestamp)
  "updatedAt": string (timestamp)
}
```

**回應範例值**

```json
{
  "id": "550e8400-e29b-41d4-a716-446655440000",
  "name": "回應字串",
  "databaseType": {},
  "databaseUrl": "回應字串",
  "includeTables": null,
  "isActive": false,
  "createdAt": "回應字串",
  "updatedAt": "回應字串"
}
```

***

### 更新資料庫配置 <a href="#undefined" id="undefined"></a>

PUT `/api/v1/chatbots/{chatbotPk}/databases/{id}/`

#### 參數

| 參數名稱        | 必填 | 類型     | 說明                                            |
| ----------- | -- | ------ | --------------------------------------------- |
| `chatbotPk` | ✅  | string | A UUID string identifying this Chatbot ID     |
| `id`        | ✅  | string | A UUID string identifying this Chatbot 資料庫配置. |

#### 請求內容

**請求參數**

| 欄位            | 類型      | 必填 | 說明                                                                                                                                                     |
| ------------- | ------- | -- | ------------------------------------------------------------------------------------------------------------------------------------------------------ |
| name          | string  | 是  | 顯示用的名稱，例如：主要業務DB、分析DB                                                                                                                                  |
| databaseType  | object  | 是  | 資料庫類型選項，有 MySQL、PostgreSQL、MSSQL、Oracle、MaiAgent `postgresql`: PostgreSQL ; `mysql`: MySQL ; `maiagent`: MaiAgent ; `oracle`: Oracle ; `mssql`: MSSQL; |
| databaseUrl   | string  | 是  | 資料庫連線字串                                                                                                                                                |
| includeTables | object  | 否  | 指定要查詢的資料表列表，格式: {"tables": \["table1", "table2"]}。MaiAgent 類型會自動從上傳的檔案中取得，不需要手動設定                                                                      |
| isActive      | boolean | 否  | 停用後將不會在 Text-to-SQL 查詢中使用此資料庫                                                                                                                          |

**請求結構範例**

```typescript
{
  "name": string // 顯示用的名稱，例如：主要業務DB、分析DB
  "databaseType":  // 資料庫類型選項，有 MySQL、PostgreSQL、MSSQL、Oracle、MaiAgent

* `postgresql` - PostgreSQL
* `mysql` - MySQL
* `maiagent` - MaiAgent
* `oracle` - Oracle
* `mssql` - MSSQL
  {
  }
  "databaseUrl": string // 資料庫連線字串
  "includeTables"?: object // 指定要查詢的資料表列表，格式: {"tables": ["table1", "table2"]}。MaiAgent 類型會自動從上傳的檔案中取得，不需要手動設定 (非必填)
  "isActive"?: boolean // 停用後將不會在 Text-to-SQL 查詢中使用此資料庫 (非必填)
}
```

**請求範例值**

```json
{
  "name": "範例名稱",
  "databaseType": {},
  "databaseUrl": "範例字串",
  "includeTables": null,
  "isActive": true
}
```

#### 程式碼範例

{% tabs %}
{% tab title="Shell/Bash" %}

```bash
# 呼叫 API 示例 (Shell)
curl -X PUT "https://api.maiagent.ai/api/v1/chatbots/550e8400-e29b-41d4-a716-446655440000/databases/550e8400-e29b-41d4-a716-446655440000/" \
  -H "Authorization: Api-Key YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "範例名稱",
    "databaseType": {},
    "databaseUrl": "範例字串",
    "includeTables": null,
    "isActive": true
  }'

# 請確認在執行前替換 YOUR_API_KEY 並核對請求資料。
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
const axios = require('axios');

// 設定請求標頭
const config = {
  headers: {
    'Authorization': 'Api-Key YOUR_API_KEY',
    'Content-Type': 'application/json'
  }
};

// 請求內容 (payload)
const data = {
    "name": "範例名稱",
    "databaseType": {},
    "databaseUrl": "範例字串",
    "includeTables": null,
    "isActive": true
  };

axios.put("https://api.maiagent.ai/api/v1/chatbots/550e8400-e29b-41d4-a716-446655440000/databases/550e8400-e29b-41d4-a716-446655440000/", data, config)
  .then(response => {
    console.log('成功取得回應:');
    console.log(response.data);
  })
  .catch(error => {
    console.error('請求發生錯誤:');
    console.error(error.response?.data || error.message);
  });
```

{% endtab %}

{% tab title="Python" %}

```python
import requests

url = "https://api.maiagent.ai/api/v1/chatbots/550e8400-e29b-41d4-a716-446655440000/databases/550e8400-e29b-41d4-a716-446655440000/"
headers = {
    "Authorization": "Api-Key YOUR_API_KEY",
    "Content-Type": "application/json"
}

# 請求內容 (payload)
data = {
      "name": "範例名稱",
      "databaseType": {},
      "databaseUrl": "範例字串",
      "includeTables": null,
      "isActive": true
    }

response = requests.put(url, json=data, headers=headers)
try:
    print("成功取得回應:")
    print(response.json())
except Exception as e:
    print("請求發生錯誤:", e)
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php
require 'vendor/autoload.php';

$client = new GuzzleHttp\Client();

try {
    $response = $client->put("https://api.maiagent.ai/api/v1/chatbots/550e8400-e29b-41d4-a716-446655440000/databases/550e8400-e29b-41d4-a716-446655440000/", [
        'headers' => [
            'Authorization' => 'Api-Key YOUR_API_KEY',
            'Content-Type' => 'application/json'
        ],
        'json' => {
            "name": "範例名稱",
            "databaseType": {},
            "databaseUrl": "範例字串",
            "includeTables": null,
            "isActive": true
        }
    ]);
    
    $data = json_decode($response->getBody(), true);
    echo "成功取得回應:\n";
    print_r($data);
} catch (Exception $e) {
    echo '請求發生錯誤: ' . $e->getMessage();
}
?>
```

{% endtab %}
{% endtabs %}

#### 回應內容

**狀態碼: 200**

**回應結構範例**

```typescript
{
  "id": string (uuid)
  "name": string // 顯示用的名稱，例如：主要業務DB、分析DB
  "databaseType":  // 資料庫類型選項，有 MySQL、PostgreSQL、MSSQL、Oracle、MaiAgent

* `postgresql` - PostgreSQL
* `mysql` - MySQL
* `maiagent` - MaiAgent
* `oracle` - Oracle
* `mssql` - MSSQL
  {
  }
  "databaseUrl": string // 資料庫連線字串
  "includeTables"?: object // 指定要查詢的資料表列表，格式: {"tables": ["table1", "table2"]}。MaiAgent 類型會自動從上傳的檔案中取得，不需要手動設定 (非必填)
  "isActive"?: boolean // 停用後將不會在 Text-to-SQL 查詢中使用此資料庫 (非必填)
  "createdAt": string (timestamp)
  "updatedAt": string (timestamp)
}
```

**回應範例值**

```json
{
  "id": "550e8400-e29b-41d4-a716-446655440000",
  "name": "回應字串",
  "databaseType": {},
  "databaseUrl": "回應字串",
  "includeTables": null,
  "isActive": false,
  "createdAt": "回應字串",
  "updatedAt": "回應字串"
}
```

***

### 部分更新資料庫配置 <a href="#undefined" id="undefined"></a>

PATCH `/api/chatbots/{chatbotPk}/databases/{id}/`

#### 參數

| 參數名稱        | 必填 | 類型     | 說明                                            |
| ----------- | -- | ------ | --------------------------------------------- |
| `chatbotPk` | ✅  | string | A UUID string identifying this Chatbot ID     |
| `id`        | ✅  | string | A UUID string identifying this Chatbot 資料庫配置. |

#### 請求內容

**請求參數**

| 欄位            | 類型      | 必填 | 說明                                                                                                                                                     |
| ------------- | ------- | -- | ------------------------------------------------------------------------------------------------------------------------------------------------------ |
| name          | string  | 否  | 顯示用的名稱，例如：主要業務DB、分析DB                                                                                                                                  |
| databaseType  | object  | 否  | 資料庫類型選項，有 MySQL、PostgreSQL、MSSQL、Oracle、MaiAgent `postgresql`: PostgreSQL ; `mysql`: MySQL ; `maiagent`: MaiAgent ; `oracle`: Oracle ; `mssql`: MSSQL; |
| databaseUrl   | string  | 否  | 資料庫連線字串                                                                                                                                                |
| includeTables | object  | 否  | 指定要查詢的資料表列表，格式: {"tables": \["table1", "table2"]}。MaiAgent 類型會自動從上傳的檔案中取得，不需要手動設定                                                                      |
| isActive      | boolean | 否  | 停用後將不會在 Text-to-SQL 查詢中使用此資料庫                                                                                                                          |

**請求結構範例**

```typescript
{
  "name"?: string // 顯示用的名稱，例如：主要業務DB、分析DB (非必填)
  "databaseType"?:  // 資料庫類型選項，有 MySQL、PostgreSQL、MSSQL、Oracle、MaiAgent

* `postgresql` - PostgreSQL
* `mysql` - MySQL
* `maiagent` - MaiAgent
* `oracle` - Oracle
* `mssql` - MSSQL (非必填)
  {
  }
  "databaseUrl"?: string // 資料庫連線字串 (非必填)
  "includeTables"?: object // 指定要查詢的資料表列表，格式: {"tables": ["table1", "table2"]}。MaiAgent 類型會自動從上傳的檔案中取得，不需要手動設定 (非必填)
  "isActive"?: boolean // 停用後將不會在 Text-to-SQL 查詢中使用此資料庫 (非必填)
}
```

**請求範例值**

```json
{
  "name": "範例名稱",
  "databaseType": {},
  "databaseUrl": "範例字串",
  "includeTables": null,
  "isActive": true
}
```

#### 程式碼範例

{% tabs %}
{% tab title="Shell/Bash" %}

```bash
# 呼叫 API 示例 (Shell)
curl -X PATCH "https://api.maiagent.ai/api/chatbots/550e8400-e29b-41d4-a716-446655440000/databases/550e8400-e29b-41d4-a716-446655440000/" \
  -H "Authorization: Api-Key YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "範例名稱",
    "databaseType": {},
    "databaseUrl": "範例字串",
    "includeTables": null,
    "isActive": true
  }'

# 請確認在執行前替換 YOUR_API_KEY 並核對請求資料。
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
const axios = require('axios');

// 設定請求標頭
const config = {
  headers: {
    'Authorization': 'Api-Key YOUR_API_KEY',
    'Content-Type': 'application/json'
  }
};

// 請求內容 (payload)
const data = {
    "name": "範例名稱",
    "databaseType": {},
    "databaseUrl": "範例字串",
    "includeTables": null,
    "isActive": true
  };

axios.patch("https://api.maiagent.ai/api/chatbots/550e8400-e29b-41d4-a716-446655440000/databases/550e8400-e29b-41d4-a716-446655440000/", data, config)
  .then(response => {
    console.log('成功取得回應:');
    console.log(response.data);
  })
  .catch(error => {
    console.error('請求發生錯誤:');
    console.error(error.response?.data || error.message);
  });
```

{% endtab %}

{% tab title="Python" %}

```python
import requests

url = "https://api.maiagent.ai/api/chatbots/550e8400-e29b-41d4-a716-446655440000/databases/550e8400-e29b-41d4-a716-446655440000/"
headers = {
    "Authorization": "Api-Key YOUR_API_KEY",
    "Content-Type": "application/json"
}

# 請求內容 (payload)
data = {
      "name": "範例名稱",
      "databaseType": {},
      "databaseUrl": "範例字串",
      "includeTables": null,
      "isActive": true
    }

response = requests.patch(url, json=data, headers=headers)
try:
    print("成功取得回應:")
    print(response.json())
except Exception as e:
    print("請求發生錯誤:", e)
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php
require 'vendor/autoload.php';

$client = new GuzzleHttp\Client();

try {
    $response = $client->patch("https://api.maiagent.ai/api/chatbots/550e8400-e29b-41d4-a716-446655440000/databases/550e8400-e29b-41d4-a716-446655440000/", [
        'headers' => [
            'Authorization' => 'Api-Key YOUR_API_KEY',
            'Content-Type' => 'application/json'
        ],
        'json' => {
            "name": "範例名稱",
            "databaseType": {},
            "databaseUrl": "範例字串",
            "includeTables": null,
            "isActive": true
        }
    ]);
    
    $data = json_decode($response->getBody(), true);
    echo "成功取得回應:\n";
    print_r($data);
} catch (Exception $e) {
    echo '請求發生錯誤: ' . $e->getMessage();
}
?>
```

{% endtab %}
{% endtabs %}

#### 回應內容

**狀態碼: 200**

**回應結構範例**

```typescript
{
  "id": string (uuid)
  "name": string // 顯示用的名稱，例如：主要業務DB、分析DB
  "databaseType":  // 資料庫類型選項，有 MySQL、PostgreSQL、MSSQL、Oracle、MaiAgent

* `postgresql` - PostgreSQL
* `mysql` - MySQL
* `maiagent` - MaiAgent
* `oracle` - Oracle
* `mssql` - MSSQL
  {
  }
  "databaseUrl": string // 資料庫連線字串
  "includeTables"?: object // 指定要查詢的資料表列表，格式: {"tables": ["table1", "table2"]}。MaiAgent 類型會自動從上傳的檔案中取得，不需要手動設定 (非必填)
  "isActive"?: boolean // 停用後將不會在 Text-to-SQL 查詢中使用此資料庫 (非必填)
  "createdAt": string (timestamp)
  "updatedAt": string (timestamp)
}
```

**回應範例值**

```json
{
  "id": "550e8400-e29b-41d4-a716-446655440000",
  "name": "回應字串",
  "databaseType": {},
  "databaseUrl": "回應字串",
  "includeTables": null,
  "isActive": false,
  "createdAt": "回應字串",
  "updatedAt": "回應字串"
}
```

***

### 部分更新資料庫配置 <a href="#undefined" id="undefined"></a>

PATCH `/api/v1/chatbots/{chatbotPk}/databases/{id}/`

#### 參數

| 參數名稱        | 必填 | 類型     | 說明                                            |
| ----------- | -- | ------ | --------------------------------------------- |
| `chatbotPk` | ✅  | string | A UUID string identifying this Chatbot ID     |
| `id`        | ✅  | string | A UUID string identifying this Chatbot 資料庫配置. |

#### 請求內容

**請求參數**

| 欄位            | 類型      | 必填 | 說明                                                                                                                                                     |
| ------------- | ------- | -- | ------------------------------------------------------------------------------------------------------------------------------------------------------ |
| name          | string  | 否  | 顯示用的名稱，例如：主要業務DB、分析DB                                                                                                                                  |
| databaseType  | object  | 否  | 資料庫類型選項，有 MySQL、PostgreSQL、MSSQL、Oracle、MaiAgent `postgresql`: PostgreSQL ; `mysql`: MySQL ; `maiagent`: MaiAgent ; `oracle`: Oracle ; `mssql`: MSSQL; |
| databaseUrl   | string  | 否  | 資料庫連線字串                                                                                                                                                |
| includeTables | object  | 否  | 指定要查詢的資料表列表，格式: {"tables": \["table1", "table2"]}。MaiAgent 類型會自動從上傳的檔案中取得，不需要手動設定                                                                      |
| isActive      | boolean | 否  | 停用後將不會在 Text-to-SQL 查詢中使用此資料庫                                                                                                                          |

**請求結構範例**

```typescript
{
  "name"?: string // 顯示用的名稱，例如：主要業務DB、分析DB (非必填)
  "databaseType"?:  // 資料庫類型選項，有 MySQL、PostgreSQL、MSSQL、Oracle、MaiAgent

* `postgresql` - PostgreSQL
* `mysql` - MySQL
* `maiagent` - MaiAgent
* `oracle` - Oracle
* `mssql` - MSSQL (非必填)
  {
  }
  "databaseUrl"?: string // 資料庫連線字串 (非必填)
  "includeTables"?: object // 指定要查詢的資料表列表，格式: {"tables": ["table1", "table2"]}。MaiAgent 類型會自動從上傳的檔案中取得，不需要手動設定 (非必填)
  "isActive"?: boolean // 停用後將不會在 Text-to-SQL 查詢中使用此資料庫 (非必填)
}
```

**請求範例值**

```json
{
  "name": "範例名稱",
  "databaseType": {},
  "databaseUrl": "範例字串",
  "includeTables": null,
  "isActive": true
}
```

#### 程式碼範例

{% tabs %}
{% tab title="Shell/Bash" %}

```bash
# 呼叫 API 示例 (Shell)
curl -X PATCH "https://api.maiagent.ai/api/v1/chatbots/550e8400-e29b-41d4-a716-446655440000/databases/550e8400-e29b-41d4-a716-446655440000/" \
  -H "Authorization: Api-Key YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "範例名稱",
    "databaseType": {},
    "databaseUrl": "範例字串",
    "includeTables": null,
    "isActive": true
  }'

# 請確認在執行前替換 YOUR_API_KEY 並核對請求資料。
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
const axios = require('axios');

// 設定請求標頭
const config = {
  headers: {
    'Authorization': 'Api-Key YOUR_API_KEY',
    'Content-Type': 'application/json'
  }
};

// 請求內容 (payload)
const data = {
    "name": "範例名稱",
    "databaseType": {},
    "databaseUrl": "範例字串",
    "includeTables": null,
    "isActive": true
  };

axios.patch("https://api.maiagent.ai/api/v1/chatbots/550e8400-e29b-41d4-a716-446655440000/databases/550e8400-e29b-41d4-a716-446655440000/", data, config)
  .then(response => {
    console.log('成功取得回應:');
    console.log(response.data);
  })
  .catch(error => {
    console.error('請求發生錯誤:');
    console.error(error.response?.data || error.message);
  });
```

{% endtab %}

{% tab title="Python" %}

```python
import requests

url = "https://api.maiagent.ai/api/v1/chatbots/550e8400-e29b-41d4-a716-446655440000/databases/550e8400-e29b-41d4-a716-446655440000/"
headers = {
    "Authorization": "Api-Key YOUR_API_KEY",
    "Content-Type": "application/json"
}

# 請求內容 (payload)
data = {
      "name": "範例名稱",
      "databaseType": {},
      "databaseUrl": "範例字串",
      "includeTables": null,
      "isActive": true
    }

response = requests.patch(url, json=data, headers=headers)
try:
    print("成功取得回應:")
    print(response.json())
except Exception as e:
    print("請求發生錯誤:", e)
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php
require 'vendor/autoload.php';

$client = new GuzzleHttp\Client();

try {
    $response = $client->patch("https://api.maiagent.ai/api/v1/chatbots/550e8400-e29b-41d4-a716-446655440000/databases/550e8400-e29b-41d4-a716-446655440000/", [
        'headers' => [
            'Authorization' => 'Api-Key YOUR_API_KEY',
            'Content-Type' => 'application/json'
        ],
        'json' => {
            "name": "範例名稱",
            "databaseType": {},
            "databaseUrl": "範例字串",
            "includeTables": null,
            "isActive": true
        }
    ]);
    
    $data = json_decode($response->getBody(), true);
    echo "成功取得回應:\n";
    print_r($data);
} catch (Exception $e) {
    echo '請求發生錯誤: ' . $e->getMessage();
}
?>
```

{% endtab %}
{% endtabs %}

#### 回應內容

**狀態碼: 200**

**回應結構範例**

```typescript
{
  "id": string (uuid)
  "name": string // 顯示用的名稱，例如：主要業務DB、分析DB
  "databaseType":  // 資料庫類型選項，有 MySQL、PostgreSQL、MSSQL、Oracle、MaiAgent

* `postgresql` - PostgreSQL
* `mysql` - MySQL
* `maiagent` - MaiAgent
* `oracle` - Oracle
* `mssql` - MSSQL
  {
  }
  "databaseUrl": string // 資料庫連線字串
  "includeTables"?: object // 指定要查詢的資料表列表，格式: {"tables": ["table1", "table2"]}。MaiAgent 類型會自動從上傳的檔案中取得，不需要手動設定 (非必填)
  "isActive"?: boolean // 停用後將不會在 Text-to-SQL 查詢中使用此資料庫 (非必填)
  "createdAt": string (timestamp)
  "updatedAt": string (timestamp)
}
```

**回應範例值**

```json
{
  "id": "550e8400-e29b-41d4-a716-446655440000",
  "name": "回應字串",
  "databaseType": {},
  "databaseUrl": "回應字串",
  "includeTables": null,
  "isActive": false,
  "createdAt": "回應字串",
  "updatedAt": "回應字串"
}
```

***

### 刪除資料庫配置 <a href="#undefined" id="undefined"></a>

DELETE `/api/chatbots/{chatbotPk}/databases/{id}/`

#### 參數

| 參數名稱        | 必填 | 類型     | 說明                                            |
| ----------- | -- | ------ | --------------------------------------------- |
| `chatbotPk` | ✅  | string | A UUID string identifying this Chatbot ID     |
| `id`        | ✅  | string | A UUID string identifying this Chatbot 資料庫配置. |

#### 程式碼範例

{% tabs %}
{% tab title="Shell/Bash" %}

```bash
# 呼叫 API 示例 (Shell)
curl -X DELETE "https://api.maiagent.ai/api/chatbots/550e8400-e29b-41d4-a716-446655440000/databases/550e8400-e29b-41d4-a716-446655440000/" \
  -H "Authorization: Api-Key YOUR_API_KEY"

# 請確認在執行前替換 YOUR_API_KEY 並核對請求資料。
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
const axios = require('axios');

// 設定請求標頭
const config = {
  headers: {
    'Authorization': 'Api-Key YOUR_API_KEY'
  }
};

// 請求內容 (payload)
const data = null;

axios.delete("https://api.maiagent.ai/api/chatbots/550e8400-e29b-41d4-a716-446655440000/databases/550e8400-e29b-41d4-a716-446655440000/", data, config)
  .then(response => {
    console.log('成功取得回應:');
    console.log(response.data);
  })
  .catch(error => {
    console.error('請求發生錯誤:');
    console.error(error.response?.data || error.message);
  });
```

{% endtab %}

{% tab title="Python" %}

```python
import requests

url = "https://api.maiagent.ai/api/chatbots/550e8400-e29b-41d4-a716-446655440000/databases/550e8400-e29b-41d4-a716-446655440000/"
headers = {
    "Authorization": "Api-Key YOUR_API_KEY"
}


response = requests.delete(url, headers=headers)
try:
    print("成功取得回應:")
    print(response.json())
except Exception as e:
    print("請求發生錯誤:", e)
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php
require 'vendor/autoload.php';

$client = new GuzzleHttp\Client();

try {
    $response = $client->delete("https://api.maiagent.ai/api/chatbots/550e8400-e29b-41d4-a716-446655440000/databases/550e8400-e29b-41d4-a716-446655440000/", [
        'headers' => [
            'Authorization' => 'Api-Key YOUR_API_KEY'
        ]
    ]);
    
    $data = json_decode($response->getBody(), true);
    echo "成功取得回應:\n";
    print_r($data);
} catch (Exception $e) {
    echo '請求發生錯誤: ' . $e->getMessage();
}
?>
```

{% endtab %}
{% endtabs %}

#### 回應內容

| 狀態碼 | 說明               |
| --- | ---------------- |
| 204 | No response body |

***

### 刪除資料庫配置 <a href="#undefined" id="undefined"></a>

DELETE `/api/v1/chatbots/{chatbotPk}/databases/{id}/`

#### 參數

| 參數名稱        | 必填 | 類型     | 說明                                            |
| ----------- | -- | ------ | --------------------------------------------- |
| `chatbotPk` | ✅  | string | A UUID string identifying this Chatbot ID     |
| `id`        | ✅  | string | A UUID string identifying this Chatbot 資料庫配置. |

#### 程式碼範例

{% tabs %}
{% tab title="Shell/Bash" %}

```bash
# 呼叫 API 示例 (Shell)
curl -X DELETE "https://api.maiagent.ai/api/v1/chatbots/550e8400-e29b-41d4-a716-446655440000/databases/550e8400-e29b-41d4-a716-446655440000/" \
  -H "Authorization: Api-Key YOUR_API_KEY"

# 請確認在執行前替換 YOUR_API_KEY 並核對請求資料。
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
const axios = require('axios');

// 設定請求標頭
const config = {
  headers: {
    'Authorization': 'Api-Key YOUR_API_KEY'
  }
};

// 請求內容 (payload)
const data = null;

axios.delete("https://api.maiagent.ai/api/v1/chatbots/550e8400-e29b-41d4-a716-446655440000/databases/550e8400-e29b-41d4-a716-446655440000/", data, config)
  .then(response => {
    console.log('成功取得回應:');
    console.log(response.data);
  })
  .catch(error => {
    console.error('請求發生錯誤:');
    console.error(error.response?.data || error.message);
  });
```

{% endtab %}

{% tab title="Python" %}

```python
import requests

url = "https://api.maiagent.ai/api/v1/chatbots/550e8400-e29b-41d4-a716-446655440000/databases/550e8400-e29b-41d4-a716-446655440000/"
headers = {
    "Authorization": "Api-Key YOUR_API_KEY"
}


response = requests.delete(url, headers=headers)
try:
    print("成功取得回應:")
    print(response.json())
except Exception as e:
    print("請求發生錯誤:", e)
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php
require 'vendor/autoload.php';

$client = new GuzzleHttp\Client();

try {
    $response = $client->delete("https://api.maiagent.ai/api/v1/chatbots/550e8400-e29b-41d4-a716-446655440000/databases/550e8400-e29b-41d4-a716-446655440000/", [
        'headers' => [
            'Authorization' => 'Api-Key YOUR_API_KEY'
        ]
    ]);
    
    $data = json_decode($response->getBody(), true);
    echo "成功取得回應:\n";
    print_r($data);
} catch (Exception $e) {
    echo '請求發生錯誤: ' . $e->getMessage();
}
?>
```

{% endtab %}
{% endtabs %}

#### 回應內容

| 狀態碼 | 說明               |
| --- | ---------------- |
| 204 | No response body |

***
