Mechanic
📣 Shopify REST Deprecation
  • ⛩️Introduction
  • 🤓Hire a Mechanic developer
  • 💯status.mechanic.dev
  • 📣Shopify is deprecating the REST API
  • 🙋"I need something custom!"
  • 🧑‍💻"I need help with my custom task!"
  • 🤖"I need help with my AI-written task!"
  • Resources
    • ⬇️Install Mechanic
    • 🧑‍💻Task library
      • Contributing
      • Requesting
    • 🚀Slack community
    • 🤝Partner directory
    • 🧠Tutorials
      • Video walkthroughs
        • Auto-tag orders by originating staff member
        • Maintain a tag for orders processed today
        • Auto-tag orders with their tracking numbers
        • Sync inventory for shared SKUs
        • Auto-tag products when their SKU(s) change
        • Auto-publish new products
        • Email a report of customers who haven't ordered in X days
        • Upgrading a Mechanic task: Adding a time delay
        • Email the customer when tracking numbers are added to their order
        • Adding an optional time delay to your Mechanic task
        • Delete all orders
        • Send an email when a specific product is shipped
        • Send recurring reminders about unpaid orders
        • Send an email when a product's price goes below its cost
        • Auto-tag customers by sales channel
        • Creating products in bulk
      • Creating a Mechanic webhook
      • Practicing writing tasks
      • Triggering tasks from a contact form
      • Creating scheduled CSV feeds
      • Fetching data from a shared Google sheet
    • 🏆Converting tasks from Shopify REST to GraphQL
      • Conversion: Single resource lookups
      • Conversion: Resource loops to paginated queries
      • Conversion: Connections from a resource
      • Conversion: Metafield lookups from a resource
      • Conversion: Resource lookups in task option fields
  • Core Concepts
    • Events
      • Topics
      • Parent and child events
    • Tasks
      • Subscriptions
      • Code
        • Environment variables
        • Action objects
        • Error objects
        • Log objects
      • Options
        • Custom validation
      • Previews
        • Defining preview events
        • Stub data
      • Shopify API version
      • Advanced settings
        • Documentation
        • JavaScript
        • Perform action runs in sequence
      • Import and export
      • User Form
    • Actions
      • Cache
      • Echo
      • Email
      • Event
      • Files
      • Flow
      • FTP
      • Google Drive
      • Google Sheets
      • HTTP
      • Integrations
        • Report Toaster
      • Shopify
      • File generators
        • Base64
        • PDF
        • Plaintext
        • URL
        • ZIP
    • Runs
      • Scheduling
      • Concurrency
      • Ordering
      • Retries
    • Interacting with Shopify
      • Responding to events
        • Reconciling missing events
      • Reading data
        • ⚠️Liquid objects
        • 🏆GraphQL in Liquid
        • Bulk operations
        • The Shopify action
      • Writing data
      • Shopify admin action links
      • API rate limit
      • API versions
  • Platform
    • 🔆Policies
      • Data
      • Plans
      • Pricing
      • Privacy
    • Cache
      • Cache endpoints
    • Email
      • Receiving email
      • Custom email addresses
      • DMARC
      • Email templates
    • Error handling
    • Events
      • Event topics
      • Event filters
    • GraphQL
      • Basics
        • Shopify Admin API GraphiQL explorer
        • Queries
        • Mutations
        • Pagination
      • Bulk operations
    • Integrations
      • Appstle Subscriptions
      • Google Drive and Google Sheets
      • Judge.me
      • Locksmith
      • Report Toaster
      • Shopify Flow
      • Run links
    • Liquid
      • Basics
        • Syntax
        • Data types
        • Variables
        • Comments
        • Filters
        • Operators
        • Control flow
          • Condition
          • Iteration
        • Whitespace
      • Liquid console
      • Mechanic filters
        • Deprecated filters
      • Mechanic keyword literals
        • array
        • hash
        • newline
      • Mechanic objects
        • Action object
        • Cache object
        • Event object
        • Options object
        • Task object
        • ⚠️Shopify REST Admin API
          • 🚫Article object
          • 🚫Blog object
          • 🚫Collection object
          • 🚫Customer object
          • 🚫Discount code object
          • 🚫Dispute object
          • 🚫Draft order object
          • 🚫Fulfillment object
          • 🚫Fulfillment order object
          • 🚫Fulfillment event object
          • 🚫Gift card object
          • 🚫Inventory item object
          • 🚫Inventory level object
          • 🚫Line item object
          • 🚫Location object
          • 🚫Metafields
            • Metafield object
            • Metafield representation object
            • Metafield collection object
          • 🚫Order object
          • 🚫Order risk object
          • 🚫Price rule object
          • 🚫Product object
          • 🚫Product image object
          • 🚫Refund object
          • 🚫Shipping zone object
          • 🚫Shop object
          • 🚫Theme object
          • 🚫Theme asset object
          • 🚫Transaction object
          • 🚫Variant object
      • Mechanic tags
        • liquid
        • action
        • assign
        • error
        • log
      • Mechanic code snippets
    • Shopify
      • Custom authentication
      • "Read all orders"
    • Webhooks
  • Techniques
    • Preventing action loops
    • Writing a high-quality task
    • Tagging Shopify resources
    • Debouncing events
    • Responding to action results
    • Working with external APIs
      • JSON Web Signatures
      • AWS request signatures
    • Finding a resource ID
    • Migrating templates from Shopify to Mechanic
    • Securing Mechanic webhooks
    • Monitoring Mechanic
  • FAQ
    • The app isn't loading. What do I do?
    • How do I stop a large batch of runs?
    • A Shopify event is missing. Where is it?
    • Does Mechanic have an affiliate program?
    • Can non-owners install Mechanic?
    • Can I replace Shopify's order emails with Mechanic?
    • Can I manually set Shopify permissions for Mechanic?
    • Does my theme need to be updated for Mechanic?
    • Do you have a plan for development stores?
    • Why don't I see any events in my task's activity?
    • Can I read data back from my webhook submission?
    • My task added a tag, but now the tag is missing – why?
    • How do I add an unsubscribe link to my emails?
    • How do I send images with my emails?
    • Can I re-send order confirmation emails with Mechanic?
    • Why am I seeing a different price than on the app store?
    • Do you have a Partner-friendly plan?
    • Why are my tasks delayed or not running?
    • My task is failing because of a permissions problem. Why?
    • How do I preview email attachments?
    • Can I query external APIs?
    • Why can't I access the Shopify API during preview mode?
    • How do marketing preferences work with Mechanic?
    • Can I send data to Google Sheets?
    • What's possible with timeline comments?
    • I'm getting a "query param length is too long" error when using GraphQL.
    • Can my Mechanic concurrency limit be raised?
    • What IP address does Mechanic use?
    • Can Mechanic read or manage customer subscriptions?
    • Why is everything harder now?
    • Can task content be translated into multiple languages?
    • Can I add a time delay to my task?
    • Can I add another store to my existing Mechanic subscription?
    • How can I reduce memory usage of my task?
    • How do I connect PayPal to Shopify with Mechanic?
    • How do I add a Shopify access scope to my task?
    • Can I have my Mechanic data retained for more (or less) than 15 days?
