> 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/en/api-reference/zi-liao-ku.md).

# Databases

### Create SQL Database Connection <a href="#sql-databases-create" id="sql-databases-create"></a>

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

#### Request Body

**Request Parameters**

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

**Example Request Schema**

```typescript
{
  "name": string // Display name for this database connection
  "description"?: string // Description of the database and its purpose (Optional)
  "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. (Optional)
  "includeTables"?: object // Optional list of tables to include. Format: {"tables": ["table1", "table2"]}. For MaiAgent type, this is auto-populated from uploaded files. (Optional)
  "isActive"?: boolean // When disabled, this database will not be used in Text-to-SQL queries (Optional)
  "chatbots"?: [ // Optional
    {
      "id": string (uuid)
    }
  ]
  "groups"?: [ // Optional
    {
      "id": string (uuid)
    }
  ]
}
```

**Example Request Values**

```json
{
  "name": "Example name",
  "description": "Example string",
  "databaseType": {},
  "databaseUrl": "Example string",
  "includeTables": null,
  "isActive": true,
  "chatbots": [
    {
      "id": "550e8400-e29b-41d4-a716-446655440000"
    }
  ],
  "groups": [
    {
      "id": "550e8400-e29b-41d4-a716-446655440000"
    }
  ]
}
```

#### Code Examples

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

```bash
# API Call Example (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": "Example name",
    "description": "Example string",
    "databaseType": {},
    "databaseUrl": "Example string",
    "includeTables": null,
    "isActive": true,
    "chatbots": [
      {
        "id": "550e8400-e29b-41d4-a716-446655440000"
      }
    ],
    "groups": [
      {
        "id": "550e8400-e29b-41d4-a716-446655440000"
      }
    ]
  }'

# Replace YOUR_API_KEY and verify the request data before running.
```

{% endtab %}

{% tab title="JavaScript" %}

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

// Set request headers
const config = {
  headers: {
    'Authorization': 'Api-Key YOUR_API_KEY',
    'Content-Type': 'application/json'
  }
};

// Request body (payload)
const data = {
    "name": "Example name",
    "description": "Example string",
    "databaseType": {},
    "databaseUrl": "Example string",
    "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('Response received successfully:');
    console.log(response.data);
  })
  .catch(error => {
    console.error('Request failed:');
    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"
}

# Request body (payload)
data = {
    "name": "Example name",
    "description": "Example string",
    "databaseType": {},
    "databaseUrl": "Example string",
    "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("Response received successfully:")
    print(response.json())
except Exception as e:
    print("Request failed:", 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' => 'Example name',
            'description' => 'Example string',
            'databaseType' => new \stdClass(),
            'databaseUrl' => 'Example string',
            '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 "Response received successfully:\n";
    print_r($data);
} catch (Exception $e) {
    echo 'Request failed: ' . $e->getMessage();
}
?>
```

{% endtab %}
{% endtabs %}

#### Response Body

**Status Code: 201**

**Example Response Schema**

```typescript
{
  "id": string (uuid)
  "name": string // Display name for this database connection
  "description"?: string // Description of the database and its purpose (Optional)
  "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. (Optional)
  "isActive"?: boolean // When disabled, this database will not be used in Text-to-SQL queries (Optional)
  "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 (Optional)
      "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) (Optional)
          "description"?: string // Description of the column for better Text-to-SQL understanding (Optional)
          "isPrimaryKey"?: boolean // Optional
          "isNullable"?: boolean // Optional
          "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)
}
```

**Example Response Values**

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

***

### List SQL Databases <a href="#sql-databases-list" id="sql-databases-list"></a>

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

#### Parameters

| Parameter Name | Required | Type    | Description                                                                                                                                                                                                  |
| -------------- | -------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `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  |                                                                                                                                                                                                              |

#### Code Examples

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

```bash
# API call example (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"

# Replace YOUR_API_KEY and verify the request data before running.
```

{% endtab %}

{% tab title="JavaScript" %}

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

// Set request headers
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('Response received successfully:');
    console.log(response.data);
  })
  .catch(error => {
    console.error('Request 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("Response received successfully:")
    print(response.json())
except Exception as e:
    print("Request error:", 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 "Response received successfully:\n";
    print_r($data);
} catch (Exception $e) {
    echo 'Request error: ' . $e->getMessage();
}
?>
```

{% endtab %}
{% endtabs %}

#### Response Content

**Status code: 200**

**Response Schema Example**

```typescript
{
  "count": integer
  "next"?: string (uri) // Optional
  "previous"?: string (uri) // Optional
  "results": [
    {
      "id": string (uuid)
      "name": string // Display name for this database connection
      "description"?: string // Description of the database and its purpose (Optional)
      "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. (Optional)
      "isActive"?: boolean // When disabled, this database will not be used in Text-to-SQL queries (Optional)
      "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)
    }
  ]
}
```

**Response Example Values**

```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": "response string",
      "description": "response string",
      "databaseType": {},
      "databaseUrlMasked": "response string",
      "includeTables": null,
      "isActive": false,
      "status": {},
      "deletedAt": "response string",
      "tables": [
        {
          "id": "550e8400-e29b-41d4-a716-446655440000",
          "tableName": "response string"
        }
      ],
      "tablesCount": 456,
      "chatbots": [
        {
          "id": "550e8400-e29b-41d4-a716-446655440000",
          "name": "response string"
        }
      ],
      "groups": [
        {
          "id": "550e8400-e29b-41d4-a716-446655440000",
          "name": "response string"
        }
      ],
      "createdBy": {
        "id": "550e8400-e29b-41d4-a716-446655440000",
        "name": "response string"
      },
      "canUpdate": false,
      "canDelete": false,
      "createdAt": "response string",
      "updatedAt": "response string"
    }
  ]
}
```

***

### Get Specific SQL Database <a href="#sql-databases-retrieve" id="sql-databases-retrieve"></a>

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

#### Parameters

| Parameter Name | Required | Type   | Description                                  |
| -------------- | -------- | ------ | -------------------------------------------- |
| `id`           | ✅        | string | A UUID string identifying this SQL Database. |

#### Code Examples

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

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

# Replace YOUR_API_KEY and verify the request data before running.
```

{% endtab %}

{% tab title="JavaScript" %}

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

