# Configure subsetting

{% hint style="info" %}
Requires the Advanced API. The Advanced API requires an Enterprise license.
{% endhint %}

You can use the Tonic Structural API to configure [subsetting](https://docs.tonic.ai/app/generation/subsetting) for a workspace. You can also enable or disable subsetting for a workspace.

You can configure a table to be a [target table](https://docs.tonic.ai/app/generation/subsetting/subsetting-about#subsetting-components-target-tables) or a [lookup table](https://docs.tonic.ai/app/generation/subsetting/subsetting-about#subsetting-components-lookup-tables). You can also remove the configuration.

## Subsetting configuration format <a href="#api-subsetting-config-format" id="api-subsetting-config-format"></a>

You apply a subsetting configuration to individual tables.

A subsetting configuration identifies a table as a target table or a lookup table. For a target table, it also indicates how to identify the records to include in the subset.

The configuration includes:

* The name of the schema that contains the table. For requests to update or delete a subsetting rule, the schema name is a request parameter and not in the request body.
* The name of the table. For requests to update or delete a subsetting rule, the table name is a request parameter and not in the request body.
* Whether the table is a lookup table (`IgnoreUpstreamTables` is `true`).\
  \
  For a lookup table, all of the records are always included. `WhereClause` is ignored, and `Percent` is always `100`.\
  \
  If the table is not a lookup table, then it is a target table.
* For a target table, to identify the records to include, either:
  * A `WHERE` clause to filter the source records.
  * A percentage of source records.

## Subsetting configuration examples <a href="#api-subsetting-config-examples" id="api-subsetting-config-examples"></a>

### **Target table with percentage** <a href="#api-subsetting-config-example-target-percentage" id="api-subsetting-config-example-target-percentage"></a>

The following example configures a table as a target table for which to include 5 percent of the records:

```csharp
{
  "Schema": "public";
  "Table": "sales";
  "Percent": 5;
  "IgnoreUpstreamTables": false
}
```

### **Target table with WHERE clause** <a href="#api-subsetting-config-example-target-where" id="api-subsetting-config-example-target-where"></a>

The following example configures a table as a target table for which to include records where the value of `amount` is less than 100.

```csharp
{
  "Schema": "public";
  "Table": "sales";
  "WhereClause": "amount < 100";
  "IgnoreUpstreamTables": false
}
```

### **Lookup table** <a href="#api-subsetting-config-example-lookup" id="api-subsetting-config-example-lookup"></a>

The following example configures a table as a lookup table:

```cpp
{
  "Schema": "public";
  "Table": "states";
  "Percent": 100;
  "IgnoreUpstreamTables": true
}
```

For a lookup table, all of the records are always included. `WhereClause` is ignored, and `Percent` is always `100`.

## Enabling or disabling subsetting for a workspace <a href="#api-subsetting-enable-disable" id="api-subsetting-enable-disable"></a>

To enable subsetting for a workspace, use:

[<mark style="background-color:green;">**POST**</mark>**&#x20;/api/workspace/{workspaceId}/subsetting/enable**](https://app.tonic.ai/apidocs/index.html#/WorkspaceSubsetting/EnableWorkspaceSubsettingAsync)

To disable subsetting for a workspace, use:

[<mark style="background-color:green;">**POST**</mark>**&#x20;/api/workspace/{workspaceId}/subsetting/disable**](https://app.tonic.ai/apidocs/index.html#/WorkspaceSubsetting/DisableWorkspaceSubsettingAsync)

## Retrieving the subsetting configurations for a workspace

To get the current list of subsetting configurations for a workspace, use:

[<mark style="background-color:blue;">**GET**</mark>**&#x20;api/workspace/{workspaceId}/subsetting**](https://app.tonic.ai/apidocs/index.html#/WorkspaceSubsetting/GetWorkspaceSubsettingAsync)

## Adding a subsetting configuration

To add a subsetting configuration, use:

[<mark style="background-color:green;">**POST**</mark>**&#x20;api/workspace/{workspaceId}/subsetting** ](https://app.tonic.ai/apidocs/index.html#/WorkspaceSubsetting/CreateWorkspaceSubsettingAsync)

The request includes the subsetting configuration to apply.

Structural checks whether the specified table has a current subsetting configuration.

* If it does, then Structural uses the provided configuration to update it.
* If it does not, then Structural returns an error.

## Adding or updating a subsetting configuration

To either add or update a subsetting configuration, use:

[<mark style="background-color:orange;">**PUT**</mark>**&#x20;api/workspace/{workspaceId}/subsetting/{schema}/{table}**](https://app.tonic.ai/apidocs/index.html#/WorkspaceSubsetting/UpdateWorkspaceSubsettingAsync)

The request body provides the subsetting configuration to apply to the specified table.

Structural checks whether the specified table has a current subsetting configuration.

* If it does, then Structural uses the provided configuration to update it.
* If it does not, then Structural adds the subsetting configuration for the table.

## Removing a subsetting configuration

To remove a subsetting configuration, use:

[<mark style="background-color:red;">**DELETE**</mark>**&#x20;api/workspace/{workspaceId}/subsetting/{schema}/{table}**](https://app.tonic.ai/apidocs/index.html#/WorkspaceSubsetting/DeleteWorkspaceSubsettingAsync)

Structural removes the subsetting configuration for the specified table.


---

# Agent Instructions: Querying This Documentation

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

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.tonic.ai/app/api/quick-start-guide/tonic-api-subsetting-config.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

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