Skip to main content

Onboard tenants over the API

When your tenants' data sits in shared warehouse tables, you can give every tenant its own Mitzu workspace: the same tables, dashboards and insights, limited to the tenant's rows by a data filter, and branded with the tenant's logo.

What a tenant can be​

A tenant is whoever owns a slice of rows in your shared tables and should only ever see that slice. The column that identifies it is usually called tenant_id, but any column works. Common cases:

  • App: one product or app among several that write into the same event tables, for example each mobile app of a studio, or each brand site of a group.
  • Partner: a seller, brand or supplier on your marketplace or platform who gets analytics on their own business.
  • Customer: a client of your B2B product who gets analytics on how their own users use it.

The same works for any other split: a store, a franchise, a region or a business unit. See What a tenant can be on the data filter page.

How it works​

Set up one template workspace by hand or over the API, then create each tenant's workspace from it with a single API call. This page walks through the whole flow with curl. Every request is described in the API reference.

Before you start​

  • Create an API key. For these requests the key acts as an Org Admin. Store it as a secret.
  • Every table the tenants share needs a column that tells the tenants apart, for example tenant_id.
export MITZU_API=https://app.mitzu.io/api/v1
export MITZU_KEY=<your API key>

1. Create the template workspace​

Create a workspace with the warehouse connection. Credentials are write-only: no response ever contains them.

curl -s -X POST "$MITZU_API/projects" \
-H "x-mitzu-api-key: $MITZU_KEY" \
-H "Content-Type: application/json" \
-d '{
"name": "Tenant template",
"connection": {
"type": "bigquery",
"host": "my-gcp-project",
"password": "<service account JSON as a string>"
}
}'

The response is the workspace with its id. Then add the tables:

TEMPLATE=<id of the template workspace>

curl -s -X POST "$MITZU_API/projects/$TEMPLATE/event-tables" \
-H "x-mitzu-api-key: $MITZU_KEY" -H "Content-Type: application/json" \
-d '{"table_schema": "marketplace", "table_name": "events",
"event_time_field": "event_time", "user_id_field": "user_id",
"event_name_field": "event_name"}'

curl -s -X POST "$MITZU_API/projects/$TEMPLATE/dimension-tables" \
-H "x-mitzu-api-key: $MITZU_KEY" -H "Content-Type: application/json" \
-d '{"table_schema": "marketplace", "table_name": "customers",
"entity": "user", "primary_key": "user_id"}'

curl -s -X POST "$MITZU_API/projects/$TEMPLATE/metric-tables" \
-H "x-mitzu-api-key: $MITZU_KEY" -H "Content-Type: application/json" \
-d '{"table_schema": "marketplace", "table_name": "daily_sales", "grain": "day",
"columns": [
{"column_name": "day", "role": "time"},
{"column_name": "revenue", "role": "metric_value",
"metric_name": "Revenue", "roll_up": "add_up"},
{"column_name": "country", "role": "dimension"}
]}'

Index the template and build the dashboards and insights every tenant should get. You can do that in Mitzu, where they are easiest to design.

curl -s -X POST "$MITZU_API/projects/$TEMPLATE/index" -H "x-mitzu-api-key: $MITZU_KEY"

2. Clone one workspace per tenant​

One request creates a tenant's workspace from the template. It sets the name, the data filter and the logo, and starts indexing. Send it as a multipart form: the JSON request goes in the request field, and the images in the logo and cover fields.

curl -s -X POST "$MITZU_API/projects/$TEMPLATE/clone" \
-H "x-mitzu-api-key: $MITZU_KEY" \
-F 'request={"name": "Acme", "data_filter": {"column": "tenant_id", "value": "4711"}, "index": true}' \
-F "logo=@acme-logo.png" \
-F "cover=@acme-cover.jpg"

The clone gets the template's connection, tables, entities, settings, dashboards, saved insights, filter groups and cohorts, wired to its own copies. It doesn't get anything computed from the template's data: cached results, chart images, indexed values, event volumes, cohort members or the workspace's AI memory. Mitzu computes them again with the tenant's filter. It never inherits the template's own data filter.

Imported cohorts are left out, because their members are the template's users. The response lists them in skipped_cohorts; insights that filter on one report the cohort as missing, so build tenant templates on dynamic cohorts. Pinned items, tags, label colors and experiments aren't copied either.

New workspaces are restricted: only Org Admins and the people you add can open them. Add the tenant's users with the members API.

The response holds the new workspace and its indexing tasks:

{
"workspace": {"id": "8c41d2e09f7a", "name": "Acme",
"data_filter": {"column": "tenant_id", "value": "4711"}, "...": "..."},
"tasks": [{"id": "1f0c9b7e2a44", "state": "queued", "error": null}],
"skipped_cohorts": []
}

To onboard many tenants, run the request in a loop over your tenant list.

3. Check the workspace​

Follow the indexing tasks until they finish:

TENANT=<id of the tenant's workspace>

curl -s "$MITZU_API/projects/$TENANT/tasks?task_id=1f0c9b7e2a44" -H "x-mitzu-api-key: $MITZU_KEY"

Then read the workspace back to check its configuration, filter and branding:

curl -s "$MITZU_API/projects/$TENANT" -H "x-mitzu-api-key: $MITZU_KEY"

Change a tenant's workspace later​

  • Replace the logo: PUT /projects/{project_id}/branding/logo with the image in a file form field, for example curl -X PUT ... -F "file=@new-logo.png". Remove it with DELETE.
  • Change the filter: PUT /projects/{project_id}/data-filter with {"column": ..., "value": ...}. This clears the workspace's cached results, so index it again with POST /projects/{project_id}/index.
  • Change settings: PATCH /projects/{project_id}/insight-settings or PATCH /projects/{project_id}/indexing-settings with only the fields to change.
  • Delete the workspace: DELETE /projects/{project_id}. This can't be undone.

Limits​

  • Your plan's limits on workspaces, dimension tables, metric tables and published dashboards apply. A clone that would go over them returns 409 and creates nothing.
  • Event names that only appear in other tenants' rows stay in the clone's event catalog after indexing. Hide them in the catalog if tenants shouldn't see them.