// Set request headers
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('Response received successfully:');
    console.log(response.data);
  })
  .catch(error => {
    console.error('Request failed:');
    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("Response received successfully:")
    print(response.json())
except Exception as e:
    print("Request failed:", 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 "Response received successfully:\n";
    print_r($data);
} catch (Exception $e) {
    echo 'Request failed: ' . $e->getMessage();
}
?>
```

{% endtab %}
{% endtabs %}

#### Response Body

**Status Code: 200**

**Example Response Schema**

```typescript
{
  "id": string (uuid)
  "name": string // Display name for this database connection
  "description"?: string // Description of the database and its purpose (Optional)
  "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. (Optional)
  "isActive"?: boolean // When disabled, this database will not be used in Text-to-SQL queries (Optional)
  "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 (Optional)
      "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) (Optional)
          "description"?: string // Description of the column for better Text-to-SQL understanding (Optional)
          "isPrimaryKey"?: boolean // Optional
          "isNullable"?: boolean // Optional
          "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)
}
```

**Example Response Values**

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

***

### Update SQL Database <a href="#sql-databases-update" id="sql-databases-update"></a>

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

#### Parameters

| Parameter Name | Required | Type   | Description                                  |
| -------------- | -------- | ------ | -------------------------------------------- |
| `id`           | ✅        | string | A UUID string identifying this SQL Database. |

#### Request Body

**Request Parameters**

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

**Example Request Schema**

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

**Example Request Values**

```json
{
  "name": "Example name",
  "description": "Example string",
  "databaseUrl": "Example string",
  "includeTables": null,
  "isActive": true,
  "chatbots": [
    {
      "id": "550e8400-e29b-41d4-a716-446655440000"
    }
  ],
  "groups": [
    {
      "id": "550e8400-e29b-41d4-a716-446655440000"
    }
  ]
}
```

#### Code Examples

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

```bash
# API Call Example (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": "Example name",
    "description": "Example string",
    "databaseUrl": "Example string",
    "includeTables": null,
    "isActive": true,
    "chatbots": [
      {
        "id": "550e8400-e29b-41d4-a716-446655440000"
      }
    ],
    "groups": [
      {
        "id": "550e8400-e29b-41d4-a716-446655440000"
      }
    ]
  }'

# Replace YOUR_API_KEY and verify the request data before running.
```

{% endtab %}

{% tab title="JavaScript" %}

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

// Set request headers
const config = {
  headers: {
    'Authorization': 'Api-Key YOUR_API_KEY',
    'Content-Type': 'application/json'
  }
};

// Request body (payload)
const data = {
    "name": "Example name",
    "description": "Example string",
    "databaseUrl": "Example string",
    "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('Response received successfully:');
    console.log(response.data);
  })
  .catch(error => {
    console.error('Request failed:');
    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"
}

# Request body (payload)
data = {
    "name": "Example name",
    "description": "Example string",
    "databaseUrl": "Example string",
    "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("Response received successfully:")
    print(response.json())
except Exception as e:
    print("Request failed:", 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' => 'Example name',
            'description' => 'Example string',
            'databaseUrl' => 'Example string',
            '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 "Response received successfully:\n";
    print_r($data);
} catch (Exception $e) {
    echo 'Request failed: ' . $e->getMessage();
}
?>
```

{% endtab %}
{% endtabs %}

#### Response Body

**Status Code: 200**

**Example Response Schema**

```typescript
{
  "id": string (uuid)
  "name": string // Display name for this database connection
  "description"?: string // Description of the database and its purpose (Optional)
  "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. (Optional)
  "isActive"?: boolean // When disabled, this database will not be used in Text-to-SQL queries (Optional)
  "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 (Optional)
      "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) (Optional)
          "description"?: string // Description of the column for better Text-to-SQL understanding (Optional)
          "isPrimaryKey"?: boolean // Optional
          "isNullable"?: boolean // Optional
          "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)
}
```

**Example Response Values**

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

***

### Partially Update SQL Database <a href="#sql-databases-partial-update" id="sql-databases-partial-update"></a>

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

#### Parameters

| Parameter Name | Required | Type   | Description                                  |
| -------------- | -------- | ------ | -------------------------------------------- |
| `id`           | ✅        | string | A UUID string identifying this SQL Database. |

#### Request Body

**Request Parameters**

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

**Example Request Schema**

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

**Example Request Values**

```json
{
  "name": "Example name",
  "description": "Example string",
  "databaseUrl": "Example string",
  "includeTables": null,
  "isActive": true,
  "chatbots": [
    {
      "id": "550e8400-e29b-41d4-a716-446655440000"
    }
  ],
  "groups": [
    {
      "id": "550e8400-e29b-41d4-a716-446655440000"
    }
  ]
}
```

#### Code Examples

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

```bash
# API Call Example (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": "Example name",
    "description": "Example string",
    "databaseUrl": "Example string",
    "includeTables": null,
    "isActive": true,
    "chatbots": [
      {
        "id": "550e8400-e29b-41d4-a716-446655440000"
      }
    ],
    "groups": [
      {
        "id": "550e8400-e29b-41d4-a716-446655440000"
      }
    ]
  }'

# Replace YOUR_API_KEY and verify the request data before running.
```

{% endtab %}

{% tab title="JavaScript" %}

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

// Set request headers
const config = {
  headers: {
    'Authorization': 'Api-Key YOUR_API_KEY',
    'Content-Type': 'application/json'
  }
};

// Request body (payload)
const data = {
    "name": "Example name",
    "description": "Example string",
    "databaseUrl": "Example string",
    "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('Response received successfully:');
    console.log(response.data);
  })
  .catch(error => {
    console.error('Request failed:');
    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"
}

# Request body (payload)
data = {
    "name": "Example name",
    "description": "Example string",
    "databaseUrl": "Example string",
    "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("Response received successfully:")
    print(response.json())
except Exception as e:
    print("Request failed:", 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' => 'Example name',
            'description' => 'Example string',
            'databaseUrl' => 'Example string',
            '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 "Response received successfully:\n";
    print_r($data);
} catch (Exception $e) {
    echo 'Request failed: ' . $e->getMessage();
}
?>
```

{% endtab %}
{% endtabs %}

#### Response Body

**Status Code: 200**

**Example Response Schema**

```typescript
{
  "id": string (uuid)
  "name": string // Display name for this database connection
  "description"?: string // Description of the database and its purpose (Optional)
  "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. (Optional)
  "isActive"?: boolean // When disabled, this database will not be used in Text-to-SQL queries (Optional)
  "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 (Optional)
      "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) (Optional)
          "description"?: string // Description of the column for better Text-to-SQL understanding (Optional)
          "isPrimaryKey"?: boolean // Optional
          "isNullable"?: boolean // Optional
          "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)
}
```

**Example Response Values**

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

***

### Delete SQL Database <a href="#sql-databases-destroy" id="sql-databases-destroy"></a>

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

#### Parameters

| Parameter Name | Required | Type   | Description                                  |
| -------------- | -------- | ------ | -------------------------------------------- |
| `id`           | ✅        | string | A UUID string identifying this SQL Database. |

#### Code Examples

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

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

# Replace YOUR_API_KEY and check the request data before running this example.
```

{% endtab %}

{% tab title="JavaScript" %}

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

// Set request headers
const config = {
  headers: {
    'Authorization': 'Api-Key YOUR_API_KEY'
  }
};

// Request body (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('Response received successfully:');
    console.log(response.data);
  })
  .catch(error => {
    console.error('Request failed:');
    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("Response received successfully:")
    print(response.json())
except Exception as e:
    print("Request failed:", 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 "Response received successfully:\n";
    print_r($data);
} catch (Exception $e) {
    echo 'Request failed: ' . $e->getMessage();
}
?>
```

{% endtab %}
{% endtabs %}

#### Response body

| Status code | Description      |
| ----------- | ---------------- |
| 204         | No response body |

***

### Test database connection <a href="#sql-databases-test-connection-create" id="sql-databases-test-connection-create"></a>

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

#### Parameters

| Parameter name | Required | Type   | Description                                  |
| -------------- | -------- | ------ | -------------------------------------------- |
| `id`           | ✅        | string | A UUID string identifying this SQL Database. |

#### Request body

**Request parameters**

| Field        | Type                                                              | Required | Description                                                                                                              |
| ------------ | ----------------------------------------------------------------- | -------- | ------------------------------------------------------------------------------------------------------------------------ |
| databaseType | string (enum: postgresql, mysql, maiagent, oracle, mssql, synxdb) | Yes      | `postgresql`: PostgreSQL ; `mysql`: MySQL ; `maiagent`: MaiAgent ; `oracle`: Oracle ; `mssql`: MSSQL ; `synxdb`: SynxDB; |
| databaseUrl  | string                                                            | Yes      |                                                                                                                          |

**Request schema example**

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

**Request example value**

```json
{
  "databaseType": "postgresql",
  "databaseUrl": "Example string"
}
```

#### Code examples

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

```bash
# Example API call (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": "Example string"
  }'

# Replace YOUR_API_KEY and check the request data before running this example.
```

{% endtab %}

{% tab title="JavaScript" %}

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

// Set request headers
const config = {
  headers: {
    'Authorization': 'Api-Key YOUR_API_KEY',
    'Content-Type': 'application/json'
  }
};

// Request body (payload)
const data = {
    "databaseType": "postgresql",
    "databaseUrl": "Example string"
  };

axios.post("https://api.maiagent.ai/api/v1/sql-databases/550e8400-e29b-41d4-a716-446655440000/test-connection/", data, config)
  .then(response => {
    console.log('Response received successfully:');
    console.log(response.data);
  })
  .catch(error => {
    console.error('Request failed:');
    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"
}

# Request body (payload)
data = {
    "databaseType": "postgresql",
    "databaseUrl": "Example string"
}

response = requests.post(url, json=data, headers=headers)
try:
    print("Response received successfully:")
    print(response.json())
except Exception as e:
    print("Request failed:", 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' => 'Example string'
        ]
    ]);
    
    $data = json_decode($response->getBody(), true);
    echo "Response received successfully:\n";
    print_r($data);
} catch (Exception $e) {
    echo 'Request failed: ' . $e->getMessage();
}
?>
```

{% endtab %}
{% endtabs %}

#### Response body

**Status code: 200**

**Response schema example**

```typescript
{
  "success"?: boolean // optional
  "message"?: string // optional
}
```

**Response example value**

```json
{
  "success": false,
  "message": "Response string"
}
```

***

### Upload files to a database <a href="#sql-databases-upload-files-create" id="sql-databases-upload-files-create"></a>

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

#### Parameters

| Parameter name | Required | Type   | Description                                  |
| -------------- | -------- | ------ | -------------------------------------------- |
| `id`           | ✅        | string | A UUID string identifying this SQL Database. |

#### Request body

**Request parameters**

| Field | Type           | Required | Description |
| ----- | -------------- | -------- | ----------- |
| files | array\[object] | Yes      |             |

**Request schema example**

```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
    }
  ]
}
```

**Request example value**

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

#### Code examples

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

```bash
# Example API call (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
      }
    ]
  }'

# Replace YOUR_API_KEY and check the request data before running this example.
```

{% endtab %}

{% tab title="JavaScript" %}

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

// Set request headers
const config = {
  headers: {
    'Authorization': 'Api-Key YOUR_API_KEY',
    'Content-Type': 'application/json'
  }
};

// Request body (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('Response received successfully:');
    console.log(response.data);
  })
  .catch(error => {
    console.error('Request failed:');
    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"
}

# Request body (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("Response received successfully:")
    print(response.json())
except Exception as e:
    print("Request failed:", 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 "Response received successfully:\n";
    print_r($data);
} catch (Exception $e) {
    echo 'Request failed: ' . $e->getMessage();
}
?>
```

{% endtab %}
{% endtabs %}

#### Response body

**Status code: 201**

**Response schema example**

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

**Response example value**

```json
{
  "message": "Response string",
  "filesCount": 456,
  "fileIds": [
    "550e8400-e29b-41d4-a716-446655440000"
  ]
}
```

***

### Batch delete SQL databases <a href="#sql-databases-batch-delete-create" id="sql-databases-batch-delete-create"></a>

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

#### Request body

**Request parameters**

| Field | Type           | Required | Description |
| ----- | -------------- | -------- | ----------- |
| ids   | array\[string] | Yes      |             |

**Request schema example**

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

**Request example value**

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

#### Code examples

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

```bash
# Example API call (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"
    ]
  }'

