> For the complete documentation index, see [llms.txt](https://docs.maiagent.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.maiagent.ai/api/ja/api-reference/zi-liao-ku.md).

# データベース

### SQL データベース接続を作成 <a href="#sql-databases-create" id="sql-databases-create"></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, SynxDB, or MaiAgent `postgresql`: PostgreSQL ; `mysql`: MySQL ; `maiagent`: MaiAgent ; `oracle`: Oracle ; `mssql`: MSSQL ; `synxdb`: SynxDB; |
| 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, SynxDB, or MaiAgent

* `postgresql` - PostgreSQL
* `mysql` - MySQL
* `maiagent` - MaiAgent
* `oracle` - Oracle
* `mssql` - MSSQL
* `synxdb` - SynxDB
  {
  }
  "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": None,
    "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' => new \stdClass(),
            '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, SynxDB, or MaiAgent

* `postgresql` - PostgreSQL
* `mysql` - MySQL
* `maiagent` - MaiAgent
* `oracle` - Oracle
* `mssql` - MSSQL
* `synxdb` - SynxDB
  {
  }
  "databaseUrlMasked": string
  "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
      "sheetName": string // Name of the source worksheet/sheet this table was created from. Empty for tables created before this field was added.
      "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
    }
  ]
  "createdBy": 
  {
    "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": {},
  "databaseUrlMasked": "レスポンス文字列",
  "includeTables": null,
  "isActive": false,
  "status": {},
  "deletedAt": "レスポンス文字列",
  "tables": [
    {
      "id": "550e8400-e29b-41d4-a716-446655440000",
      "tableName": "レスポンス文字列",
      "sheetName": "レスポンス文字列",
      "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": "レスポンス文字列"
    }
  ],
  "createdBy": {
    "id": "550e8400-e29b-41d4-a716-446655440000",
    "name": "レスポンス文字列"
  },
  "canUpdate": false,
  "canDelete": false,
  "createdAt": "レスポンス文字列",
  "updatedAt": "レスポンス文字列"
}
```

***

### SQL データベース一覧を取得 <a href="#sql-databases-list" id="sql-databases-list"></a>

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

#### パラメータ

| パラメータ名         | 必須 | 型       | 説明                                                                                                                                                                                                           |
| -------------- | -- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `databaseType` | ❌  | string  | Type of database: PostgreSQL, MySQL, MSSQL, Oracle, SynxDB, or MaiAgent \`postgresql\`: PostgreSQL ; \`mysql\`: MySQL ; \`maiagent\`: MaiAgent ; \`oracle\`: Oracle ; \`mssql\`: MSSQL ; \`synxdb\`: SynxDB; |
| `isActive`     | ❌  | boolean |                                                                                                                                                                                                              |
| `isExternal`   | ❌  | boolean |                                                                                                                                                                                                              |
| `page`         | ❌  | integer | A page number within the paginated result set.                                                                                                                                                               |
| `pageSize`     | ❌  | integer | Number of results to return per page.                                                                                                                                                                        |
| `pagination`   | ❌  | boolean | Set to false to return all databases without pagination (defaults to true).                                                                                                                                  |
| `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&pagination=true&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&pagination=true&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&pagination=true&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&pagination=true&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, SynxDB, or MaiAgent

