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

# Google Sheets integration

> Append one Google Sheets row per completed call: TL;DR, summary, next steps, caller number, or AMD verdict. Service-account auth, five-minute setup.

The Google Sheets integration appends one row to your spreadsheet per
completed call. Recap events carry the summary fields; AMD events carry the
verdict fields, so one tab becomes the call log your team actually opens.

## What you need

* A **Google Cloud service account** with a JSON key:
  1. In [console.cloud.google.com](https://console.cloud.google.com), open or
     create a project.
  2. **APIs & Services → Library** → enable the **Google Sheets API**.
  3. **APIs & Services → Credentials → Create Credentials → Service
     Account**, name it (for example, `pyai-call-log`).
  4. Open the service account → **Keys → Add Key → Create new key → JSON** →
     download.
* **Share your spreadsheet with the service account's email as an Editor**
  (the `client_email` in the JSON, like
  `pyai-call-log@project.iam.gserviceaccount.com`). Rows cannot append
  without this share.
* The **spreadsheet id** from the URL (`/d/<this-part>/edit`) and the **tab
  name** (for example, `Sheet1`).

## Connect

1. In PyAI Console, open **Integrations** and find **Google Sheets** under
   Automation.
2. Click **Connect**, paste the full JSON key, the spreadsheet id, and the
   tab name, and pick your events.
3. Press **Test**. A sample row lands in the tab.
4. Done. Rows append from the next completed call.

## What lands

One row per call, with these columns in order:

| Recap events                                                                                 | AMD events                                                                                                                  |
| -------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------- |
| event, occurred\_at, call\_id, status, pack\_id, tldr, summary, next\_steps, customer\_phone | event, occurred\_at, call\_id, status, answered\_by, answered\_by\_twilio, confidence, decision\_ms, reason, session\_label |

## Troubleshooting

* **Error: The caller does not have permission.** The sheet is not shared
  with the service account's email, or it is shared as Viewer. Share as
  **Editor** and press Test again.
* **Error: Unable to parse range.** The tab name is wrong or was renamed.
  Update the connection with the current tab name (stored credentials are
  preserved).
* **Error: invalid\_grant / private key error.** The JSON key was deleted or
  the paste was truncated. Create a fresh key in Google Cloud and paste the
  whole file again.
* **Revoking access later.** Unshare the sheet or delete the JSON key in
  Google Cloud; deliveries fail visibly and stop, and disconnecting the
  integration in PyAI deletes the stored key.