# Replace YOUR_API_KEY and check the request data before running this example.
```

{% endtab %}

{% tab title="JavaScript" %}

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

// Set request headers
const config = {
  headers: {
    'Authorization': 'Api-Key YOUR_API_KEY',
    'Content-Type': 'application/json'
  }
};

// Request body (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('Response received successfully:');
    console.log(response.data);
  })
  .catch(error => {
    console.error('Request failed:');
    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"
}

# Request body (payload)
data = {
    "ids": [
        "550e8400-e29b-41d4-a716-446655440000"
    ]
}

response = requests.post(url, json=data, headers=headers)
try:
    print("Response received successfully:")
    print(response.json())
except Exception as e:
    print("Request failed:", 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 "Response received successfully:\n";
    print_r($data);
} catch (Exception $e) {
    echo 'Request failed: ' . $e->getMessage();
}
?>
```

{% endtab %}
{% endtabs %}

#### Response body

| Status code | Description      |
| ----------- | ---------------- |
| 204         | No response body |

***

### List database tables <a href="#sql-databases-tables-list" id="sql-databases-tables-list"></a>

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

#### Parameters

| Parameter name  | Required | Type    | Description                                                                                                                                             |
| --------------- | -------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `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; |

#### Code examples

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

```bash
# Example API call (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"

# Replace YOUR_API_KEY and check the request data before running this example.
```

{% endtab %}

{% tab title="JavaScript" %}

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

// Set request headers
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('Response received successfully:');
    console.log(response.data);
  })
  .catch(error => {
    console.error('Request failed:');
    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("Response received successfully:")
    print(response.json())
except Exception as e:
    print("Request failed:", 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 "Response received successfully:\n";
    print_r($data);
} catch (Exception $e) {
    echo 'Request failed: ' . $e->getMessage();
}
?>
```

{% endtab %}
{% endtabs %}

#### Response body

**Status code: 200**

**Response schema example**

```typescript
{
  "count": integer
  "next"?: string (uri) // optional
  "previous"?: string (uri) // optional
  "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 (optional)
      "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) (optional)
          "description"?: string // Description of the column for better Text-to-SQL understanding (optional)
          "isPrimaryKey"?: boolean // optional
          "isNullable"?: boolean // optional
          "createdAt": string (timestamp)
          "updatedAt": string (timestamp)
        }
      ]
      "createdAt": string (timestamp)
      "updatedAt": string (timestamp)
    }
  ]
}
```

**Response example value**

```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": "Response string",
      "sheetName": "Response string",
      "description": "Response string",
      "status": {},
      "errorMessage": "Response string",
      "sourceFile": {
        "id": "550e8400-e29b-41d4-a716-446655440000",
        "name": "Response string",
        "isFromKnowledgeBase": false
      },
      "columns": [
        {
          "id": "550e8400-e29b-41d4-a716-446655440000",
          "columnName": "Response string",
          "columnType": "Response string",
          "description": "Response string",
          "isPrimaryKey": false,
          "isNullable": false,
          "createdAt": "Response string",
          "updatedAt": "Response string"
        }
      ],
      "createdAt": "Response string",
      "updatedAt": "Response string"
    }
  ]
}
```

***

### Create a database table <a href="#sql-databases-tables-create" id="sql-databases-tables-create"></a>

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

#### Parameters

| Parameter name  | Required | Type   | Description |
| --------------- | -------- | ------ | ----------- |
| `sqlDatabasePk` | ✅        | string |             |

#### Request body

**Request parameters**

| Field       | Type   | Required | Description                                                                |
| ----------- | ------ | -------- | -------------------------------------------------------------------------- |
| tableName   | string | Yes      | Name of the table in the database                                          |
| description | string | No       | Description of the table and its data for better Text-to-SQL understanding |

**Request schema example**

```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 (optional)
}
```

**Request example value**

```json
{
  "tableName": "Example string",
  "description": "Example string"
}
```

#### Code examples

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

```bash
# Example API call (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": "Example string",
    "description": "Example string"
  }'

# Replace YOUR_API_KEY and check the request data before running this example.
```

{% endtab %}

{% tab title="JavaScript" %}

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

// Set request headers
const config = {
  headers: {
    'Authorization': 'Api-Key YOUR_API_KEY',
    'Content-Type': 'application/json'
  }
};

// Request body (payload)
const data = {
    "tableName": "Example string",
    "description": "Example string"
  };

axios.post("https://api.maiagent.ai/api/v1/sql-databases/{sqlDatabasePk}/tables/", data, config)
  .then(response => {
    console.log('Response received successfully:');
    console.log(response.data);
  })
  .catch(error => {
    console.error('Request failed:');
    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"
}

# Request body (payload)
data = {
    "tableName": "Example string",
    "description": "Example string"
}

response = requests.post(url, json=data, headers=headers)
try:
    print("Response received successfully:")
    print(response.json())
except Exception as e:
    print("Request failed:", 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' => 'Example string',
            'description' => 'Example string'
        ]
    ]);
    
    $data = json_decode($response->getBody(), true);
    echo "Response received successfully:\n";
    print_r($data);
} catch (Exception $e) {
    echo 'Request failed: ' . $e->getMessage();
}
?>
```

{% endtab %}
{% endtabs %}

#### Response Body

**Status Code: 201**

**Example Response Schema**

```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 (Optional)
  "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) (Optional)
      "description"?: string // Description of the column for better Text-to-SQL understanding (Optional)
      "isPrimaryKey"?: boolean // Optional
      "isNullable"?: boolean // Optional
      "createdAt": string (timestamp)
      "updatedAt": string (timestamp)
    }
  ]
  "createdAt": string (timestamp)
  "updatedAt": string (timestamp)
}
```

**Example Response Values**

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

***

### Get Specific Table <a href="#sql-databases-tables-retrieve" id="sql-databases-tables-retrieve"></a>

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

#### Parameters

| Parameter Name  | Required | Type   | Description                                    |
| --------------- | -------- | ------ | ---------------------------------------------- |
| `id`            | ✅        | string | A UUID string identifying this Database Table. |
| `sqlDatabasePk` | ✅        | string |                                                |

#### Code Examples

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

```bash
# API Call Example (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"