* `postgresql` - PostgreSQL
* `mysql` - MySQL
* `maiagent` - MaiAgent
* `oracle` - Oracle
* `mssql` - MSSQL
* `synxdb` - SynxDB
      {
      }
      "databaseUrlMasked": string
      "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
        }
      ]
      "tablesCount": integer
      "chatbots": [
        {
          "id": string (uuid)
          "name": string
        }
      ]
      "groups": [
        {
          "id": string (uuid)
          "name": string
        }
      ]
      "createdBy": 
      {
        "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": {},
      "databaseUrlMasked": "レスポンス文字列",
      "includeTables": null,
      "isActive": false,
      "status": {},
      "deletedAt": "レスポンス文字列",
      "tables": [
        {
          "id": "550e8400-e29b-41d4-a716-446655440000",
          "tableName": "レスポンス文字列"
        }
      ],
      "tablesCount": 456,
      "chatbots": [
        {
          "id": "550e8400-e29b-41d4-a716-446655440000",
          "name": "レスポンス文字列"
        }
      ],
      "groups": [
        {
          "id": "550e8400-e29b-41d4-a716-446655440000",
          "name": "レスポンス文字列"
        }
      ],
      "createdBy": {
        "id": "550e8400-e29b-41d4-a716-446655440000",
        "name": "レスポンス文字列"
      },
      "canUpdate": false,
      "canDelete": false,
      "createdAt": "レスポンス文字列",
      "updatedAt": "レスポンス文字列"
    }
  ]
}
```

***

### 特定の SQL データベースを取得 <a href="#sql-databases-retrieve" id="sql-databases-retrieve"></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, SynxDB, or MaiAgent

* `postgresql` - PostgreSQL
* `mysql` - MySQL
* `maiagent` - MaiAgent
* `oracle` - Oracle
* `mssql` - MSSQL
* `synxdb` - SynxDB
  {
  }
  "databaseUrlMasked": string
  "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
      "sheetName": string // Name of the source worksheet/sheet this table was created from. Empty for tables created before this field was added.
      "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
    }
  ]
  "createdBy": 
  {
    "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": {},
  "databaseUrlMasked": "レスポンス文字列",
  "includeTables": null,
  "isActive": false,
  "status": {},
  "deletedAt": "レスポンス文字列",
  "tables": [
    {
      "id": "550e8400-e29b-41d4-a716-446655440000",
      "tableName": "レスポンス文字列",
      "sheetName": "レスポンス文字列",
      "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": "レスポンス文字列"
    }
  ],
  "createdBy": {
    "id": "550e8400-e29b-41d4-a716-446655440000",
    "name": "レスポンス文字列"
  },
  "canUpdate": false,
  "canDelete": false,
  "createdAt": "レスポンス文字列",
  "updatedAt": "レスポンス文字列"
}
```

***

### SQL データベースの更新 <a href="#sql-databases-update" id="sql-databases-update"></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": None,
    "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, SynxDB, or MaiAgent

* `postgresql` - PostgreSQL
* `mysql` - MySQL
* `maiagent` - MaiAgent
* `oracle` - Oracle
* `mssql` - MSSQL
* `synxdb` - SynxDB
  {
  }
  "databaseUrlMasked": string
  "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
      "sheetName": string // Name of the source worksheet/sheet this table was created from. Empty for tables created before this field was added.
      "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
    }
  ]
  "createdBy": 
  {
    "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": {},
  "databaseUrlMasked": "レスポンス文字列",
  "includeTables": null,
  "isActive": false,
  "status": {},
  "deletedAt": "レスポンス文字列",
  "tables": [
    {
      "id": "550e8400-e29b-41d4-a716-446655440000",
      "tableName": "レスポンス文字列",
      "sheetName": "レスポンス文字列",
      "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": "レスポンス文字列"
    }
  ],
  "createdBy": {
    "id": "550e8400-e29b-41d4-a716-446655440000",
    "name": "レスポンス文字列"
  },
  "canUpdate": false,
  "canDelete": false,
  "createdAt": "レスポンス文字列",
  "updatedAt": "レスポンス文字列"
}
```

***

### SQL データベースの部分更新 <a href="#sql-databases-partial-update" id="sql-databases-partial-update"></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": None,
    "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, SynxDB, or MaiAgent

* `postgresql` - PostgreSQL
* `mysql` - MySQL
* `maiagent` - MaiAgent
* `oracle` - Oracle
* `mssql` - MSSQL
* `synxdb` - SynxDB
  {
  }
  "databaseUrlMasked": string
  "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
      "sheetName": string // Name of the source worksheet/sheet this table was created from. Empty for tables created before this field was added.
      "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
    }
  ]
  "createdBy": 
  {
    "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": {},
  "databaseUrlMasked": "レスポンス文字列",
  "includeTables": null,
  "isActive": false,
  "status": {},
  "deletedAt": "レスポンス文字列",
  "tables": [
    {
      "id": "550e8400-e29b-41d4-a716-446655440000",
      "tableName": "レスポンス文字列",
      "sheetName": "レスポンス文字列",
      "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": "レスポンス文字列"
    }
  ],
  "createdBy": {
    "id": "550e8400-e29b-41d4-a716-446655440000",
    "name": "レスポンス文字列"
  },
  "canUpdate": false,
  "canDelete": false,
  "createdAt": "レスポンス文字列",
  "updatedAt": "レスポンス文字列"
}
```

