Shopify merchants often rely on Google Sheets to manage products, analyze sales, and track inventory. Manually exporting and importing data, however, is inefficient and error-prone. The more innovative approach is to connect Shopify with Google Sheets via APIs, allowing data to sync automatically in real time.
This tutorial explains how to integrate the Google Sheets API with the Shopify Admin API using OAuth 2.0, enabling a secure, automated data flow between the two platforms. We’ll cover authorization, token handling, and a sample sync script built with Node.js.
1. What This Integration Does.
By integrating Google Sheets and Shopify, you can:
- Pull product or order data from Shopify directly into a sheet.
- Update product inventory or pricing in sheets and push back to Shopify
- Automate reporting, stock tracking, or adjustments.
Example workflow: When a new order is placed in Shopify, your connected Google Sheet automatically logs the customer details, product SKUs, and total revenue — no manual entry required.
2. Understanding O Auth 2.0
Both Shopify and Google require OAuth 2.0 for secure success.
OAuth allows your app to act on behalf of user without storing their password.
The process works like this:
- The user authorizes your app through a consent screen.
- You receive an authorization code.
- Your server exchanges that code for an access token and refresh token.
- You use the access token to call APIs securely.
3. Prerequisites
Before you strat coding you need to:
- A Shopify Partner account (to create a custom app).
- Access to your store’s Admin API credentials.
- A Google Cloud project with Sheets API enabled.
- A Node.js environment with
axios,express, andGoogleapisinstalled.
4. Setting Up Shopify Credentials
- 1. In Shopify Admin → Settings → Apps → Develop Apps.
- 2.Create a new app → Enable Admin API Access → Select required scopes (
like read_products, write_products). - 3. Install the app in your store and note your Admin API access token and API key.
- 4. You’ll use this token later when pushing data back to Shopify.
5. Setting up Google Sheets OAuth credentials
- Visit the Google Cloud Console
- Create a new project → Enable Google Sheets API and Google Drive API.
- Under “Credentials,” create an OAuth 2.0 Client ID and download the JSON file.
- This file contains your client ID, secret, and redirect URIs.
6. Installing Dependencies
Run the following commands in your Node.js project directory:
npm init -y
npm install express axios googleapis dotenv
Add your credentials to a .envfile:
SHOPIFY_STORE=myshop.myshopify.com
SHOPIFY_ACCESS_TOKEN=shpat_xxxxx
GOOGLE_CLIENT_ID=your_client_id
GOOGLE_CLIENT_SECRET=your_client_secret
GOOGLE_REDIRECT_URI=http://localhost:3000/oauth2callback
7. Implementing Google OAuth Flow
import express from "express";
import { google } from "googleapis";
import dotenv from "dotenv";
dotenv.config();
const app = express();
const oauth2Client = new google.auth.OAuth2(
process.env.GOOGLE_CLIENT_ID,
process.env.GOOGLE_CLIENT_SECRET,
process.env.GOOGLE_REDIRECT_URI
);
// Step 1: Redirect user to Google’s consent screen
app.get("/auth", (req, res) => {
const url = oauth2Client.generateAuthUrl({
access_type: "offline",
scope: ["https://www.googleapis.com/auth/spreadsheets", "https://www.googleapis.com/auth/drive.file"],
});
res.redirect(url);
});
// Step 2: Handle callback and get tokens
app.get("/oauth2callback", async (req, res) => {
const { code } = req.query;
const { tokens } = await oauth2Client.getToken(code);
oauth2Client.setCredentials(tokens);
res.send("Google Sheets connected successfully!");
});
app.listen(3000, () => console.log("Server running on http://localhost:3000"));
8. Reading Data from Shopify and Writing to Google Sheets
Now, let’s sync product data from Shopify to a Google Sheet.
import axios from "axios";
const SHEET_ID = "your_google_sheet_id_here";
async function syncProducts() {
try {
// 1. Fetch products from Shopify
const shopifyResponse = await axios.get(
`https://${process.env.SHOPIFY_STORE}/admin/api/2024-10/products.json?limit=5`,
{
headers: {
"X-Shopify-Access-Token": process.env.SHOPIFY_ACCESS_TOKEN,
"Content-Type": "application/json",
},
}
);
const products = shopifyResponse.data.products.map((p) => [p.id, p.title, p.variants[0].price]);
// 2. Write data to Google Sheet
const sheets = google.sheets({ version: "v4", auth: oauth2Client });
await sheets.spreadsheets.values.update({
spreadsheetId: SHEET_ID,
range: "Sheet1!A1",
valueInputOption: "RAW",
requestBody: { values: [["ID", "Title", "Price"], ...products] },
});
console.log("Products synced to Google Sheets successfully!");
} catch (error) {
console.error("Sync failed:", error.message);
}
}
Run this function after successful Google OAuth authorization.
You’ll see Shopify product details appear instantly inside your connected Google Sheet.
9. Handling Errors Gracefully
Always handle failed requests, rate limits, or expired tokens.
Best Practices:
- Retry failed requests with exponential backoff.
- Refresh Google OAuth tokens automatically using the refresh_token.
- Use queues (like BullMQ or Celery) for large data syncs.
- Log all API interactions for debugging and recovery.
Proper error handling ensures smooth synchronization and prevents data loss during API outages or connection drops.
10. When to Involve Professionals
If your integration involves complex data structures, multiple stores, or enterprise ERPs, it’s smart to work with expert Shopify developers.
They can help you design secure middleware layers, implement advanced OAuth logic, and optimize API performance for high-volume use cases.
For large-scale implementations or headless commerce architectures, partnering with a certified Shopify Partner Agency ensures reliability, compliance, and scalability. They’re experienced in connecting Shopify with CRMs, ERPs, accounting platforms, and third-party analytics systems using secure API pipelines.
11. Conclusion
Integrating the Google Sheets API with Shopify using OAuth 2.0 unlocks automation and data transparency. You can build dynamic reports, manage product data seamlessly, and eliminate manual CSV exports forever.
With OAuth, your integration remains secure and scalable, supporting automatic token refresh and controlled data access.
Whether you’re a developer automating product sync or a merchant wanting live dashboards, this connection creates endless possibilities for workflow automation and business insights.
Top comments (0)