# Replace YOUR_API_KEY and verify the request data before running.
```

{% endtab %}

{% tab title="JavaScript" %}

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

// Set request headers
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('Response received successfully:');
    console.log(response.data);
  })
  .catch(error => {
    console.error('Request failed:');
    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("Response received successfully:")
    print(response.json())
except Exception as e:
    print("Request failed:", 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 "Response received successfully:\n";
    print_r($data);
} catch (Exception $e) {
    echo 'Request failed: ' . $e->getMessage();
}
?>
```

{% endtab %}
{% endtabs %}

#### Response Body

**Status Code: 200**

**Example Response Schema**

```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 (Optional)
  "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) (Optional)
      "description"?: string // Description of the column for better Text-to-SQL understanding (Optional)
      "isPrimaryKey"?: boolean // Optional
      "isNullable"?: boolean // Optional
      "createdAt": string (timestamp)
      "updatedAt": string (timestamp)
    }
  ]
  "createdAt": string (timestamp)
  "updatedAt": string (timestamp)
}
```

**Example Response Values**

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

***

### Update Table <a href="#sql-databases-tables-update" id="sql-databases-tables-update"></a>

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

#### Parameters

| Parameter Name  | Required | Type   | Description                                    |
| --------------- | -------- | ------ | ---------------------------------------------- |
| `id`            | ✅        | string | A UUID string identifying this Database Table. |
| `sqlDatabasePk` | ✅        | string |                                                |

#### Request Body

**Request Parameters**

| Field       | Type   | Required | Description                                                                |
| ----------- | ------ | -------- | -------------------------------------------------------------------------- |
| tableName   | string | Yes      | Name of the table in the database                                          |
| description | string | No       | Description of the table and its data for better Text-to-SQL understanding |

**Example Request Schema**

```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 (Optional)
}
```

**Example Request Values**

```json
{
  "tableName": "Example string",
  "description": "Example string"
}
```

#### Code Examples

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

```bash
# API Call Example (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": "Example string",
    "description": "Example string"
  }'

# Replace YOUR_API_KEY and verify the request data before running.
```

{% endtab %}

{% tab title="JavaScript" %}

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

// Set request headers
const config = {
  headers: {
    'Authorization': 'Api-Key YOUR_API_KEY',
    'Content-Type': 'application/json'
  }
};

// Request body (payload)
const data = {
    "tableName": "Example string",
    "description": "Example string"
  };

axios.put("https://api.maiagent.ai/api/v1/sql-databases/{sqlDatabasePk}/tables/550e8400-e29b-41d4-a716-446655440000/", data, config)
  .then(response => {
    console.log('Response received successfully:');
    console.log(response.data);
  })
  .catch(error => {
    console.error('Request failed:');
    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"
}

# Request body (payload)
data = {
    "tableName": "Example string",
    "description": "Example string"
}

response = requests.put(url, json=data, headers=headers)
try:
    print("Response received successfully:")
    print(response.json())
except Exception as e:
    print("Request failed:", 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' => 'Example string',
            'description' => 'Example string'
        ]
    ]);
    
    $data = json_decode($response->getBody(), true);
    echo "Response received successfully:\n";
    print_r($data);
} catch (Exception $e) {
    echo 'Request failed: ' . $e->getMessage();
}
?>
```

{% endtab %}
{% endtabs %}

#### Response Body

**Status Code: 200**

**Example Response Schema**

```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 (Optional)
  "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) (Optional)
      "description"?: string // Description of the column for better Text-to-SQL understanding (Optional)
      "isPrimaryKey"?: boolean // Optional
      "isNullable"?: boolean // Optional
      "createdAt": string (timestamp)
      "updatedAt": string (timestamp)
    }
  ]
  "createdAt": string (timestamp)
  "updatedAt": string (timestamp)
}
```

**Example Response Values**

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

***

### Partially Update Table <a href="#sql-databases-tables-partial-update" id="sql-databases-tables-partial-update"></a>

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

#### Parameters

| Parameter Name  | Required | Type   | Description                                    |
| --------------- | -------- | ------ | ---------------------------------------------- |
| `id`            | ✅        | string | A UUID string identifying this Database Table. |
| `sqlDatabasePk` | ✅        | string |                                                |

#### Request Body

**Request Parameters**

| Field       | Type   | Required | Description                                                                |
| ----------- | ------ | -------- | -------------------------------------------------------------------------- |
| tableName   | string | No       | Name of the table in the database                                          |
| description | string | No       | Description of the table and its data for better Text-to-SQL understanding |

**Example Request Schema**

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

**Example Request Values**

```json
{
  "tableName": "Example string",
  "description": "Example string"
}
```

#### Code Examples

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

```bash
# API Call Example (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": "Example string",
    "description": "Example string"
  }'

# Replace YOUR_API_KEY and verify the request data before running.
```

{% endtab %}

{% tab title="JavaScript" %}

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

// Set request headers
const config = {
  headers: {
    'Authorization': 'Api-Key YOUR_API_KEY',
    'Content-Type': 'application/json'
  }
};

// Request body (payload)
const data = {
    "tableName": "Example string",
    "description": "Example string"
  };

axios.patch("https://api.maiagent.ai/api/v1/sql-databases/{sqlDatabasePk}/tables/550e8400-e29b-41d4-a716-446655440000/", data, config)
  .then(response => {
    console.log('Response received successfully:');
    console.log(response.data);
  })
  .catch(error => {
    console.error('Request failed:');
    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"
}

# Request body (payload)
data = {
    "tableName": "Example string",
    "description": "Example string"
}

response = requests.patch(url, json=data, headers=headers)
try:
    print("Response received successfully:")
    print(response.json())
except Exception as e:
    print("Request failed:", 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' => 'Example string',
            'description' => 'Example string'
        ]
    ]);
    
    $data = json_decode($response->getBody(), true);
    echo "Response received successfully:\n";
    print_r($data);
} catch (Exception $e) {
    echo 'Request failed: ' . $e->getMessage();
}
?>
```

{% endtab %}
{% endtabs %}

#### Response Body

**Status Code: 200**

**Example Response Schema**

```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 (Optional)
  "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) (Optional)
      "description"?: string // Description of the column for better Text-to-SQL understanding (Optional)
      "isPrimaryKey"?: boolean // Optional
      "isNullable"?: boolean // Optional
      "createdAt": string (timestamp)
      "updatedAt": string (timestamp)
    }
  ]
  "createdAt": string (timestamp)
  "updatedAt": string (timestamp)
}
```

**Example Response Values**

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

***

### Delete Table <a href="#sql-databases-tables-destroy" id="sql-databases-tables-destroy"></a>

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

#### Parameters

| Parameter Name  | Required | Type   | Description                                    |
| --------------- | -------- | ------ | ---------------------------------------------- |
| `id`            | ✅        | string | A UUID string identifying this Database Table. |
| `sqlDatabasePk` | ✅        | string |                                                |

#### Code Examples

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

```bash
# API Call Example (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"

# Replace YOUR_API_KEY and verify the request data before running.
```

{% endtab %}

{% tab title="JavaScript" %}

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

// Set request headers
const config = {
  headers: {
    'Authorization': 'Api-Key YOUR_API_KEY'
  }
};