***

### SQL データベースの削除 <a href="#sql-databases-destroy" id="sql-databases-destroy"></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="#sql-databases-test-connection-create" id="sql-databases-test-connection-create"></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, synxdb) | はい | `postgresql`: PostgreSQL ; `mysql`: MySQL ; `maiagent`: MaiAgent ; `oracle`: Oracle ; `mssql`: MSSQL ; `synxdb`: SynxDB; |
| databaseUrl  | string                                                            | はい |                                                                                                                          |

**リクエストスキーマの例**

```typescript
{
  "databaseType": string (enum: postgresql, mysql, maiagent, oracle, mssql, synxdb) // * `postgresql` - PostgreSQL
* `mysql` - MySQL
* `maiagent` - MaiAgent
* `oracle` - Oracle
* `mssql` - MSSQL
* `synxdb` - SynxDB
  "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="#sql-databases-upload-files-create" id="sql-databases-upload-files-create"></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-databases-batch-delete-create" id="sql-databases-batch-delete-create"></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="#sql-databases-tables-list" id="sql-databases-tables-list"></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
      "sheetName": string // Name of the source worksheet/sheet this table was created from. Empty for tables created before this field was added.
      "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": "レスポンス文字列",
      "sheetName": "レスポンス文字列",
      "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="#sql-databases-tables-create" id="sql-databases-tables-create"></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
  "sheetName": string // Name of the source worksheet/sheet this table was created from. Empty for tables created before this field was added.
  "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": "レスポンス文字列",
  "sheetName": "レスポンス文字列",
  "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="#sql-databases-tables-retrieve" id="sql-databases-tables-retrieve"></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
  "sheetName": string // Name of the source worksheet/sheet this table was created from. Empty for tables created before this field was added.
  "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": "レスポンス文字列",
  "sheetName": "レスポンス文字列",
  "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="#sql-databases-tables-update" id="sql-databases-tables-update"></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
  "sheetName": string // Name of the source worksheet/sheet this table was created from. Empty for tables created before this field was added.
  "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": "レスポンス文字列",
  "sheetName": "レスポンス文字列",
  "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="#sql-databases-tables-partial-update" id="sql-databases-tables-partial-update"></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
  "sheetName": string // Name of the source worksheet/sheet this table was created from. Empty for tables created before this field was added.
  "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": "レスポンス文字列",
  "sheetName": "レスポンス文字列",
  "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="#sql-databases-tables-destroy" id="sql-databases-tables-destroy"></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="#sql-databases-tables-batch-delete-create" id="sql-databases-tables-batch-delete-create"></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="#sql-databases-tables-columns-list" id="sql-databases-tables-columns-list"></a>

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

#### パラメータ

| パラメータ名          | 必須 | 型      | 説明 |
| --------------- | -- | ------ | -- |
| `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/" \
  -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/", 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/"
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/", [
        '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="#sql-databases-tables-columns-retrieve" id="sql-databases-tables-columns-retrieve"></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="#sql-databases-tables-columns-update" id="sql-databases-tables-columns-update"></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="#sql-databases-tables-columns-partial-update" id="sql-databases-tables-columns-partial-update"></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="#database-connection-test-create" id="database-connection-test-create"></a>

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

#### リクエストボディ

**リクエストパラメータ**