Powered by GitBook

Important Updates

  • 📣 Shopify REST Deprecation
On this page
  • Options
  • Operations
  • append_rows
  • create_spreadsheet
  • export_spreadsheet
  • Authentication
  • File Access
  • Folder Support
  • Folder Path Examples
  • Examples
  • Append Rows to Existing Google Sheet
  • Create New Google Sheet
  • Export Google Sheet
  • Dynamic Data Example
  • Create Google Sheet in a Folder
  • Read Data From Google Sheet
  • Action Responses
  • append_rows Response
  • Example:

Was this helpful?

Edit on GitHub
Export as PDF
  1. Core Concepts
  2. Actions

Google Sheets

PreviousGoogle DriveNextHTTP

Last updated 3 months ago

Was this helpful?

The Google Sheets action allows you to interact with Google Sheets. It supports creating new spreadsheets, appending data to existing sheets, and exporting spreadsheets in various formats. Mechanic interacts with Google Sheets via the Google Sheets API, using OAuth2 for authentication.

Due to Google security restrictions, Mechanic can only access spreadsheets that were created through Mechanic itself. To work with Google Sheets:

  • First create a spreadsheet using the "create_spreadsheet" operation

  • Store the returned spreadsheet ID for later use

  • Then use operations like "append_rows" on this spreadsheet

See this great in the task library.

Options

Option
Type
Description

account

string

Required: the Google account email address to authenticate with

operation

string

Required: the operation to perform. One of: "append_rows", "create_spreadsheet", "export_spreadsheet"

spreadsheet_id

string

Required: for append_rows and export_spreadsheet; the ID of the target spreadsheet

title

string

Required: for create_spreadsheet; the title for the new spreadsheet

rows

array

Required: for append_rows and optional for create_spreadsheet; array of arrays containing the data to write

sheet_name

string

Optional: for append_rows; defaults to "Sheet1"

file_type

string

Optional: for export_spreadsheet; the format to export. One of: "xlsx" (default), "csv", "pdf", "html", "ods", "tsv"

folder_path

string

Optional: for create_spreadsheet; the folder path where the spreadsheet should be created (e.g., "reports/2024/monthly")

Operations

append_rows

Adds new rows to an existing spreadsheet.

Required Options

  • account

  • spreadsheet_id

  • rows

Optional Options

  • sheet_name (defaults to "Sheet1")

create_spreadsheet

Creates a new spreadsheet, optionally with initial data.

Required Options

  • account

  • title

Optional Options

  • folder_path (path where spreadsheet should be created)

  • rows (initial data to populate the spreadsheet)

export_spreadsheet

Exports a spreadsheet in various formats.

Required Options

  • account

  • spreadsheet_id

Optional Options

  • file_type

    • xlsx (default)

    • csv

    • pdf

    • html

    • ods

    • tsv

Authentication

This action requires connecting a Google account with the appropriate permissions. To connect an account:

  1. Go to the Settings screen

  2. Click Authentication

  3. Follow the Google account connection flow

