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

# Connect BigQuery with a Service Account

> Connect BigQuery to Markifact with a Google Cloud service account key, and limit its access to a project, a single dataset or a single table.

You can connect BigQuery in two ways: sign in with Google (Quick Connect), or use a **service account**. A service account is an identity that belongs to your Google Cloud project, not to a person, and you decide exactly which data it can reach. Available on every Markifact plan.

***

## When to use a service account

| Use a service account when | Use Quick Connect when |
| - | - |
| The connection should keep working if a team member leaves | You want to connect in one click |
| You want Markifact to reach only specific datasets or tables | Your own Google access is the right level |
| Your company blocks third-party Google sign-in | Your company blocks service account keys |

***

## Step 1: Create the service account

**1. Create it**

In the [Google Cloud console](https://console.cloud.google.com/iam-admin/serviceaccounts), open **IAM & Admin**, then **Service Accounts**, select your project and click **Create service account**. Give it a name such as `markifact`.

**2. Grant BigQuery Job User**

In the permissions step, add the role **BigQuery Job User**. This lets it run queries. It does not give access to any data yet.

**3. Finish**

Skip the last step and click **Done**. Copy the service account's email address, which looks like `markifact@your-project.iam.gserviceaccount.com`. You need it in the next step.

***

## Step 2: Choose what data it can access

Pick one of the three levels. **Data Viewer** is read-only. **Data Editor** also lets Markifact create tables and insert rows.

| Level | Where you grant it | What Markifact can do |
| - | - | - |
| **Whole project** | IAM, on the project | Browse and query every dataset in the project |
| **One dataset** (most common) | On the dataset | Browse and query that dataset only. Other datasets stay invisible. |
| **One table** | On the table | Query that one table by name. Read-only. |

### Whole project

When you create the service account (or later in **IAM & Admin**, then **IAM**, then **Grant access**), add **BigQuery Data Viewer** or **BigQuery Data Editor** next to BigQuery Job User.

### One dataset

1. In [BigQuery](https://console.cloud.google.com/bigquery), find the dataset in the left panel and click the three dots next to its name.
2. Click **Share**, then **Manage permissions**.
3. Click **Add principal** and paste the service account's email.
4. Choose **BigQuery Data Viewer** (read only) or **BigQuery Data Editor** (read and write), then save.

Repeat for each dataset Markifact should reach. Or run this in the BigQuery editor:

```sql theme={"dark"}
GRANT `roles/bigquery.dataViewer`
ON SCHEMA `your-project.your_dataset`
TO "serviceAccount:markifact@your-project.iam.gserviceaccount.com";
```

Use `roles/bigquery.dataEditor` to also allow writes.

### One table

1. In [BigQuery](https://console.cloud.google.com/bigquery), find the table in the left panel and click the three dots next to its name.
2. Click **Share**, then **Manage permissions**.
3. Click **Add principal** and paste the service account's email.
4. Choose **BigQuery Data Viewer**, then save.

Or with SQL:

```sql theme={"dark"}
GRANT `roles/bigquery.dataViewer`
ON TABLE `your-project.your_dataset.your_table`
TO "serviceAccount:markifact@your-project.iam.gserviceaccount.com";
```

> [!WARNING]
>
> Table-level access works differently from dataset access:
>
> * Markifact can **query the table** and read its schema, but the dataset and table do **not** appear in the dataset and table lists. Type the full table name in your query, for example `your-project.your_dataset.your_table`.
> * It is **read-only in practice**. Insert Rows needs Data Editor on the dataset, not only on the table.
>
> If you want Markifact to browse tables or write data, grant access on the dataset instead.

### What works at each level

| Markifact operation | Whole project | One dataset | One table |
| - | - | - | - |
| Run Query | Yes | Yes, on that dataset | Yes, on that table |
| Get Table Schema | Yes | Yes | Yes |
| List Datasets, List Tables | Yes | Yes, that dataset only | No |
| Insert Rows, Create Table (Data Editor) | Yes | Yes | No |
| Create Dataset (Data Editor) | Yes | No | No |

***

## Step 3: Create a JSON key

1. In **Service Accounts**, open your service account.
2. Go to the **Keys** tab, click **Add key**, then **Create new key**.
3. Choose **JSON** and click **Create**. A `.json` file downloads to your computer.

***

## Step 4: Connect in Markifact

1. Open [Connections](https://www.markifact.com/app/connections) and click **Connect** next to BigQuery.
2. Open the **Service Account** tab.
3. Open the downloaded `.json` file in a text editor, copy all of it and paste it into the box.
4. Click **Save Connection**. Markifact tests the key before saving.

The connection is named after the service account's email. Connecting the same service account again with a new key replaces the old key.

***

## Frequently asked questions

> [accordion] Can I limit Markifact to a single dataset?
>
> Yes, and this is the setup we recommend. Give the service account **BigQuery Job User** on the project, then **BigQuery Data Viewer** or **Data Editor** on that dataset only. Markifact then sees that dataset and nothing else in the project.

> [accordion] Can I limit Markifact to a single table?
>
> Yes, for reading. Grant **BigQuery Data Viewer** on the table. Markifact can query it and read its schema, but the table will not show up in dataset or table lists, so write its full name in the query. To insert rows, grant Data Editor on the dataset instead.

> [accordion] How do I make the connection read-only?
>
> Use **BigQuery Data Viewer** everywhere and never grant Data Editor. Markifact can then query data, and Google refuses every attempt to create tables or insert rows.

> [accordion] Does the service account need access to my whole project?
>
> No. **BigQuery Job User** on the project only lets it run queries. It cannot read any data until you grant Data Viewer or Data Editor on a project, a dataset or a table.

> [accordion] Why is my dataset or table list empty in Markifact?
>
> The service account has no dataset-level access. This is expected when you granted access on single tables only. Either grant Data Viewer on the dataset, or keep table-level access and type the full table name in your query.

> [accordion] We are an agency. How do we set this up for several clients?
>
> Ask each client to create a service account in their own Google Cloud project, grant it access to the datasets they want to share, and send you the JSON key. Add one BigQuery connection per client in Markifact. Each connection only reaches that client's data.

> [accordion] Who pays for the queries?
>
> Queries run in the project you select in Markifact and are billed to that project by Google, the same as queries you run yourself.

> [accordion] How do I remove Markifact's access?
>
> Delete the key under **Service Accounts**, **Keys**, or remove the service account's roles. Access stops immediately. Then delete the connection in Markifact.

***

## Good to know

* **The key does not expire.** It works until you delete it in Google Cloud. To rotate it, create a new key, connect again with it, then delete the old key.
* **Keep the file safe.** Anyone with the key has the service account's access. Delete the downloaded file once the connection is saved.
* **Key creation can be blocked.** Some organizations turn off service account keys with a policy. If **Create new key** is unavailable, ask your Google Cloud admin or use Quick Connect.

***

## Troubleshooting

| Message | What to do |
| - | - |
| That is not a service account key | Paste the whole `.json` file, starting with `{` and ending with `}`. It must contain `"type": "service_account"`. |
| The private key in this service account file could not be read | The file was changed or cut off when copying. Download a new key and paste it unchanged. |
| Google rejected the service account key | The key was deleted or the service account is disabled. Create a new JSON key. |
| BigQuery rejected the service account | Enable the BigQuery API on the project and grant the BigQuery Job User role. |
| Access denied to BigQuery | The service account has no access to that dataset or table, or it has Data Viewer and the operation writes data. Check the table in Step 2. |


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