| フィールド        | 型      | 必須 | 説明                                                                                                                                     |
| ------------ | ------ | -- | -------------------------------------------------------------------------------------------------------------------------------------- |
| databaseType | object | はい | データベースの種類（MaiAgent が内部で使用する種類は含みません） `postgresql`: PostgreSQL ; `mysql`: MySQL ; `oracle`: Oracle ; `mssql`: MSSQL ; `synxdb`: SynxDB; |
| databaseUrl  | string | はい | データベース接続文字列                                                                                                                            |

**リクエストスキーマの例**

```typescript
{
  "databaseType":  // データベースの種類（MaiAgent が内部で使用する種類は含みません）

* `postgresql` - PostgreSQL
* `mysql` - MySQL
* `oracle` - Oracle
* `mssql` - MSSQL
* `synxdb` - SynxDB
  {
  }
  "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="#database-examples-list" id="database-examples-list"></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"?:  // Database type option

* `postgresql` - PostgreSQL
* `mysql` - MySQL
* `maiagent` - MaiAgent
* `oracle` - Oracle
* `mssql` - MSSQL
* `synxdb` - SynxDB (任意)
    {
    }
    "databaseTypeExample": string // For example: postgresql://db_user:db_password@db_ip:db_port/db_name
  }
]
```

**レスポンス値の例**

```json
[
  {
    "databaseType": {},
    "databaseTypeExample": "レスポンス文字列"
  }
]
```

**ステータスコード: 401**

**レスポンススキーマの例**

```typescript
{
  "detail"?: string // 任意
}
```

**レスポンス値の例**

```json
{
  "detail": "レスポンス文字列"
}
```

***

### 特定の接続文字列の例を取得 <a href="#database-examples-retrieve" id="database-examples-retrieve"></a>

GET `/api/v1/database-examples/{id}/`

#### パラメータ

| パラメータ名 | 必須 | 型      | 説明                                                          |
| ------ | -- | ------ | ----------------------------------------------------------- |
| `id`   | ✅  | string | A UUID string identifying this Database Connection Example. |

#### コード例

{% 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"?:  // Database type option

* `postgresql` - PostgreSQL
* `mysql` - MySQL
* `maiagent` - MaiAgent
* `oracle` - Oracle
* `mssql` - MSSQL
* `synxdb` - SynxDB (任意)
  {
  }
  "databaseTypeExample": string // For example: postgresql://db_user:db_password@db_ip:db_port/db_name
}
```

**レスポンス値の例**

```json
{
  "databaseType": {},
  "databaseTypeExample": "レスポンス文字列"
}
```

***

### AI アシスタントのデータベース設定を一覧表示 <a href="#chatbots-databases-list" id="chatbots-databases-list"></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 // Display name, for example: Main Business DB, Analytics DB.
      "databaseType":  // Database type: MySQL, PostgreSQL, MSSQL, Oracle, SynxDB, or MaiAgent.

* `postgresql` - PostgreSQL
* `mysql` - MySQL
* `maiagent` - MaiAgent
* `oracle` - Oracle
* `mssql` - MSSQL
* `synxdb` - SynxDB
      {
      }
      "databaseUrl": string // Database connection string.
      "databaseUrlMasked": string
      "includeTables"?: object // Tables to query, formatted as {"tables": ["table1", "table2"]}. The MaiAgent type reads them from uploaded files automatically, so no manual setup is needed. (任意)
      "isActive"?: boolean // When inactive, this database is not used for Text-to-SQL queries. (任意)
      "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": "レスポンス文字列",
      "databaseUrlMasked": "レスポンス文字列",
      "includeTables": null,
      "isActive": false,
      "createdAt": "レスポンス文字列",
      "updatedAt": "レスポンス文字列"
    }
  ]
}
```

***

### AI アシスタントのデータベース設定を追加 <a href="#chatbots-databases-create" id="chatbots-databases-create"></a>

POST `/api/v1/chatbots/{chatbotPk}/databases/`