File Access

The action can only access spreadsheets it creates, no other spreadsheets in your drive.

Folder Support

When creating spreadsheets, you can specify a folder path to organize your files:

  • Use forward slashes to separate folder names (e.g., "reports/2024/monthly")

  • Folders will be created if they don't exist

  • Can only access folders created by this integration

  • Invalid characters not allowed: < > : " / \ | ? *

Folder Path Examples

reports/monthly           # Two levels deep
data/2024/q1/sales       # Four levels deep
archives/exports/sheets   # Three levels deep

Examples

Append Rows to Existing Google Sheet

{% action "google_sheets" %}
  {
    "account": "user@example.com",
    "operation": "append_rows",
    "spreadsheet_id": "1234567890abcdef",
    "sheet_name": "Orders",
    "rows": [
      ["Order ID", "Customer", "Total"],
      ["1001", "John Doe", "99.99"],
      ["1002", "Jane Smith", "149.99"]
    ]
  }
{% endaction %}

Create New Google Sheet

{% action "google_sheets" %}
  {
    "account": "user@example.com",
    "operation": "create_spreadsheet",
    "title": "Monthly Sales Report",
    "rows": [
      ["Month", "Revenue", "Expenses", "Profit"],
      ["January", "5000", "3000", "2000"],
      ["February", "5500", "3200", "2300"]
    ]
  }
{% endaction %}

Export Google Sheet

{% action "google_sheets" %}
  {
    "account": "user@example.com",
    "operation": "export_spreadsheet",
    "spreadsheet_id": "1234567890abcdef",
    "file_type": "pdf"
  }
{% endaction %}

Dynamic Data Example

{% assign order_rows = array %}
{% assign header_row = array %}
{% assign header_row["Order", "Customer", "Total"] %}
{% assign order_rows[header_row] %}

{% for order in shop.orders %}
  {% assign order_row = array %}
  {% assign order_row[order.name, order.customer.name, order.total_price] %}
  {% assign order_rows[order_row] %}
{% endfor %}

{% action "google_sheets" %}
  {
    "account": {{ options.google_account | json }},
    "operation": "append_rows",
    "spreadsheet_id": {{ options.spreadsheet_id | json }},
    "rows": {{ order_rows | json }}
  }
{% endaction %}

Create Google Sheet in a Folder

{% action "google_sheets" %}
  {
    "account": "user@example.com",
    "operation": "create_spreadsheet",
    "folder_path": "reports/2024/monthly",
    "title": "March Sales",
    "rows": [
      ["Date", "Revenue", "Units"],
      ["2024-03-01", "5000", "50"],
      ["2024-03-02", "6000", "60"]
    ]
  }
{% endaction %}

Read Data From Google Sheet

Task subscriptions
mechanic/user/trigger
mechanic/actions/perform
Task code
{% if event.topic == "mechanic/user/trigger" %}
  {% action "google_sheets" %}
    {
      "account": {{ options.google_account__required | json }},
      "operation": "export_spreadsheet",
      "spreadsheet_id":  {{ options.spreadsheet_id__required | json }},
      "file_type": "csv"    
    }
  {% endaction %}
{% endif %}

{% if event.topic == "mechanic/actions/perform" %}
  {% if action.type == "google_sheets" and action.run.ok %}
    {% assign sheet_data = action.run.result.data_base64 | 
    base64_decode | parse_csv: headers: true %}
      {% action "echo" sheet_data %}
  {% endif %}
{% endif %}

Action Responses

The action returns different responses based on the operation performed:

append_rows Response

{
  "spreadsheet_id": string,
  "updated_range": string,
  "updated_rows": number,
  "updated_columns": number,
  "spreadsheet_url": string
}

Example:

{
  "spreadsheet_id": "1234567890abcdef",
  "updated_range": "Sheet1!A1:C3",
  "updated_rows": 3,
  "updated_columns": 3,
  "spreadsheet_url": "https://docs.google.com/spreadsheets/d/1234567890abcdef"
}

create_spreadsheet Response

{
  "spreadsheet_id": string,
  "spreadsheet_url": string,
  "title": string
}

Example:

{
  "spreadsheet_id": "1234567890abcdef",
  "spreadsheet_url": "https://docs.google.com/spreadsheets/d/1234567890abcdef",
  "title": "Monthly Sales Report"
}

create_spreadsheet Response with Folder

{
  "spreadsheet_id": string,
  "spreadsheet_url": string,
  "title": string,
  "folder_path": string
}

Example:

{
  "spreadsheet_id": "1234567890abcdef",
  "spreadsheet_url": "https://docs.google.com/spreadsheets/d/1234567890abcdef",
  "title": "March Sales",
  "folder_path": "reports/2024/monthly"
}

export_spreadsheet Response

{
  "spreadsheet_id": string,
  "name": string,
  "size": number,
  "file_type": string,
  "data_base64": string
}

Example:

{
  "spreadsheet_id": "1234567890abcdef",
  "name": "Monthly Sales Report",
  "size": 12345,
  "file_type": "pdf",
  "data_base64": "base64encodeddata..."
}

example