Connector for Google Sheets

Workflows connector that defines the built-in function used to access Google Sheets from within a workflow.

Explore further

For detailed documentation that includes this code sample, see the following:

Code sample

YAML

# This workflow creates, updates, gets, and deletes a Google Sheets spreadsheet
# using the Google Sheets connector.
#
# Features included in this test:
# - Google Sheets connector
#
# Expected successful output: "SUCCESS"
- init:
    assign:
      - createRange: "A20"         # example range
      - getRange: "A1:B4"          # example range
      - row:
          values:
            - {"userEnteredFormat": {"backgroundColor": {"red": 0, "green":1, "blue":0, "alpha":1}}}
      - start1:
          sheetId: 0
          rowIndex: 2
          columnIndex: 0
      - request1:
          rows:
            - ${row}
          fields: userEnteredFormat.backgroundColor
          start: ${start1}
      - driveScope: https://www.googleapis.com/auth/drive
- create_spreadsheet:
    call: googleapis.sheets.v4.spreadsheets.create
    args:
      body:
      connector_params:
        scopes: ${driveScope}
    result: resp
- assign_sheet_id:
    assign:
      - sheetId: ${resp.spreadsheetId}
- update_spreadsheet:
    call: googleapis.sheets.v4.spreadsheets.values.update
    args:
      spreadsheetId: ${sheetId}
      range: ${createRange}
      valueInputOption: RAW
      includeValuesInResponse:
      body:
        values:
          - ["text to update"]
- batch_update:
    call: googleapis.sheets.v4.spreadsheets.batchUpdate
    args:
      spreadsheetId: ${sheetId}
      body:
        requests:
          - updateCells: ${request1}
        includeSpreadsheetInResponse: true
      connector_params:
        scopes: ${driveScope}
- get_from_sheet:
    call: googleapis.sheets.v4.spreadsheets.get
    args:
      spreadsheetId: ${sheetId}
      ranges:
        - ${getRange}
      includeGridData: false
      connector_params:
        scopes: ${driveScope}
- delete_sheet:
    call: http.delete
    args:
      url: ${"https://www.googleapis.com/drive/v2/files/" + sheetId}
      auth:
        type: OAuth2
        scopes: ${driveScope}
- return_step:
    return: SUCCESS

What's next

To search and filter code samples for other Google Cloud products, see the Google Cloud sample browser.