#### パラメータ

| パラメータ名      | 必須 | 型      | 説明                                        |
| ----------- | -- | ------ | ----------------------------------------- |
| `chatbotPk` | ✅  | string | A UUID string identifying this Chatbot ID |

#### リクエストボディ

**リクエストパラメータ**

| フィールド         | 型       | 必須  | 説明                                                                                                                                                                                             |
| ------------- | ------- | --- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| name          | string  | はい  | Display name, for example: Main Business DB, Analytics DB.                                                                                                                                     |
| databaseType  | object  | はい  | Database type: MySQL, PostgreSQL, MSSQL, Oracle, SynxDB, or MaiAgent. `postgresql`: PostgreSQL ; `mysql`: MySQL ; `maiagent`: MaiAgent ; `oracle`: Oracle ; `mssql`: MSSQL ; `synxdb`: SynxDB; |
| databaseUrl   | string  | はい  | Database connection string.                                                                                                                                                                    |
| includeTables | object  | いいえ | Tables to query, formatted as {"tables": \["table1", "table2"]}. The MaiAgent type reads them from uploaded files automatically, so no manual setup is needed.                                 |
| isActive      | boolean | いいえ | When inactive, this database is not used for Text-to-SQL queries.                                                                                                                              |

**リクエストスキーマの例**

```typescript
{
  "name": string // Display name, for example: Main Business DB, Analytics DB.
  "databaseType":  // Database type: MySQL, PostgreSQL, MSSQL, Oracle, SynxDB, or MaiAgent.

* `postgresql` - PostgreSQL
* `mysql` - MySQL
* `maiagent` - MaiAgent
* `oracle` - Oracle
* `mssql` - MSSQL
* `synxdb` - SynxDB
  {
  }
  "databaseUrl": string // Database connection string.
  "includeTables"?: object // Tables to query, formatted as {"tables": ["table1", "table2"]}. The MaiAgent type reads them from uploaded files automatically, so no manual setup is needed. (任意)
  "isActive"?: boolean // When inactive, this database is not used for Text-to-SQL queries. (任意)
}
```

**リクエスト値の例**

```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": None,
    "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' => new \stdClass(),
            '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 // Display name, for example: Main Business DB, Analytics DB.
  "databaseType":  // Database type: MySQL, PostgreSQL, MSSQL, Oracle, SynxDB, or MaiAgent.

* `postgresql` - PostgreSQL
* `mysql` - MySQL
* `maiagent` - MaiAgent
* `oracle` - Oracle
* `mssql` - MSSQL
* `synxdb` - SynxDB
  {
  }
  "databaseUrl": string // Database connection string.
  "databaseUrlMasked": string
  "includeTables"?: object // Tables to query, formatted as {"tables": ["table1", "table2"]}. The MaiAgent type reads them from uploaded files automatically, so no manual setup is needed. (任意)
  "isActive"?: boolean // When inactive, this database is not used for Text-to-SQL queries. (任意)
  "createdAt": string (timestamp)
  "updatedAt": string (timestamp)
}
```

**レスポンス値の例**

```json
{
  "id": "550e8400-e29b-41d4-a716-446655440000",
  "name": "レスポンス文字列",
  "databaseType": {},
  "databaseUrl": "レスポンス文字列",
  "databaseUrlMasked": "レスポンス文字列",
  "includeTables": null,
  "isActive": false,
  "createdAt": "レスポンス文字列",
  "updatedAt": "レスポンス文字列"
}
```

***

### 特定のデータベース設定を取得 <a href="#chatbots-databases-retrieve" id="chatbots-databases-retrieve"></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 Database Configuration. |

#### コード例

