# Query the connector table

List tables or collections in a structured data source. `object_kind` in the response is used to determine the object type.

```text
POST https://moi.matrixorigin.cn/newmoi/connectors/structured/v1/source/objects
```

## Preparation before calling

Prepare the query conditions in this order:

1. [List connector databases](list-databases.md) and record the database name.
2. Confirm that the browsable connector has `enabled` and `capabilities.list_tables` set to `true`.
3. Only when `list_schemas` is `true`, [list database schemas](list-schemas.md) and pass the returned schema name; otherwise, omit `schema`.

The example below uses:

- `$AI_STUDIO_API_KEY`: The actual personal access token, passed through the `X-API-Key` Header.
- `$WORKSPACE_ID`: The workspace ID to be queried, passed through the `X-Workspace-ID` Header.
- `$CONNECTOR_ID` and `$SOURCE_TYPE`: View the connector ID and source type returned by the browsable connector interface.
- `$DATABASE`: Query the `data.databases[].name` returned by the database interface.
- `$SCHEMA`: Get the `data.schemas[].name` returned by the database classification interface; this field is not passed when the source does not support the classification level.

## Request example

```bash
curl -X POST "https://moi.matrixorigin.cn/newmoi/connectors/structured/v1/source/objects" \
  -H "X-API-Key: $AI_STUDIO_API_KEY" \
  -H "X-Workspace-ID: $WORKSPACE_ID" \
  -H 'Content-Type: application/json' \
  -d "{
    \"connector_id\": \"$CONNECTOR_ID\",
    \"source_type\": \"$SOURCE_TYPE\",
    \"database\": \"$DATABASE\"
  }"
```

When the source has this classification level, add `"schema":"$SCHEMA"` in the request body.

## Request body

| Field | Type | Is it required | Description |
| --- | --- | --- | --- |
| `connector_id` | string | Yes | The saved connector ID. |
| `source_type` | string | Yes | A structured source type. |
| `database` | string | Yes | Database name. |
| `schema` | string | No | Database classification name; only provided if the source has this classification level. |

`[]` after a type denotes an array. `[]` in a field path denotes each item in an array.

## Successful response

Returns `200` on success.

```json
{
  "code": "OK",
  "msg": "OK",
  "data": {
    "objects": [
      {
        "database": "sales",
        "schema": "public",
        "table": "orders",
        "display_name": "orders",
        "object_kind": "table"
      }
    ],
    "endpoint_results": []
  }
}
```

The response fields are as follows.

| Field | Type | Description |
| --- | --- | --- |
| `code` | string | `OK` on success. |
| `msg` | string | `OK` on success. |
| `data.objects` | object[] | Structured objects under the current database and category. |
| `data.objects[].database` | string | The database to which the object belongs, passed as it is when [querying the connector table structure](get-table-schema.md). |
| `data.objects[].schema` | string | The database classification to which the object belongs; may be omitted if not applicable. Pass in the table structure query as is when needed. |
| `data.objects[].table` | string | Table name; returned for table objects and passed unchanged when querying the table structure. |
| `data.objects[].collection` | string | Collection name; returned for collection objects and passed unchanged when querying the table structure. |
| `data.objects[].display_name` | string | The name of the object used for display. |
| `data.objects[].object_kind` | string | Object type. |
| `data.endpoint_results` | JSON[] | Currently returns an empty array. |

`[]` after a type means an array. For example, `string[]` is an array of strings.


## Error response

```json
{
  "code": "ErrParamInvalid",
  "msg": "invalid parameter",
  "data": null
}
```

### Common HTTP errors

```{list-table}
:header-rows: 1
:widths: 12 30 28 30

* - HTTP status code
  - error code
  - Common causes
  - Recommended actions
* - `400`
  - `ErrParamInvalid`
  - Field is missing, or `source_type` does not match the connector.
  - Use the `connector_id` and `source_type` of the same capability record, and pass in the object location returned in the previous step.
* - `501`
  - `STRUCTURED_CONNECTOR_SERVICE_UNAVAILABLE`
  - The current service does not provide structured data source discovery.
  - This group of interfaces is temporarily unavailable.
* - `200`
  - `STRUCTURED_LOAD_FEATURE_DISABLED`
  - The structured data source feature is not enabled in the current workspace.
  - Check if this feature is available for this workspace.
* - `200`
  - `STRUCTURED_LOAD_MONGODB_DISABLED`
  - MongoDB structured discovery is not enabled for the current workspace.
  - Do not continue calling the MongoDB connector's discovery interface.
* - `500`
  - `ErrServer`
  - The service failed to list the object.
  - Keep the desensitization error message and try again.
```

## Follow-up operations

After selecting the object, bring the object identifier [query connector table structure](get-table-schema.md).
