> ## Documentation Index
> Fetch the complete documentation index at: https://docs.generalvalidation.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Author Table Pairs and Tests

> Save Table references, create Table Pairs, Tests, and test sets through the API, and grant your Environment's workspace identity read access in Fabric.

After an Owner sets up the Environment, a script or agent can manage Tables,
Table Pairs, Tests, and test sets through the General Validation API. Because
the API has no access to your Microsoft Fabric tenant, granting the dedicated
workspace's identity read access to paired Tables happens directly in Fabric
with your tool's own Fabric access.

## Before you start

* An Owner has activated the Organization and set up the Environment in the
  app. Both happen once.
* Your tool calls the API with a workload identity that has
  `GV.APIContributor`; see [API authentication](https://docs.generalvalidation.com/api/authentication.md). Browse
  **Endpoints** in the sidebar for every operation's schema.
* Your tool makes Fabric API calls with an identity that has Admin or Member on
  the source and target workspaces. A service principal also needs your Fabric
  administrator to enable **Service principals can call Fabric public APIs**.

## Create Tables, a Table Pair, and Tests

Save a reference to each existing Lakehouse or Warehouse Table with
`POST /api/v1/fabric/tables`, using the workspace, Lakehouse or Warehouse, and
Table path that Fabric's API lists. Then create the Table Pair with
`POST /api/v1/fabric/pairs` and add Tests with `POST /api/v1/fabric/tests`.
`GET /api/v1/fabric/catalog` returns the fixed catalog of
[the 12 validation functions](https://docs.generalvalidation.com/validate-data/tests.md#the-12-validation-functions).

Each create operation requires an `id` you choose (a new UUID). If a call times
out, send the same request again: the API returns what was saved and creates
nothing more, so scripts can rerun safely.

To share Tests across many Table Pairs, create a
[test set](https://docs.generalvalidation.com/validate-data/tests.md#test-sets) with `POST /api/v1/fabric/test-sets`
containing its name, join keys, and Tests, then pass its ID as `test_set_id`
when creating each Table Pair. `POST /api/v1/fabric/pairs/<pair-id>/test-set`
saves an existing pair's Tests as a new test set, and
`POST /api/v1/fabric/pairs/<pair-id>/independent` gives a pair its own copy of
its set's Tests, matching **Save as test set** and **Make independent** in the
app.

```bash theme={null}
curl --fail-with-body \
  --header "Authorization: Bearer ${gv_access_token}" \
  --header "Content-Type: application/json" \
  --data '{"id": "<new-uuid>", "name": "Orders", "workspace_id": "<workspace-id>", "lakehouse_id": "<lakehouse-id>", "path": "Tables/dbo/orders", "format": "delta"}' \
  "https://api.generalvalidation.com/api/v1/fabric/tables"
```

Tables from connectors (SQL databases, Salesforce, and Lakehouse Files) are
prepared in the app rather than saved with `POST /api/v1/fabric/tables`.
Deleting a Table Pair archives it while keeping its Run history and Results. A
test set cannot be deleted while any Table Pair uses it.

## Give the workspace identity read access

Your Environment's workspace identity needs read access to each source and
target Table outside the dedicated workspace before a Table Pair's first Run.
Ask the API what the pair needs:

```bash theme={null}
curl --fail-with-body \
  --header "Authorization: Bearer ${gv_access_token}" \
  "https://api.generalvalidation.com/api/v1/fabric/pairs/<pair-id>/read-access"
```

```json theme={null}
{
  "identity_id": "<workspace-identity-object-id>",
  "workspaces": [
    {
      "workspace_id": "<source-workspace-id>",
      "workspace_role": "Viewer",
      "lakehouses": [
        {
          "lakehouse_id": "<lakehouse-id>",
          "data_access_role": "GeneralValidation1a2b3c4d",
          "paths": ["/Tables/dbo/orders"]
        }
      ]
    }
  ]
}
```

An empty `workspaces` list means the pair needs no extra grants. Otherwise, in
Fabric, using an identity with Admin or Member on each listed workspace:

1. Add the identity as Viewer on the workspace with
   `POST https://api.fabric.microsoft.com/v1/workspaces/<workspace-id>/roleAssignments`
   and the body
   `{"principal": {"id": "<identity_id>", "type": "ServicePrincipal"}, "role": "Viewer"}`.
   A `409` response means the identity already has a role there; keep it.
2. For each Lakehouse, grant the identity Read on the listed paths through a
   OneLake data access role. The app keeps them in the role named
   `data_access_role`, so add the paths there to keep grants consolidated.
   Fabric's `PUT .../items/<lakehouse-id>/dataAccessRoles` replaces every role
   in the Lakehouse, so read the existing roles first and send the others back
   unchanged with the `ETag` you read.

A Warehouse needs Viewer only. A Table reached through a shortcut also needs
read access at the shortcut's target. As an alternative to calling Fabric APIs
directly, a workspace admin can open the pair in the app, select **Copy Fabric
notebook snippet** in **Access for validation**, and run it in any Fabric
notebook (or list the workspace in `SOURCE_WORKSPACE_IDS` in the installer
notebook). Until access is in place, the pair's Runs end with **Could not read
a Table**.

## Next steps

* [Run validation from code](https://docs.generalvalidation.com/api/run-validation.md)
* [API overview](https://docs.generalvalidation.com/api/overview.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.