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

# Google Sheets

## 🐕‍🦺 Setup guide

This guide will help you set up Google Sheets as a data source for Zenskar.

> 🚧 Prerequisites
>
> * A Google Cloud Platform (GCP) project.
> * Google Sheets API must be enabled in your GCP project
> * You must possess a Service Account Key with access to the Google Sheets spreadsheet you want to replicate
> * URL of the Google spreadsheet you want to sync.

### Set up GCP

#### Create a service account

1. Open the [Service Accounts](https://console.cloud.google.com/projectselector2/iam-admin/serviceaccounts) page in your Google Cloud console.
2. Select an existing project, or create a new project.

<Image align="center" className="border" border={true} src="https://files.readme.io/c663255edf2bd26607dd2b3b697e945434661034417c7957e3d91730c1419ced-Screenshot_From_2024-10-30_14-33-17.png" />

3. At the top of the page, click **+ CREATE SERVICE ACCOUNT**.

<Image align="center" className="border" border={true} src="https://files.readme.io/4f29d876b2f8d99536957112555cd61c286a652ef2e569bda6fe601db21b2b85-Screenshot_From_2024-10-30_14-35-34.png" />

4. Enter a name and description for the service account, then click **CREATE AND CONTINUE**.

<Image align="center" className="border" width="50% " border={true} src="https://files.readme.io/b1bb93cbdc2b97018de28b1ca3e6988a5188289ce9c4a9e822e276770f45eb1b-Screenshot_From_2024-10-30_14-37-55.png" />

5. Under Service account permissions, select the roles to grant to the service account, then click Continue. We recommend the Viewer role.

<Image align="center" className="border" width="50% " border={true} src="https://files.readme.io/55ac2b1c108fef666c7845bf6573f5050bcc0f7e35ea45d3f283349629f31ea2-Screenshot_From_2024-10-30_14-42-20.png" />

#### Generate a key

1. Go to the [APIs and services](https://console.cloud.google.com/apis/credentials) page and click on the email address of the service account you just created.

<Image align="center" className="border" border={true} src="https://files.readme.io/73ebb20c6dfba0f5f9a3f2a602a4b348090320df9d7e730145029b2e15728cc0-Screenshot_From_2024-10-30_14-48-06.png" />

2. In the **Keys** tab, click the **ADD KEY** drop-down menu, and click on the **Create new key** option.

<Image align="center" className="border" border={true} src="https://files.readme.io/cabe91950e7403ec57cbac837ff7e3200ccb870c7a9f7e51f6b0c7da43737ae1-Screenshot_From_2024-10-30_14-51-34.png" />

3. Select JSON as the key type, and click **CREATE**. This will generate and download the JSON key file that you'll use for authentication.

<Image align="center" className="border" width="55% " border={true} src="https://files.readme.io/f8cf9e642897dde3aa580563b27e11f519daf0cf2cd2e9a2db17b4415a222602-Screenshot_From_2024-10-30_14-52-53.png" />

#### Enable the Google Sheets API

1. Go to the [API Library](https://console.cloud.google.com/apis/library) page.
2. Ensure that the correct project is selected at the top of the page.
3. Find and select the **Google Sheets API** from the **API library**.
4. Click **ENABLE**.

> 📚 Note
>
> If your spreadsheet is viewable by anyone with its link, no further action is needed. If not, give your Service Account access to your spreadsheet.

### ⚙️ Set up data source and type

1. Log into your Zenskar account.
2. In the left navigation bar, click **Metering** > **Data Sources**. In the top-right corner, click **+ ADD DATA SOURCE**.
3. In the **Set Up Source** section of the **Add New Data Source** page, enter a name for the Google Sheets data source connection.
4. Select **Google Sheets** from the **Source Type** drop-down menu.

### ⚙️ Configure data source

Configure the following options in the **Source Config** section of the **Add New Data Source** page:

1. In **Row Batch Size**, define the number of records you want the Google API to fetch at a time. The default value is 200.

> 🚧 Note
>
> The [Google API rate limit](https://developers.google.com/sheets/api/limits) is 100 requests per 100 seconds per user and 500 requests per 100 seconds per project. Zenskar respects these rate limits and batches requests to the API in order to efficiently pull data.

2. Select the **Service Account Key Authentication** option from the **Authentication Type** drop-down menu.
3. In the **Service Account Information** textbox, enter your service account key in JSON format.

> 📚 Information
>
> Zenskar's Google Sheets data-source connector pulls data from a single Google Sheets spreadsheet. To replicate multiple spreadsheets, set up multiple Google Sheets data sources.

> 🚧 Permissions
>
> Please make sure the Service Account has the Project Viewer permission.

> 👍 Security
>
> Zenskar only accesses the spreadsheet you want to replicate. We do not access any other file in your Google Drive.

4. In the **Spreadsheet Link** textbox, enter the link to the Google Sheets spreadsheet. To get the link, go to the Google spreadsheet you want to sync, click **Share** in the top right corner, and click **Copy link**.
5. Click on the **SAVE SOURCE** button.
6. You will be taken to the **Sync Required Tables & Columns** page where you can select the tables and columns you would like to sync with Zenskar.

Each individual sheet in a Google Sheets spreadsheet is treated as a separate table in Zenskar's database.

<Image align="center" className="border" border={true} src="https://files.readme.io/5903d95-image.png" />

You can choose which sheet to sync with Zenskar.

<Image align="center" className="border" border={true} src="https://files.readme.io/7f1fc84-image.png" />

All columns within a sheet are treated as columns in corresponding tables in the destination database.

<Image align="center" className="border" border={true} src="https://files.readme.io/b2e13cb-image.png" />

You can choose which columns to sync with Zenskar.

<Image align="center" className="border" width="50% " border={true} src="https://files.readme.io/cda85de-image.png" />

7. Click on the **FINISH SETUP** button.
