# Google Sheets (prebuilt connector)

## Description

**Google Sheets** is whatever you want it to be! Retrieve and update data from your sheets as needed.

## API documentation

API documentation for **Google Sheets** (used to build this connector) can be found via the link below:

{% embed url="<https://developers.google.com/sheets/api/guides/concepts>" %}

## Authentication&#x20;

When adding connector instances for **Google Sheets**, the following authentication methods are supported:

* [OAuth 2 (client credentials)](#oauth-2-authorisation-code)

### OAuth 2 (client credentials)

When a user chooses to [add a connector instance](https://doc.wearepatchworks.com/product-documentation/connectors-and-instances/working-with-instances/adding-an-instance) using **OAuth 2 (client credentials)** authentication, the credentials below are required:

<table><thead><tr><th>Credential</th><th data-type="checkbox">Required?</th><th>Notes</th></tr></thead><tbody><tr><td><code>Client ID</code></td><td>true</td><td>Follow the steps detailed <a href="#the-steps">below</a> (your <strong>client ID</strong> is generated in <em>Stage 3</em>).</td></tr><tr><td><code>Client Secret</code></td><td>true</td><td>Follow the steps detailed <a href="#the-steps">below</a> (your <strong>client secret</strong> is generated in <em>Stage 3</em>).</td></tr><tr><td><code>Refresh Token</code></td><td>true</td><td>Follow the steps detailed <a href="#the-steps">below</a> (your <strong>refresh token</strong> is generated in <em>Stage 5</em>).</td></tr></tbody></table>

## Prerequisites

* You must have a Google Workspace account that's part of an organisation.

## The steps

* [Stage 1: Create a Google APIs and services project](#stage-1-create-an-apis-and-services-project)
* [Stage 2: Configure a consent screen](#stage-2-configure-consent-screen)
* [Stage 3: Create OAuth 2.0 credentials](#stage-3-create-oauth-credentials)
* [Stage 4: Apply OAuth 2.0 credentials to your OAuth playground](#stage-4-apply-credentials-in-the-oauth-playground)
* [Stage 5: Obtain a refresh token](#stage-5-obtain-a-refresh-token)

### Stage 1: Create a Google APIs and services project

**Step 1**\
Access the [Google APIs console - APIs and Services](https://console.cloud.google.com/apis/dashboard).

**Step 2**\
If you haven't got an account already, go ahead and create one (use the Google account associated with the sheets you want to access).

**Step 3**\
Click the **create project** button.

<div align="left"><figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2Fxf4dCxXgwTwVNMEOVS9k%2Fgoogle%20sheets%201.png?alt=media&#x26;token=0f4f8864-1721-4f57-82a3-9bcf9ed35771" alt=""><figcaption></figcaption></figure></div>

{% hint style="info" %}
If you have existing projects, this page may not be the same. If you can't see a *create project* button, click the dropdown at the top of the page to open the *select a resource* page, then click the *new project* button:

<img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2Ffyua9ZMzcWal7q3c6HBo%2Fgoogle%20sheets%20-%20consent%20screen%20-%201a.png?alt=media&#x26;token=cd85dd3f-c63e-445b-9027-5fa0c0077d18" alt="" data-size="original">
{% endhint %}

**Step 4**\
Enter an appropriate name for this project (leave other settings as they default) and click the **create** button:

<div align="left"><figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2F4HMrYCJBSp7eVJrsWh0a%2Fgoogle%20sheets%202a.png?alt=media&#x26;token=b7bb0179-175a-4562-9673-cdfbb7a34dc2" alt="" width="563"><figcaption></figcaption></figure></div>

### Stage 2: Configure consent screen

**Step 1**\
Select  **OAuth consent screen** from the left-hand navigation menu:

<div align="left"><figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FvK78t9lOd2M9PnEo7IXz%2Fgoogle%20sheets%203.png?alt=media&#x26;token=d06b40e5-8f6b-4d2f-8f3e-8aeac5a6875b" alt=""><figcaption></figcaption></figure></div>

**Step 2**\
Select the **internal** radio button and then click the **create** button:

<div align="left"><figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FyYzqDy2UkTaFMXmkV8Dv%2Fgoogle%20sheets%20-%20consent%20screen%20-%202.png?alt=media&#x26;token=51430591-afd9-4a64-8c0a-bf5ad74038b3" alt="" width="375"><figcaption></figcaption></figure></div>

**Step 3**\
Complete **app information**:

<div align="left"><figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FGRA5zYPgoRZATPqYzZ05%2Fgoogle%20sheets%20-%20consent%20screen%20-%203.png?alt=media&#x26;token=e2a44966-e58c-4bdd-a6a1-a9822de933bb" alt="" width="563"><figcaption></figcaption></figure></div>

The only mandatory fields are:

| Field                           | Summary                                                                 |
| ------------------------------- | ----------------------------------------------------------------------- |
| App name                        | We recommend something clearly identifiable as a Patchworks integration |
| User support email              | Enter your own email address.                                           |
| Developer contact email address | Enter your own email address.                                           |

**Step 4**\
Click **save and continue**.

**Step 5**\
Click the **add or remove scopes** button:

<div align="left"><figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FOlr6Oggeuc6rt2tgocC5%2Fgoogle%20sheets%20-%20consent%20screen%20-%204.png?alt=media&#x26;token=a3834910-3103-4c37-a6a1-664caf073220" alt="" width="563"><figcaption></figcaption></figure></div>

**Step 6**\
Add the following in the **manually add scopes** section:

```
https://www.googleapis.com/auth/spreadsheets
```

...then select **add to table**:

<div align="left"><figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FONdRu2LxtyHra1rKNVyd%2Fgoogle%20sheets%20-%20consent%20screen%20-%205.png?alt=media&#x26;token=5f800ed9-c17f-4305-a6f1-fd011b3bf75c" alt="" width="563"><figcaption></figcaption></figure></div>

**Step 7**\
Click the **update** button at the end of the page:

<div align="left"><figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FWv7ASy2bdZO4o67x4j3b%2Fgoogle%20sheets%20-%20consent%20screen%20-%206.png?alt=media&#x26;token=5346cf45-8e11-434a-aad6-530795b5e703" alt="" width="563"><figcaption></figcaption></figure></div>

**Step 8**\
Check that the new scope has been added under **sensitive scopes**:

<div align="left"><figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2Fh6AL15t3osbbYKcElQ9u%2Fgoogle%20sheets%20-%20consent%20screen%20-%207.png?alt=media&#x26;token=444d8a12-e184-47b2-bc3a-708f5e0f72f7" alt="" width="563"><figcaption></figcaption></figure></div>

**Step 9**\
Click **save and continue** at the end of the page:

<div align="left"><figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FVngG1xbpInLIlWXGRlw2%2Fgoogle%20sheets%20-%20consent%20screen%20-%208.png?alt=media&#x26;token=bf6314a4-019a-45eb-b623-351c773c242c" alt="" width="563"><figcaption></figcaption></figure></div>

### Stage 3: Create OAuth credentials

**Step 1**\
Select **credentials** from the left-hand navigation menu:

<div align="left"><figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FDZDToj1frZaWUbe74hyQ%2Fgoogle%20sheets%20-%20credentials%20-%201.png?alt=media&#x26;token=ce99520b-fae7-4bc1-98f4-1df465133073" alt=""><figcaption></figcaption></figure></div>

**Step 2**\
Click the **create credentials** button:

<div align="left"><figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FRXVznTitu7JIcCVFXoiO%2Fgoogle%20sheets%20-%20credentials%20-%202.png?alt=media&#x26;token=d16e618c-ab91-402b-9e34-9e303ce8ea12" alt=""><figcaption></figcaption></figure></div>

**Step 3**\
Select **OAuth client ID**:

<div align="left"><figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FV2mMzK5puNMl7Mj7zEsb%2Fgoogle%20sheets%20-%20credentials%20-%203.png?alt=media&#x26;token=52a15045-dcf6-44b2-920e-0607d224c75c" alt=""><figcaption></figcaption></figure></div>

**Step 4**\
Select **web application**:

<div align="left"><figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2F2euRC5Aoukyezq3cWhrI%2Fgoogle%20sheets%20-%20credentials%20-%204.png?alt=media&#x26;token=6edfd085-39f4-49a8-8696-8315f24c51e2" alt="" width="563"><figcaption></figcaption></figure></div>

**Step 5**\
Enter a name for this application - we recommend something clearly identifiable as a Patchworks integration, for example `Patchworks Web Client`:

<div align="left"><figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2F6aoHID8sKikZxatQ5nBy%2Fgoogle%20sheets%20-%20credentials%20-%205.png?alt=media&#x26;token=a5e62a76-0a6d-41b9-9fc7-235c463ef2f9" alt="" width="563"><figcaption></figcaption></figure></div>

**Step 6**\
Move down to the **authorised redirect URIs** section and click the **add URI** button:

<div align="left"><figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2F3Md6ZI8xOsWkaKgLGkXd%2Fgoogle%20sheets%20-%20credentials%20-%206.png?alt=media&#x26;token=d92d3c1d-7a17-4941-80fa-c4f91244a1b2" alt="" width="324"><figcaption></figcaption></figure></div>

**Step 7**\
Enter the following URI:

```
https://developers.google.com/oauthplayground
```

**Step 8**\
Click the **create** button:

<div align="left"><figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FDn46v3ir0hVIrDD4iWGU%2Fgoogle%20sheets%20-%20credentials%20-%207.png?alt=media&#x26;token=feac05e8-0a33-466b-95bf-2191eeb69176" alt="" width="563"><figcaption></figcaption></figure></div>

**Step 9**\
Your **client ID** and client secret are displayed - copy these and add them to your password manager so they're available in the next stage (and for later use in Patchworks):

<div align="left"><figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2Ffd45z5vyZmmYwwpXJ2Mv%2Fgoogle%20sheets%20-%20credentials%20-%208.png?alt=media&#x26;token=90836b22-ccd0-4e99-a5ae-11297450971e" alt="" width="563"><figcaption></figcaption></figure></div>

**Step 10**\
Click **OK** to close this window.

### Stage 4: Apply credentials in the OAuth playground

**Step 1**\
In a new browser tab/window, access the following URL to access the **OAuth playground**:

```
https://developers.google.com/oauthplayground
```

**Step 2**\
In the top-right corner, click the 'cog' icon to access **OAuth 2.0 configuration**:

<div align="left"><figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FTIgpNKl7b8vanakrPyPV%2Fgoogle%20sheets%20-%20apply%20auth%201.png?alt=media&#x26;token=7013b9e0-a6a8-4684-9b8e-3f91b8c289fd" alt=""><figcaption></figcaption></figure></div>

**Step 3**\
At the end of the configuration page, select the **use your own OAuth credentials** checkbox:

<div align="left"><figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2F4abouDpDZYA7AVp3D0fF%2Fgoogle%20sheets%20-%20apply%20auth%202.png?alt=media&#x26;token=ae3faa2b-e4d8-4871-81f4-8c8ab71ba370" alt="" width="375"><figcaption></figcaption></figure></div>

**Step 4**\
Add your **client ID** and **client secret** (created in the [previous stage](#stage-3-create-oauth-credentials)) into given fields:&#x20;

<div align="left"><figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FbDdXDY8grhK159GfTxhx%2Fgoogle%20sheets%20-%20apply%20auth%203.png?alt=media&#x26;token=fbcd33fb-5b51-4320-9c34-eddfd7c6ebb0" alt="" width="375"><figcaption></figcaption></figure></div>

**Step 5**\
Close this window.

### Stage 5: Obtain a refresh token

**Step 1**\
Still in the **OAuth playground**, move to the end of the left panel and enter the following URL in the **input your own scopes** field:

```
https://www.googleapis.com/auth/spreadsheets
```

...then click the **authorise APIs** button:

<div align="left"><figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FJZadl8R7ApFrqB2TOXkL%2Fgoogle%20sheets%20-%20auth%20APIs%201.png?alt=media&#x26;token=a52646c3-b264-4e36-a3d8-1d20ccef2f30" alt=""><figcaption></figcaption></figure></div>

**Step 2**\
When prompted, log in with the same Google account that you started with in [Stage 1](#stage-1-create-an-apis-and-services-project):

<figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2Fnj6KUQfRUVUGokQeMXKa%2Fgoogle%20sheets%20-%20auth%20APIs%202.png?alt=media&#x26;token=92bc3ca1-018c-4cee-9e35-14bda27b398a" alt=""><figcaption></figcaption></figure>

...you should see confirmation that your app (in this case named *Patchworks*) has access to Google spreadsheets associated with this account:

<figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FoVVkc000MIlmaPIoPGKl%2Fgoogle%20sheets%20-%20auth%20APIs%203.png?alt=media&#x26;token=16fdcdf7-1b19-444a-afe0-7c5713658496" alt=""><figcaption></figcaption></figure>

**Step 3**\
Click **allow** to continue to the **OAuth 2.0 playground**.

**Step 4**\
Click the **exchange authorization code for tokens** button:

<figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2Ff36GUD7lnNpC30tQhN20%2Fgoogle%20sheets%20-%20auth%20APIs%204.png?alt=media&#x26;token=93e61fd1-d2e0-4f19-a662-a309de03a783" alt=""><figcaption></figcaption></figure>

**Step 5**\
Copy the **refresh token** and add it to your password manager.

### Stage 6: Enable the Google Sheets API

**Step 1**\
Switch back to your [Google APIs console - APIs and Services](https://console.cloud.google.com/apis/dashboard) tab/window and select **enabled APIs and services** from the left-hand navigation menu:

<figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2F1jw7t7g9K56PGiek2tqC%2Fgoogle%20sheets%20-%20enable%20api%201.png?alt=media&#x26;token=23ff01f3-9e4c-4c27-8e22-f4c2a12c3508" alt=""><figcaption></figcaption></figure>

**Step 2**\
Select **enable APIs and Services** at the top of the page:

<figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2F66xbV3Q0UfSDmb8eQ3YQ%2Fgoogle%20sheets%20-%20enable%20api%202.png?alt=media&#x26;token=26e72d64-7632-46e1-98e9-54cbdf07f738" alt=""><figcaption></figcaption></figure>

**Step 3**\
Search for **Google sheets API**:

<div align="left"><figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FRnWDJtrgAHpHsm7iyls8%2Fgoogle%20sheets%20-%20enable%20api%203.png?alt=media&#x26;token=c66c99af-07f7-45a4-a91d-668c5dc866f1" alt="" width="563"><figcaption></figcaption></figure></div>

**Step 4**\
Click the **Google sheets API** result tile:

<div align="left"><figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FvZDdJnKgCwuLyik3loZb%2Fgoogle%20sheets%20-%20enable%20api%204.png?alt=media&#x26;token=e1486e53-1946-4314-9aa3-d5b8bc4d8cf1" alt=""><figcaption></figcaption></figure></div>

**Step 5**\
Click the **enable** button:

<div align="left"><figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FKRBo51heGshVDH9TMOcB%2Fgoogle%20sheets%20-%20enable%20api%205.png?alt=media&#x26;token=434316ad-c02f-4a9e-8fe6-470bf7533a5b" alt="" width="563"><figcaption></figcaption></figure></div>

**Step 6**\
Google Sheets setup is now complete. If you haven't done so already, you can [install the Google Sheets connector from the Patchworks marketplace](https://doc.wearepatchworks.com/product-documentation/connectors-and-instances/working-with-connectors/installing-a-connector) and then use your **client ID**, **client secret**, and **refresh token** to [add required connector instances](https://doc.wearepatchworks.com/product-documentation/connectors-and-instances/working-with-instances/adding-an-instance).


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://doc.wearepatchworks.com/product-documentation/connectors-and-instances/patchworks-connectors/google-sheets-prebuilt-connector.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