// Request body (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('Response received successfully:');
    console.log(response.data);
  })
  .catch(error => {
    console.error('Request failed:');
    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("Response received successfully:")
    print(response.json())
except Exception as e:
    print("Request failed:", 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 "Response received successfully:\n";
    print_r($data);
} catch (Exception $e) {
    echo 'Request failed: ' . $e->getMessage();
}
?>
```

{% endtab %}
{% endtabs %}

#### Response Body

| Status code | Description      |
| ----------- | ---------------- |
| 204         | No response body |

***

### Batch delete tables <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/`

#### Parameters

| Parameter Name  | Required | Type   | Description |
| --------------- | -------- | ------ | ----------- |
| `sqlDatabasePk` | ✅        | string |             |

#### Request Body

**Request Parameters**

| Field | Type           | Required | Description |
| ----- | -------------- | -------- | ----------- |
| ids   | array\[string] | Yes      |             |

**Example Request Schema**

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

**Example Request Values**

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

#### Code Examples

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

```bash
# API Call Example (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"
    ]
  }'

# Replace YOUR_API_KEY and verify the request data before running.
```

{% endtab %}

{% tab title="JavaScript" %}

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

// Set request headers
const config = {
  headers: {
    'Authorization': 'Api-Key YOUR_API_KEY',
    'Content-Type': 'application/json'
  }
};

// Request body (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('Response received successfully:');
    console.log(response.data);
  })
  .catch(error => {
    console.error('Request failed:');
    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"
}

# Request body (payload)
data = {
    "ids": [
        "550e8400-e29b-41d4-a716-446655440000"
    ]
}

response = requests.post(url, json=data, headers=headers)
try:
    print("Response received successfully:")
    print(response.json())
except Exception as e:
    print("Request failed:", 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 "Response received successfully:\n";
    print_r($data);
} catch (Exception $e) {
    echo 'Request failed: ' . $e->getMessage();
}
?>
```

{% endtab %}
{% endtabs %}

#### Response Body

| Status code | Description      |
| ----------- | ---------------- |
| 204         | No response body |

***

### List table columns <a href="#sql-databases-tables-columns-list" id="sql-databases-tables-columns-list"></a>

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

#### Parameters

| Parameter Name  | Required | Type   | Description |
| --------------- | -------- | ------ | ----------- |
| `sqlDatabasePk` | ✅        | string |             |
| `tablePk`       | ✅        | string |             |

#### Code Examples

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

```bash
# API Call Example (Shell)
curl -X GET "https://api.maiagent.ai/api/v1/sql-databases/{sqlDatabasePk}/tables/{tablePk}/columns/" \
  -H "Authorization: Api-Key YOUR_API_KEY"

# Replace YOUR_API_KEY and verify the request data before running.
```

{% endtab %}

{% tab title="JavaScript" %}

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

// Set request headers
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('Response received successfully:');
    console.log(response.data);
  })
  .catch(error => {
    console.error('Request failed:');
    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("Response received successfully:")
    print(response.json())
except Exception as e:
    print("Request failed:", 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 "Response received successfully:\n";
    print_r($data);
} catch (Exception $e) {
    echo 'Request failed: ' . $e->getMessage();
}
?>
```

{% endtab %}
{% endtabs %}

#### Response Body

**Status Code: 200**

**Example Response Schema**

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

**Example Response Values**

```json
[
  {
    "id": "550e8400-e29b-41d4-a716-446655440000",
    "columnName": "Response string",
    "columnType": "Response string",
    "description": "Response string",
    "isPrimaryKey": false,
    "isNullable": false,
    "createdAt": "Response string",
    "updatedAt": "Response string"
  }
]
```

***

### Get a specific table column <a href="#sql-databases-tables-columns-retrieve" id="sql-databases-tables-columns-retrieve"></a>

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

#### Parameters

| Parameter Name  | Required | Type   | Description                                           |
| --------------- | -------- | ------ | ----------------------------------------------------- |
| `id`            | ✅        | string | A UUID string identifying this Database Table Column. |
| `sqlDatabasePk` | ✅        | string |                                                       |
| `tablePk`       | ✅        | string |                                                       |

#### Code Examples

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

```bash
# API Call Example (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"

# Replace YOUR_API_KEY and verify the request data before running.
```

{% endtab %}

{% tab title="JavaScript" %}

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

// Set request headers
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('Response received successfully:');
    console.log(response.data);
  })
  .catch(error => {
    console.error('Request failed:');
    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("Response received successfully:")
    print(response.json())
except Exception as e:
    print("Request failed:", 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 "Response received successfully:\n";
    print_r($data);
} catch (Exception $e) {
    echo 'Request failed: ' . $e->getMessage();
}
?>
```

{% endtab %}
{% endtabs %}

#### Response Body

**Status Code: 200**

**Example Response Schema**

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

**Example Response Values**

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

***

### Update a table column <a href="#sql-databases-tables-columns-update" id="sql-databases-tables-columns-update"></a>

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

#### Parameters

| Parameter Name  | Required | Type   | Description                                           |
| --------------- | -------- | ------ | ----------------------------------------------------- |
| `id`            | ✅        | string | A UUID string identifying this Database Table Column. |
| `sqlDatabasePk` | ✅        | string |                                                       |
| `tablePk`       | ✅        | string |                                                       |

#### Request Body

**Request Parameters**

| Field        | Type    | Required | Description                                                    |
| ------------ | ------- | -------- | -------------------------------------------------------------- |
| columnName   | string  | Yes      |                                                                |
| columnType   | string  | No       | Data type of the column (e.g., VARCHAR, INTEGER, TIMESTAMP)    |
| description  | string  | No       | Description of the column for better Text-to-SQL understanding |
| isPrimaryKey | boolean | No       |                                                                |
| isNullable   | boolean | No       |                                                                |

**Example Request Schema**

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

**Example Request Values**

```json
{
  "columnName": "Example string",
  "columnType": "Example string",
  "description": "Example string",
  "isPrimaryKey": true,
  "isNullable": true
}
```

#### Code Examples

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

```bash
# API Call Example (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": "Example string",
    "columnType": "Example string",
    "description": "Example string",
    "isPrimaryKey": true,
    "isNullable": true
  }'

# Replace YOUR_API_KEY and verify the request data before running.
```

{% endtab %}

{% tab title="JavaScript" %}

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

// Set request headers
const config = {
  headers: {
    'Authorization': 'Api-Key YOUR_API_KEY',
    'Content-Type': 'application/json'
  }
};

// Request body (payload)
const data = {
    "columnName": "Example string",
    "columnType": "Example string",
    "description": "Example string",
    "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('Response received successfully:');
    console.log(response.data);
  })
  .catch(error => {
    console.error('Request failed:');
    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"
}

# Request body (payload)
data = {
    "columnName": "Example string",
    "columnType": "Example string",
    "description": "Example string",
    "isPrimaryKey": True,
    "isNullable": True
}

response = requests.put(url, json=data, headers=headers)
try:
    print("Response received successfully:")
    print(response.json())
except Exception as e:
    print("Request failed:", 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' => 'Example string',
            'columnType' => 'Example string',
            'description' => 'Example string',
            'isPrimaryKey' => true,
            'isNullable' => true
        ]
    ]);
    
    $data = json_decode($response->getBody(), true);
    echo "Response received successfully:\n";
    print_r($data);
} catch (Exception $e) {
    echo 'Request failed: ' . $e->getMessage();
}
?>
```

{% endtab %}
{% endtabs %}

#### Response Body

**Status Code: 200**

**Example Response Schema**

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

**Example Response Values**

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

***

### Partially update a table column <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}/`

#### Parameters

| Parameter Name  | Required | Type   | Description                                           |
| --------------- | -------- | ------ | ----------------------------------------------------- |
| `id`            | ✅        | string | A UUID string identifying this Database Table Column. |
| `sqlDatabasePk` | ✅        | string |                                                       |
| `tablePk`       | ✅        | string |                                                       |

#### Request Body

**Request Parameters**

| Field        | Type    | Required | Description                                                    |
| ------------ | ------- | -------- | -------------------------------------------------------------- |
| columnName   | string  | No       |                                                                |
| columnType   | string  | No       | Data type of the column (e.g., VARCHAR, INTEGER, TIMESTAMP)    |
| description  | string  | No       | Description of the column for better Text-to-SQL understanding |
| isPrimaryKey | boolean | No       |                                                                |
| isNullable   | boolean | No       |                                                                |

**Example Request Schema**

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

**Example Request Values**

```json
{
  "columnName": "Example string",
  "columnType": "Example string",
  "description": "Example string",
  "isPrimaryKey": true,
  "isNullable": true
}
```

#### Code Examples

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

```bash
# API Call Example (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": "Example string",
    "columnType": "Example string",
    "description": "Example string",
    "isPrimaryKey": true,
    "isNullable": true
  }'

# Replace YOUR_API_KEY and verify the request data before running.
```

{% endtab %}

{% tab title="JavaScript" %}

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

// Set request headers
const config = {
  headers: {
    'Authorization': 'Api-Key YOUR_API_KEY',
    'Content-Type': 'application/json'
  }
};

// Request body (payload)
const data = {
    "columnName": "Example string",
    "columnType": "Example string",
    "description": "Example string",
    "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('Response received successfully:');
    console.log(response.data);
  })
  .catch(error => {
    console.error('Request failed:');
    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"
}

# Request body (payload)
data = {
    "columnName": "Example string",
    "columnType": "Example string",
    "description": "Example string",
    "isPrimaryKey": True,
    "isNullable": True
}

response = requests.patch(url, json=data, headers=headers)
try:
    print("Response received successfully:")
    print(response.json())
except Exception as e:
    print("Request failed:", 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' => 'Example string',
            'columnType' => 'Example string',
            'description' => 'Example string',
            'isPrimaryKey' => true,
            'isNullable' => true
        ]
    ]);
    
    $data = json_decode($response->getBody(), true);
    echo "Response received successfully:\n";
    print_r($data);
} catch (Exception $e) {
    echo 'Request failed: ' . $e->getMessage();
}
?>
```

{% endtab %}
{% endtabs %}

#### Response Body

**Status Code: 200**

**Example Response Schema**

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

**Example Response Values**

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

***

### Test Database Connection (General) <a href="#database-connection-test-create" id="database-connection-test-create"></a>

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

#### Request Body

**Request Parameters**

| Field        | Type   | Required | Description                                                                                                                                                      |
| ------------ | ------ | -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| databaseType | object | Yes      | Database type (excluding the type used internally by MaiAgent) `postgresql`: PostgreSQL ; `mysql`: MySQL ; `oracle`: Oracle ; `mssql`: MSSQL ; `synxdb`: SynxDB; |
| databaseUrl  | string | Yes      | Database connection string                                                                                                                                       |

**Example Request Schema**

```typescript
{
  "databaseType":  // Database type (excluding the type used internally by MaiAgent)

* `postgresql` - PostgreSQL
* `mysql` - MySQL
* `oracle` - Oracle
* `mssql` - MSSQL
* `synxdb` - SynxDB
  {
  }
  "databaseUrl": string // Database connection string
}
```

**Example Request Values**

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

#### Code Examples

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

```bash
# API Call Example (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"
  }'

