# Google Sheets

## Authentication

Follow the steps below to create a service account for your Google Cloud project and share your Google sheet through the \*\*\*\* service account key.

### Create a service account key

Follow the steps below:

1. Enable the [Google Sheets API](https://console.cloud.google.com/apis/library/sheets.googleapis.com) of your Google Cloud project.
2. Select **APIs & Services** > **Credentials** from the left panel.
3. Click **+ CREAT CREDENTIALS** > **Service account** to create a new service account.

   <figure><img src="https://125370873-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FzdpN2Lz0hzXpnNScDzVt%2Fuploads%2Fgit-blob-6dac4aa73857f4f230558cc15310144e2b378c84%2FGoogle-sheets-account.gif?alt=media" alt=""><figcaption></figcaption></figure>
4. Get a service account key:

   1. Click the **Email** of the service account.
   2. Click **KEYS** > **ADD KEY** > **Create new key**.
   3. Select **JSON** as the key type.
   4. Click **CREATE** to download it.

   <figure><img src="https://125370873-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FzdpN2Lz0hzXpnNScDzVt%2Fuploads%2Fgit-blob-dbb4bdbd5a9baf277c95bf08bd104cfce8dad25a%2FGoogle-sheets-key.gif?alt=media" alt=""><figcaption></figcaption></figure>

{% hint style="success" %}
Now the service account key, in a JSON format, is downloaded to your device. Make sure to keep it somewhere safe.
{% endhint %}

### Share your Google sheet

Navigate back to to [Google Sheets](https://docs.google.com/spreadsheets), and follow the steps below to share your sheet through the \*\*\*\* service account key.

1. Open the JSON file of the key.
2. Copy the value of `client_email`, which is an identity used for access management of your sheet.

   <figure><img src="https://125370873-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FzdpN2Lz0hzXpnNScDzVt%2Fuploads%2Fgit-blob-d575554047e4053cd9d0f90bf8d5f71b221ccdb2%2FGoogle-sheets-key-client-email.jpeg?alt=media" alt=""><figcaption></figcaption></figure>
3. Click **Share** at the top right and paste the copied `client_email` value to add a member with access.

   <figure><img src="https://125370873-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FzdpN2Lz0hzXpnNScDzVt%2Fuploads%2Fgit-blob-8e49a80c14509c95b422d9ff6c8fb4826f6f569f%2FGoogle-sheets-share.jpg?alt=media" alt=""><figcaption></figcaption></figure>
4. Select **Editor** as the role and click **Send**.

   <figure><img src="https://125370873-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FzdpN2Lz0hzXpnNScDzVt%2Fuploads%2Fgit-blob-54402503941e51cad8147149cdd8bb4b4fbb0f06%2FGoogle-sheets-send.jpg?alt=media" alt=""><figcaption></figcaption></figure>

{% hint style="success" %}
When you see the notification **Access updated**, you have authorized this service account to edit your sheet.
{% endhint %}

## Connect Google Sheets to Appizap

Follow the steps below:

<figure><img src="https://125370873-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FzdpN2Lz0hzXpnNScDzVt%2Fuploads%2FGJTlcYxMYQuiwBGZ5i7r%2FConnectNewDataSourceOverview.gif?alt=media&#x26;token=51b6e26e-59fd-4e2e-ab3f-2c10b4d53bb6" alt=""><figcaption></figcaption></figure>

1. Click **Data Sources** on Appizap homepage.
2. Click **New Data Source** on the top right. Note that this permission is restricted to workspace admins and developers.
3. Select **Database** > **Google Sheets** as the type.<br>

   <figure><img src="https://125370873-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FzdpN2Lz0hzXpnNScDzVt%2Fuploads%2F52K96BTBSjsRq4y3Hs7i%2Fimage.png?alt=media&#x26;token=38a9beb3-0898-4842-ba49-378be73a1768" alt=""><figcaption></figcaption></figure>
4. Set its name and paste the whole content in the JSON flie of the key to **Service Account**.<br>

   <figure><img src="https://125370873-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FzdpN2Lz0hzXpnNScDzVt%2Fuploads%2FriF2wU4PGEsaMgphQSgE%2Fimage.png?alt=media&#x26;token=411095ae-8379-4e53-86a1-37330fcc264e" alt=""><figcaption></figcaption></figure>
5. Click **Save**, and you can check it in your data source library later.
6. To access and manipulate data in your app, you can fill in the **Spreadsheet** id and **Sheet Name** in a query editor as follows.

   <figure><img src="https://github.com/nighthack/Appizap-Docs/blob/main/.gitbook/assets/image%20(31)%20(1)%20(1)%20(1)%20.png" alt=""><figcaption></figcaption></figure>

   <figure><img src="https://github.com/nighthack/Appizap-Docs/blob/main/.gitbook/assets/image%20(13)%20(1)%20(1)%20(1)%20(1)%20(1)" alt=""><figcaption></figcaption></figure>

   The available methods are **Read Data**, **Append Row**, **Update Row**, and **Clear Row**.