{% 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 // Display name, for example: Main Business DB, Analytics DB.
  "databaseType":  // Database type: MySQL, PostgreSQL, MSSQL, Oracle, SynxDB, or MaiAgent.

* `postgresql` - PostgreSQL
* `mysql` - MySQL
* `maiagent` - MaiAgent
* `oracle` - Oracle
* `mssql` - MSSQL
* `synxdb` - SynxDB
  {
  }
  "databaseUrl": string // Database connection string.
  "databaseUrlMasked": string
  "includeTables"?: object // Tables to query, formatted as {"tables": ["table1", "table2"]}. The MaiAgent type reads them from uploaded files automatically, so no manual setup is needed. (任意)
  "isActive"?: boolean // When inactive, this database is not used for Text-to-SQL queries. (任意)
  "createdAt": string (timestamp)
  "updatedAt": string (timestamp)
}
```

**レスポンス値の例**

```json
{
  "id": "550e8400-e29b-41d4-a716-446655440000",
  "name": "サンプル文字列",
  "databaseType": {},
  "databaseUrl": "サンプル文字列",
  "databaseUrlMasked": "サンプル文字列",
  "includeTables": null,
  "isActive": false,
  "createdAt": "サンプル文字列",
  "updatedAt": "サンプル文字列"
}
```

***

### データベース設定を更新 <a href="#chatbots-databases-update" id="chatbots-databases-update"></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 Database Configuration. |

#### リクエストボディ

**リクエストパラメータ**

| フィールド         | 型       | 必須  | 説明                                                                                                                                                                                             |
| ------------- | ------- | --- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| name          | string  | はい  | Display name, for example: Main Business DB, Analytics DB.                                                                                                                                     |
| databaseType  | object  | はい  | Database type: MySQL, PostgreSQL, MSSQL, Oracle, SynxDB, or MaiAgent. `postgresql`: PostgreSQL ; `mysql`: MySQL ; `maiagent`: MaiAgent ; `oracle`: Oracle ; `mssql`: MSSQL ; `synxdb`: SynxDB; |
| databaseUrl   | string  | はい  | Database connection string.                                                                                                                                                                    |
| includeTables | object  | いいえ | Tables to query, formatted as {"tables": \["table1", "table2"]}. The MaiAgent type reads them from uploaded files automatically, so no manual setup is needed.                                 |
| isActive      | boolean | いいえ | When inactive, this database is not used for Text-to-SQL queries.                                                                                                                              |

**リクエストスキーマの例**

```typescript
{
  "name": string // Display name, for example: Main Business DB, Analytics DB.
  "databaseType":  // Database type: MySQL, PostgreSQL, MSSQL, Oracle, SynxDB, or MaiAgent.

* `postgresql` - PostgreSQL
* `mysql` - MySQL
* `maiagent` - MaiAgent
* `oracle` - Oracle
* `mssql` - MSSQL
* `synxdb` - SynxDB
  {
  }
  "databaseUrl": string // Database connection string.
  "includeTables"?: object // Tables to query, formatted as {"tables": ["table1", "table2"]}. The MaiAgent type reads them from uploaded files automatically, so no manual setup is needed. (任意)
  "isActive"?: boolean // When inactive, this database is not used for Text-to-SQL queries. (任意)
}
```

**リクエスト値の例**

```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": None,
    "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' => new \stdClass(),
            '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 // Display name, for example: Main Business DB, Analytics DB.
  "databaseType":  // Database type: MySQL, PostgreSQL, MSSQL, Oracle, SynxDB, or MaiAgent.

