# Send Data to Google Sheets

Append Flux events to Google Sheets using a service account and webhook action.

## Introduction

The [Soracom Flux Webhook Action](https://docs.soracom.io/en/services/flux/webhook) supports Google Service Account authentication, which lets Flux automatically obtain an OAuth 2.0 access token before sending the request. With this authentication method, you can call Google APIs such as the Google Sheets API or the BigQuery API directly from your Flux app.

This guide walks you through configuring a Flux app that uses the [API/Manual Execution Event Source](https://docs.soracom.io/en/services/flux/api) to append a row to a Google Sheets spreadsheet whenever a request is sent to the channel endpoint.

> [!WARNING]
>
> Refer to the [Pricing & Fee Schedule](https://docs.soracom.io/en/pricing#soracom-flux) for detailed information on Soracom Flux pricing. Soracom Flux includes a free tier providing limited usage for certain features at no cost.

## Requirements

For this project, you will need the following:

- A Soracom account
  - If you don't already have a Soracom account, follow the steps in the [Quick Start guide](https://docs.soracom.io/en/guides/quick-start).
- A Google Cloud project with permission to create a service account and enable APIs.
- A Google Sheets spreadsheet that you can share with the service account.

## Step 1: Create a Service Account in Google Cloud and Grant Permissions

To allow the Flux Webhook Action to call the Google Sheets API in your Google Cloud project, create a service account, download its JSON key, and grant the service account access to the target Google Sheets spreadsheet.

### Enable the Google Sheets API

In the [Google Cloud Console](https://console.cloud.google.com/), select the project in which you want to create the service account, and enable the [Google Sheets API](https://console.cloud.google.com/apis/library/sheets.googleapis.com).

> [!WARNING]
>
> To use other Google APIs (such as BigQuery or Drive), enable each API individually.

### Create the Service Account

In [IAM & Admin → Service Accounts](https://console.cloud.google.com/iam-admin/serviceaccounts), click **Create service account** and configure the following:

- **Service account name**: Enter any name, for example `flux-sheets-integration`.
- **Service account ID**: Leave the auto-generated value as is.
- **Service account description**: Describe the intended use of the account.

Click **Create and continue**, skip role assignment, then click **Done**.

The email address of the new service account (e.g., `flux-sheets-integration@<PROJECT_ID>.iam.gserviceaccount.com`) is referred to as `${service_account_email}` from this point onward.

### Create a JSON Key

Open the service account you created, and click **Keys → Add key → Create new key**. Select **JSON** as the key type and click **Create**.

A JSON file is downloaded. The contents of this file are referred to as `${service_account_json}` from this point onward.

> [!NOTE]
>
> The downloaded JSON file is sensitive information. Do not paste it into chat tools, email, or Git repositories. After registering it in Credential Sets, we recommend deleting the local copy.

### Share the Google Sheets Spreadsheet with the Service Account

Open the target Google Sheets spreadsheet and click **Share**. Enter `${service_account_email}`, set the permission to **Editor**, and send. Clear the **Notify people** checkbox.

The `<SPREADSHEET_ID>` from the spreadsheet URL `https://docs.google.com/spreadsheets/d/<SPREADSHEET_ID>/edit` is referred to as `${spreadsheet_id}` from this point onward.

> [!WARNING]
>
> We recommend granting access at the resource level (principle of least privilege) rather than granting project-wide access.

## Step 2: Register the Google Service Account (JSON) Credential Set

To allow Flux to call Google APIs, register the service account JSON key as a Credential Set in the Soracom User Console.

In the **Register credentials** dialog of Credential Sets, configure the following. For instructions on how to open this dialog, refer to [Creating a Credential Set](https://docs.soracom.io/en/services/authentication/credential-sets#creating-a-credential-set).

| Field | Description |
| - | - |
| **Credential set ID** | Enter any descriptive name to identify the credentials, for example `flux-sheets-integration`. |
| **Type** | Select **Google Service Account (JSON credentials)**. |
| **Credentials** | Paste the entire contents of `${service_account_json}` (the JSON file downloaded in Step 1). |

For details on the available fields, refer to [Credential Sets](https://docs.soracom.io/en/services/authentication/credential-sets).

## Step 3: Create a Flux App

A [Flux app](https://docs.soracom.io/en/services/flux) can integrate various forms of inputs and apply sophisticated business logic to achieve desired outcomes.

1. Sign in to the **[User Console](https://console.soracom.io/?coverage_type=g)**. From the **☰ Menu**, expand **Soracom Flux** and select **Flux Apps**.

2. Click **+ Create a new Flux app**.

3. Name the Flux app and provide an optional description, then click **Create**.

   The Flux app will be created and the **Studio** tab in **Soracom Flux Studio** will automatically be displayed.

### Create a Channel

A channel is a Flux [component](https://docs.soracom.io/en/services/flux#components) that connects an event source to actions in your Flux app.

1. Open the **Studio** tab in **Soracom Flux Studio**.

2. Click **+ Create a channel**.

3. Choose **API/Manual Execution** as the [event source](https://docs.soracom.io/en/services/flux#event-source) and click **Next**.

4. Configure the following:

   - **Name**: Name your channel.
   - **Description**: Optionally provide a summary of the channel.

5. Click **Create a new channel**.

6. After confirming that your configuration is correct, click the ✕ to return to the **Studio** tab.

### Create a Webhook Action

This step configures a Webhook action within your Flux app. When triggered, the action calls the Google Sheets API and appends a new row to the target Google Sheets spreadsheet.

> [!WARNING]
>
> For details on the Webhook Action, refer to the [Webhook Action](https://docs.soracom.io/en/services/flux/webhook) reference. For details on the Google Service Account authentication fields, refer to [Auth Type](https://docs.soracom.io/en/services/flux/webhook#config) in the same reference.

1. Click on the channel created in the [previous section](https://docs.soracom.io/en/services/flux/google-sheets/#create-a-channel) to open the configuration dialog, then select the **Actions** tab and click **+ Add Action**.

2. In the **Create a new action** dialog, choose **Webhook** as your action type, then click **OK**.

3. Configure the following:

   - **Name**: Enter an action name.
   - **Description**: Optionally provide a summary.
   - **Enabled**: Set the action to enabled.
   - **Condition**:
     - **Action Condition**: Leave this field blank so that the action executes each time it is called.

4. Configure the following in the **Config** section of the dialog:

   - **HTTP Method**: Select **POST**.

   - **URL**: Enter the Google Sheets API `values.append` endpoint that includes `${spreadsheet_id}` from Step 1:

     ```text
     https://sheets.googleapis.com/v4/spreadsheets/${spreadsheet_id}/values/Sheet1!A1:append?valueInputOption=USER_ENTERED
     ```

     If the tab name in your spreadsheet is not `Sheet1`, replace `Sheet1` with the correct tab name.

   - **Auth Type**: Select **Google Service Account**.

   - **Credentials**: Select the credential set registered in [Step 2](https://docs.soracom.io/en/services/flux/google-sheets/#step-2-register-the-google-service-account-json-credential-set), for example `flux-sheets-integration`.

   - **Scope**: Enter `https://www.googleapis.com/auth/spreadsheets`.

   - **Subject**: Leave blank.

   > [!WARNING]
   >
   > For the list of supported scopes, refer to Google for Developers' OAuth 2.0 Scopes for Google APIs documentation. Set **Subject** only when using Google Workspace domain-wide delegation.

   - **HTTP Headers**: Selecting **application/json** for **HTTP Body** automatically sets `Content-Type: application/json`.

   - **HTTP Body**: Select **application/json** and enter the following:

     ```json
     {
       "majorDimension": "ROWS",
       "values": [
         ["${payload.deviceId}", "${payload.timestamp}", "${payload.temperature}", "${payload.humidity}"]
       ]
     }
     ```

5. Configure the following in the **Output** section of the dialog:

   - **Republish this action output to another channel**: Set republishing to **Disabled**.

6. Click **Create**.

7. After confirming that your configuration is correct, click the ✕ to return to the **Studio** tab.

## Testing

### Send a Message from the API/Manual Execution Channel

1. From the **☰ Menu**, expand **Soracom Flux** and select **Flux Apps**.

2. Select your Flux app for this project.

3. Click on the channel created in the [Create a Channel](https://docs.soracom.io/en/services/flux/google-sheets/#create-a-channel) section to open the configuration dialog and select the **Test** tab.

4. In **Content Type**, select **application/json**, then enter the following in the **Body** field and click **Execute**:

   ```json
   {
     "deviceId": "test-device-001",
     "timestamp": "2026-05-13T11:00:00+09:00",
     "temperature": 25.3,
     "humidity": 60.5
   }
   ```

### Verify That the Row Was Appended in Google Sheets

Open the Google Sheets spreadsheet you shared in [Step 1](https://docs.soracom.io/en/services/flux/google-sheets/#step-1-create-a-service-account-in-google-cloud-and-grant-permissions), and confirm that the `deviceId`, `timestamp`, `temperature`, and `humidity` values from the previous step have been appended as a new row in the target sheet tab.

### Check the Execution History of the Flux App

1. Sign in to the **[User Console](https://console.soracom.io/?coverage_type=g)**. From the **☰ Menu**, expand **Soracom Flux** and select **Flux Apps**.

2. Click on the Flux app you created.

3. Select the **History** tab.

   For each channel, the Message, Context, Input, and Output of the action executed from that channel are displayed. If `updates.updatedRows` in the Webhook Action **Output** is `1`, the row was appended to the Google Sheets spreadsheet successfully.

> [!WARNING]
>
> To learn about detailed logging, see the [View Logs](https://docs.soracom.io/en/services/flux/logs) documentation.