# Replace YOUR_API_KEY and verify the request data before running.
```

{% endtab %}

{% tab title="JavaScript" %}

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

// Set request headers
const config = {
  headers: {
    'Authorization': 'Api-Key YOUR_API_KEY',
    'Content-Type': 'application/json'
  }
};

// Request body (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('Response received successfully:');
    console.log(response.data);
  })
  .catch(error => {
    console.error('Request failed:');
    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"
}

# Request body (payload)
data = {
    "database_type": "postgresql",
    "database_url": "postgresql://user:password@localhost:5432/dbname"
}

response = requests.post(url, json=data, headers=headers)
try:
    print("Response received successfully:")
    print(response.json())
except Exception as e:
    print("Request failed:", 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 "Response received successfully:\n";
    print_r($data);
} catch (Exception $e) {
    echo 'Request failed: ' . $e->getMessage();
}
?>
```

{% endtab %}
{% endtabs %}

#### Response Body

**Status Code: 200**

**Example Response Schema**

```typescript
{
  "status":  // Connection status

* `success` - success
* `failed` - failed
  {
  }
  "responseTime"?: number (double) // Response time (seconds) (Optional)
  "message"?: string // Success message (Optional)
  "errorMessage"?: string // Error message (Optional)
}
```

**Example Response Values**

```json
{
  "status": "success",
  "response_time": 0.123,
  "message": "Successfully connected to PostgreSQL database"
}
```

**Status Code: 400**

**Example Response Schema**

```typescript
{
  "detail"?: string // Optional
}
```

**Example Response Values**

```json
{
  "status": "success",
  "response_time": 0.123,
  "message": "Successfully connected to PostgreSQL database"
}
```

***

### List Database Connection String Examples <a href="#database-examples-list" id="database-examples-list"></a>

GET `/api/v1/database-examples/`

#### Code Examples

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

```bash
# Example API call (Shell)
curl -X GET "https://api.maiagent.ai/api/v1/database-examples/" \
  -H "Authorization: Api-Key YOUR_API_KEY"

# Replace YOUR_API_KEY and verify the request data before running.
```

{% endtab %}

{% tab title="JavaScript" %}

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

// Set request headers
const config = {
  headers: {
    'Authorization': 'Api-Key YOUR_API_KEY'
  }
};