* `postgresql` - PostgreSQL
* `mysql` - MySQL
* `maiagent` - MaiAgent
* `oracle` - Oracle
* `mssql` - MSSQL
* `synxdb` - SynxDB
  {
  }
  "databaseUrl": string // Database connection string.
  "databaseUrlMasked": string
  "includeTables"?: object // Tables to query, formatted as {"tables": ["table1", "table2"]}. The MaiAgent type reads them from uploaded files automatically, so no manual setup is needed. (任意)
  "isActive"?: boolean // When inactive, this database is not used for Text-to-SQL queries. (任意)
  "createdAt": string (timestamp)
  "updatedAt": string (timestamp)
}
```

**レスポンス値の例**

```json
{
  "id": "550e8400-e29b-41d4-a716-446655440000",
  "name": "サンプル文字列",
  "databaseType": {},
  "databaseUrl": "サンプル文字列",
  "databaseUrlMasked": "サンプル文字列",
  "includeTables": null,
  "isActive": false,
  "createdAt": "サンプル文字列",
  "updatedAt": "サンプル文字列"
}
```

***

### データベース設定を部分更新 <a href="#chatbots-databases-partial-update" id="chatbots-databases-partial-update"></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 Database Configuration. |

#### リクエストボディ

**リクエストパラメータ**

| フィールド         | 型       | 必須  | 説明                                                                                                                                                                                             |
| ------------- | ------- | --- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| name          | string  | いいえ | Display name, for example: Main Business DB, Analytics DB.                                                                                                                                     |
| databaseType  | object  | いいえ | Database type: MySQL, PostgreSQL, MSSQL, Oracle, SynxDB, or MaiAgent. `postgresql`: PostgreSQL ; `mysql`: MySQL ; `maiagent`: MaiAgent ; `oracle`: Oracle ; `mssql`: MSSQL ; `synxdb`: SynxDB; |
| databaseUrl   | string  | いいえ | Database connection string.                                                                                                                                                                    |
| includeTables | object  | いいえ | Tables to query, formatted as {"tables": \["table1", "table2"]}. The MaiAgent type reads them from uploaded files automatically, so no manual setup is needed.                                 |
| isActive      | boolean | いいえ | When inactive, this database is not used for Text-to-SQL queries.                                                                                                                              |

**リクエストスキーマの例**

```typescript
{
  "name"?: string // Display name, for example: Main Business DB, Analytics DB. (任意)
  "databaseType"?:  // Database type: MySQL, PostgreSQL, MSSQL, Oracle, SynxDB, or MaiAgent.

* `postgresql` - PostgreSQL
* `mysql` - MySQL
* `maiagent` - MaiAgent
* `oracle` - Oracle
* `mssql` - MSSQL
* `synxdb` - SynxDB (任意)
  {
  }
  "databaseUrl"?: string // Database connection string. (任意)
  "includeTables"?: object // Tables to query, formatted as {"tables": ["table1", "table2"]}. The MaiAgent type reads them from uploaded files automatically, so no manual setup is needed. (任意)
  "isActive"?: boolean // When inactive, this database is not used for Text-to-SQL queries. (任意)
}
```

**リクエスト値の例**

```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": None,
    "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' => new \stdClass(),
            '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 // Display name, for example: Main Business DB, Analytics DB.
  "databaseType":  // Database type: MySQL, PostgreSQL, MSSQL, Oracle, SynxDB, or MaiAgent.

* `postgresql` - PostgreSQL
* `mysql` - MySQL
* `maiagent` - MaiAgent
* `oracle` - Oracle
* `mssql` - MSSQL
* `synxdb` - SynxDB
  {
  }
  "databaseUrl": string // Database connection string.
  "databaseUrlMasked": string
  "includeTables"?: object // Tables to query, formatted as {"tables": ["table1", "table2"]}. The MaiAgent type reads them from uploaded files automatically, so no manual setup is needed. (任意)
  "isActive"?: boolean // When inactive, this database is not used for Text-to-SQL queries. (任意)
  "createdAt": string (timestamp)
  "updatedAt": string (timestamp)
}
```

**レスポンス値の例**

```json
{
  "id": "550e8400-e29b-41d4-a716-446655440000",
  "name": "サンプル文字列",
  "databaseType": {},
  "databaseUrl": "サンプル文字列",
  "databaseUrlMasked": "サンプル文字列",
  "includeTables": null,
  "isActive": false,
  "createdAt": "サンプル文字列",
  "updatedAt": "サンプル文字列"
}
```

***

### データベース設定を削除 <a href="#chatbots-databases-destroy" id="chatbots-databases-destroy"></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 Database Configuration. |

#### コード例

{% 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 |

***


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.maiagent.ai/api/ja/api-reference/zi-liao-ku.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

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