axios.get("https://api.maiagent.ai/api/v1/database-examples/", config)
  .then(response => {
    console.log('Response received successfully:');
    console.log(response.data);
  })
  .catch(error => {
    console.error('Request failed:');
    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("Response received successfully:")
    print(response.json())
except Exception as e:
    print("Request failed:", 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 "Response received successfully:\n";
    print_r($data);
} catch (Exception $e) {
    echo 'Request failed: ' . $e->getMessage();
}
?>
```

{% endtab %}
{% endtabs %}

#### Response Body

**Status Code: 200**

**Example Response Schema**

```typescript
[
  {
    "databaseType"?:  // Database type option

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

**Example Response Values**

```json
[
  {
    "databaseType": {},
    "databaseTypeExample": "Response string"
  }
]
```

**Status Code: 401**

**Example Response Schema**

```typescript
{
  "detail"?: string // Optional
}
```

**Example Response Values**

```json
{
  "detail": "Response string"
}
```

***

### Retrieve a Specific Connection String Example <a href="#database-examples-retrieve" id="database-examples-retrieve"></a>

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

#### Parameters

| Parameter | Required | Type   | Description                                                 |
| --------- | -------- | ------ | ----------------------------------------------------------- |
| `id`      | ✅        | string | A UUID string identifying this Database Connection Example. |

#### Code Examples

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

```bash
# Example API call (Shell)
curl -X GET "https://api.maiagent.ai/api/v1/database-examples/550e8400-e29b-41d4-a716-446655440000/" \
  -H "Authorization: Api-Key YOUR_API_KEY"

# Replace YOUR_API_KEY and verify the request data before running.
```

{% endtab %}

{% tab title="JavaScript" %}

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

// Set request headers
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('Response received successfully:');
    console.log(response.data);
  })
  .catch(error => {
    console.error('Request failed:');
    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("Response received successfully:")
    print(response.json())
except Exception as e:
    print("Request failed:", 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 "Response received successfully:\n";
    print_r($data);
} catch (Exception $e) {
    echo 'Request failed: ' . $e->getMessage();
}
?>
```

{% endtab %}
{% endtabs %}

#### Response Body

**Status Code: 200**

**Example Response Schema**

```typescript
{
  "databaseType"?:  // Database type option

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

**Example Response Values**

```json
{
  "databaseType": {},
  "databaseTypeExample": "Response string"
}
```

***

### List Database Configurations of an AI Assistant <a href="#chatbots-databases-list" id="chatbots-databases-list"></a>

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

#### Parameters

| Parameter Name | Required | Type    | Description                                    |
| -------------- | -------- | ------- | ---------------------------------------------- |
| `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.          |

#### Code Examples

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

```bash
# API Call Example (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"

# Replace YOUR_API_KEY and verify the request data before running.
```

{% endtab %}

{% tab title="JavaScript" %}

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

// Set request headers
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('Response received successfully:');
    console.log(response.data);
  })
  .catch(error => {
    console.error('Request failed:');
    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("Response received successfully:")
    print(response.json())
except Exception as e:
    print("Request failed:", 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 "Response received successfully:\n";
    print_r($data);
} catch (Exception $e) {
    echo 'Request failed: ' . $e->getMessage();
}
?>
```

{% endtab %}
{% endtabs %}

#### Response Body

**Status Code: 200**

**Example Response Schema**

```typescript
{
  "count": integer
  "next"?: string (uri) // Optional
  "previous"?: string (uri) // Optional
  "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. (Optional)
      "isActive"?: boolean // When inactive, this database is not used for Text-to-SQL queries. (Optional)
      "createdAt": string (timestamp)
      "updatedAt": string (timestamp)
    }
  ]
}
```

**Example Response Values**

```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": "Response string",
      "databaseType": {},
      "databaseUrl": "Response string",
      "databaseUrlMasked": "Response string",
      "includeTables": null,
      "isActive": false,
      "createdAt": "Response string",
      "updatedAt": "Response string"
    }
  ]
}
```

***

### Add Database Configuration to an AI Assistant <a href="#chatbots-databases-create" id="chatbots-databases-create"></a>

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

#### Parameters

| Parameter Name | Required | Type   | Description                               |
| -------------- | -------- | ------ | ----------------------------------------- |
| `chatbotPk`    | ✅        | string | A UUID string identifying this Chatbot ID |

#### Request Body

**Request Parameters**

| Field         | Type    | Required | Description                                                                                                                                                                                    |
| ------------- | ------- | -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| name          | string  | Yes      | Display name, for example: Main Business DB, Analytics DB.                                                                                                                                     |
| databaseType  | object  | Yes      | Database type: MySQL, PostgreSQL, MSSQL, Oracle, SynxDB, or MaiAgent. `postgresql`: PostgreSQL ; `mysql`: MySQL ; `maiagent`: MaiAgent ; `oracle`: Oracle ; `mssql`: MSSQL ; `synxdb`: SynxDB; |
| databaseUrl   | string  | Yes      | Database connection string.                                                                                                                                                                    |
| includeTables | object  | No       | 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 | No       | When inactive, this database is not used for Text-to-SQL queries.                                                                                                                              |

**Example Request Schema**

```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. (Optional)
  "isActive"?: boolean // When inactive, this database is not used for Text-to-SQL queries. (Optional)
}
```

**Example Request Values**

```json
{
  "name": "Example name",
  "databaseType": {},
  "databaseUrl": "Example string",
  "includeTables": null,
  "isActive": true
}
```

#### Code Examples

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

```bash
# API Call Example (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": "Example name",
    "databaseType": {},
    "databaseUrl": "Example string",
    "includeTables": null,
    "isActive": true
  }'

# Replace YOUR_API_KEY and verify the request data before running.
```

{% endtab %}

{% tab title="JavaScript" %}

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

// Set request headers
const config = {
  headers: {
    'Authorization': 'Api-Key YOUR_API_KEY',
    'Content-Type': 'application/json'
  }
};

// Request body (payload)
const data = {
    "name": "Example name",
    "databaseType": {},
    "databaseUrl": "Example string",
    "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('Response received successfully:');
    console.log(response.data);
  })
  .catch(error => {
    console.error('Request failed:');
    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"
}

# Request body (payload)
data = {
    "name": "Example name",
    "databaseType": {},
    "databaseUrl": "Example string",
    "includeTables": None,
    "isActive": True
}

response = requests.post(url, json=data, headers=headers)
try:
    print("Response received successfully:")
    print(response.json())
except Exception as e:
    print("Request failed:", 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' => 'Example name',
            'databaseType' => new \stdClass(),
            'databaseUrl' => 'Example string',
            'includeTables' => null,
            'isActive' => true
        ]
    ]);
    
    $data = json_decode($response->getBody(), true);
    echo "Response received successfully:\n";
    print_r($data);
} catch (Exception $e) {
    echo 'Request failed: ' . $e->getMessage();
}
?>
```

{% endtab %}
{% endtabs %}

#### Response Body

**Status Code: 201**

**Example Response Schema**

```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. (Optional)
  "isActive"?: boolean // When inactive, this database is not used for Text-to-SQL queries. (Optional)
  "createdAt": string (timestamp)
  "updatedAt": string (timestamp)
}
```

**Example Response Values**

```json
{
  "id": "550e8400-e29b-41d4-a716-446655440000",
  "name": "Response string",
  "databaseType": {},
  "databaseUrl": "Response string",
  "databaseUrlMasked": "Response string",
  "includeTables": null,
  "isActive": false,
  "createdAt": "Response string",
  "updatedAt": "Response string"
}
```

***

### Get Specific Database Configuration <a href="#chatbots-databases-retrieve" id="chatbots-databases-retrieve"></a>

GET `/api/v1/chatbots/{chatbotPk}/databases/{id}/`

#### Parameters

| Parameter Name | Required | Type   | Description                                                    |
| -------------- | -------- | ------ | -------------------------------------------------------------- |
| `chatbotPk`    | ✅        | string | A UUID string identifying this Chatbot ID                      |
| `id`           | ✅        | string | A UUID string identifying this Chatbot Database Configuration. |

#### Code Examples

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

```bash
# API Call Example (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"

# Replace YOUR_API_KEY and verify the request data before running.
```

{% endtab %}

{% tab title="JavaScript" %}

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

// Set request headers
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('Response received successfully:');
    console.log(response.data);
  })
  .catch(error => {
    console.error('Request failed:');
    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("Response received successfully:")
    print(response.json())
except Exception as e:
    print("Request failed:", 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 "Response received successfully:\n";
    print_r($data);
} catch (Exception $e) {
    echo 'Request failed: ' . $e->getMessage();
}
?>
```

{% endtab %}
{% endtabs %}

#### Response Body

**Status Code: 200**

**Example Response Schema**

```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. (Optional)
  "isActive"?: boolean // When inactive, this database is not used for Text-to-SQL queries. (Optional)
  "createdAt": string (timestamp)
  "updatedAt": string (timestamp)
}
```

**Example Response Values**

```json
{
  "id": "550e8400-e29b-41d4-a716-446655440000",
  "name": "Response string",
  "databaseType": {},
  "databaseUrl": "Response string",
  "databaseUrlMasked": "Response string",
  "includeTables": null,
  "isActive": false,
  "createdAt": "Response string",
  "updatedAt": "Response string"
}
```

***

### Update Database Configuration <a href="#chatbots-databases-update" id="chatbots-databases-update"></a>

PUT `/api/v1/chatbots/{chatbotPk}/databases/{id}/`

#### Parameters

| Parameter Name | Required | Type   | Description                                                    |
| -------------- | -------- | ------ | -------------------------------------------------------------- |
| `chatbotPk`    | ✅        | string | A UUID string identifying this Chatbot ID                      |
| `id`           | ✅        | string | A UUID string identifying this Chatbot Database Configuration. |

#### Request Body

**Request Parameters**

| Field         | Type    | Required | Description                                                                                                                                                                                    |
| ------------- | ------- | -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| name          | string  | Yes      | Display name, for example: Main Business DB, Analytics DB.                                                                                                                                     |
| databaseType  | object  | Yes      | Database type: MySQL, PostgreSQL, MSSQL, Oracle, SynxDB, or MaiAgent. `postgresql`: PostgreSQL ; `mysql`: MySQL ; `maiagent`: MaiAgent ; `oracle`: Oracle ; `mssql`: MSSQL ; `synxdb`: SynxDB; |
| databaseUrl   | string  | Yes      | Database connection string.                                                                                                                                                                    |
| includeTables | object  | No       | 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 | No       | When inactive, this database is not used for Text-to-SQL queries.                                                                                                                              |

**Example Request Schema**

```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. (Optional)
  "isActive"?: boolean // When inactive, this database is not used for Text-to-SQL queries. (Optional)
}
```

**Example Request Values**

```json
{
  "name": "Example name",
  "databaseType": {},
  "databaseUrl": "Example string",
  "includeTables": null,
  "isActive": true
}
```

#### Code Examples

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

```bash
# API Call Example (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": "Example name",
    "databaseType": {},
    "databaseUrl": "Example string",
    "includeTables": null,
    "isActive": true
  }'

# Replace YOUR_API_KEY and verify the request data before running.
```

{% endtab %}

{% tab title="JavaScript" %}

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

// Set request headers
const config = {
  headers: {
    'Authorization': 'Api-Key YOUR_API_KEY',
    'Content-Type': 'application/json'
  }
};

// Request body (payload)
const data = {
    "name": "Example name",
    "databaseType": {},
    "databaseUrl": "Example string",
    "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('Response received successfully:');
    console.log(response.data);
  })
  .catch(error => {
    console.error('Request failed:');
    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"
}

# Request body (payload)
data = {
    "name": "Example name",
    "databaseType": {},
    "databaseUrl": "Example string",
    "includeTables": None,
    "isActive": True
}

response = requests.put(url, json=data, headers=headers)
try:
    print("Response received successfully:")
    print(response.json())
except Exception as e:
    print("Request failed:", 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' => 'Example name',
            'databaseType' => new \stdClass(),
            'databaseUrl' => 'Example string',
            'includeTables' => null,
            'isActive' => true
        ]
    ]);
    
    $data = json_decode($response->getBody(), true);
    echo "Response received successfully:\n";
    print_r($data);
} catch (Exception $e) {
    echo 'Request failed: ' . $e->getMessage();
}
?>
```

{% endtab %}
{% endtabs %}

#### Response Body

**Status Code: 200**

**Example Response Schema**

```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. (Optional)
  "isActive"?: boolean // When inactive, this database is not used for Text-to-SQL queries. (Optional)
  "createdAt": string (timestamp)
  "updatedAt": string (timestamp)
}
```

**Example Response Values**

```json
{
  "id": "550e8400-e29b-41d4-a716-446655440000",
  "name": "Response string",
  "databaseType": {},
  "databaseUrl": "Response string",
  "databaseUrlMasked": "Response string",
  "includeTables": null,
  "isActive": false,
  "createdAt": "Response string",
  "updatedAt": "Response string"
}
```

***

### Partially Update Database Configuration <a href="#chatbots-databases-partial-update" id="chatbots-databases-partial-update"></a>

PATCH `/api/v1/chatbots/{chatbotPk}/databases/{id}/`

#### Parameters

| Parameter Name | Required | Type   | Description                                                    |
| -------------- | -------- | ------ | -------------------------------------------------------------- |
| `chatbotPk`    | ✅        | string | A UUID string identifying this Chatbot ID                      |
| `id`           | ✅        | string | A UUID string identifying this Chatbot Database Configuration. |

#### Request Body

**Request Parameters**

| Field         | Type    | Required | Description                                                                                                                                                                                    |
| ------------- | ------- | -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| name          | string  | No       | Display name, for example: Main Business DB, Analytics DB.                                                                                                                                     |
| databaseType  | object  | No       | Database type: MySQL, PostgreSQL, MSSQL, Oracle, SynxDB, or MaiAgent. `postgresql`: PostgreSQL ; `mysql`: MySQL ; `maiagent`: MaiAgent ; `oracle`: Oracle ; `mssql`: MSSQL ; `synxdb`: SynxDB; |
| databaseUrl   | string  | No       | Database connection string.                                                                                                                                                                    |
| includeTables | object  | No       | 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 | No       | When inactive, this database is not used for Text-to-SQL queries.                                                                                                                              |

**Example Request Schema**

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

* `postgresql` - PostgreSQL
* `mysql` - MySQL
* `maiagent` - MaiAgent
* `oracle` - Oracle
* `mssql` - MSSQL
* `synxdb` - SynxDB (Optional)
  {
  }
  "databaseUrl"?: string // Database connection string. (Optional)
  "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. (Optional)
  "isActive"?: boolean // When inactive, this database is not used for Text-to-SQL queries. (Optional)
}
```

**Example Request Values**

```json
{
  "name": "Example name",
  "databaseType": {},
  "databaseUrl": "Example string",
  "includeTables": null,
  "isActive": true
}
```

#### Code Examples

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

```bash
# API Call Example (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": "Example name",
    "databaseType": {},
    "databaseUrl": "Example string",
    "includeTables": null,
    "isActive": true
  }'

# Replace YOUR_API_KEY and verify the request data before running.
```

{% endtab %}

{% tab title="JavaScript" %}

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

// Set request headers
const config = {
  headers: {
    'Authorization': 'Api-Key YOUR_API_KEY',
    'Content-Type': 'application/json'
  }
};

// Request body (payload)
const data = {
    "name": "Example name",
    "databaseType": {},
    "databaseUrl": "Example string",
    "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('Response received successfully:');
    console.log(response.data);
  })
  .catch(error => {
    console.error('Request failed:');
    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"
}

# Request body (payload)
data = {
    "name": "Example name",
    "databaseType": {},
    "databaseUrl": "Example string",
    "includeTables": None,
    "isActive": True
}

response = requests.patch(url, json=data, headers=headers)
try:
    print("Response received successfully:")
    print(response.json())
except Exception as e:
    print("Request failed:", 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' => 'Example name',
            'databaseType' => new \stdClass(),
            'databaseUrl' => 'Example string',
            'includeTables' => null,
            'isActive' => true
        ]
    ]);
    
    $data = json_decode($response->getBody(), true);
    echo "Response received successfully:\n";
    print_r($data);
} catch (Exception $e) {
    echo 'Request failed: ' . $e->getMessage();
}
?>
```

{% endtab %}
{% endtabs %}

#### Response Body

**Status Code: 200**

**Example Response Schema**

```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. (Optional)
  "isActive"?: boolean // When inactive, this database is not used for Text-to-SQL queries. (Optional)
  "createdAt": string (timestamp)
  "updatedAt": string (timestamp)
}
```

**Example Response Values**

```json
{
  "id": "550e8400-e29b-41d4-a716-446655440000",
  "name": "Response string",
  "databaseType": {},
  "databaseUrl": "Response string",
  "databaseUrlMasked": "Response string",
  "includeTables": null,
  "isActive": false,
  "createdAt": "Response string",
  "updatedAt": "Response string"
}
```

***

### Delete Database Configuration <a href="#chatbots-databases-destroy" id="chatbots-databases-destroy"></a>

DELETE `/api/v1/chatbots/{chatbotPk}/databases/{id}/`

#### Parameters

| Parameter Name | Required | Type   | Description                                                    |
| -------------- | -------- | ------ | -------------------------------------------------------------- |
| `chatbotPk`    | ✅        | string | A UUID string identifying this Chatbot ID                      |
| `id`           | ✅        | string | A UUID string identifying this Chatbot Database Configuration. |

#### Code Examples

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

```bash
# API Call Example (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"

# Replace YOUR_API_KEY and verify the request data before running.
```

{% endtab %}

{% tab title="JavaScript" %}

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

// Set request headers
const config = {
  headers: {
    'Authorization': 'Api-Key YOUR_API_KEY'
  }
};

// Request body (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('Response received successfully:');
    console.log(response.data);
  })
  .catch(error => {
    console.error('Request failed:');
    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("Response received successfully:")
    print(response.json())
except Exception as e:
    print("Request failed:", 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 "Response received successfully:\n";
    print_r($data);
} catch (Exception $e) {
    echo 'Request failed: ' . $e->getMessage();
}
?>
```

{% endtab %}
{% endtabs %}

#### Response Body

| Status Code | Description      |
| ----------- | ---------------- |
| 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/en/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.
