In this guide, we'll walk you through the process of setting up a Cloudhooks integration that automatically updates a Google Sheet with new Shopify order data.
In this series, we'll show you how to integrate Cloudhooks with popular SaaS products.
The first product in the series is Google Sheets - many Shopify store owners want to integrate with Sheets.
We'll cover the use case of how to append a row with customer and purchase data to a sheet for every order.
The sheet will have four columns: name, email, purchase date, and gross purchase amount.
Before we jump into the implementation, it's important to understand the different ways we can interact with Google Sheets.
Google Sheets offers a client-side javascript API, an Apps Script API, and a server-to-server integration.
Cloudhooks runs hooks on the server side, so it can't use the client-side Google Sheets javascript API. The server-to-server Google Sheets API requires OAuth, but we'd like to keep the integration simple. This leaves us with the Google Apps Script integration, which is surprisingly easy.
Having explored our options, let's focus on the most suitable approach for our needs: using Google Apps Script.
Did you know that a Google Apps Script can act as an API endpoint to receive HTTP GET or POST requests? It can also take advantage of Sheets’ client-side API which will make our job really simple.
Our integration will look like this:
With our strategy in place, it's time to roll up our sleeves and start building our integration.
Open Google Sheets and create a new spreadsheet. Name the first sheet “Orders”, and add name, email, date, and gross amount columns:
Take note of the spreadsheet ID found in the document URL (it’s the selection on the screenshot):
In your spreadsheet:
Replace the contents of the script editor with this code:
Replace the spreadsheet id constant with a real value, and create an API key with random alphanumeric characters.
Note that the API key is sent as a query parameter, so using special characters might cause unwanted side effects.
Now that we have our script ready, the next step is to make it accessible as a web app so Cloudhooks can send data to it.
Deploy the script to receive requests by following these steps:
Click “Authorize access” to grant access to the script to your spreadsheet.
Copy the web app URL from the deployment screen:
With our Google Apps Script deployed, we're ready to configure Cloudhooks to send data to our new endpoint.
Create a new hook for the “Order created” event in your Cloudhooks dashboard.
Paste the following code in the “Hook” tab:
Replace the constants for the API key and the deployed script URL.
Our setup is complete, but before we celebrate, let's make sure everything is working as expected.
You can perform end-to-end testing in Cloudhooks. Open your hook, go to the “Hook” tab, and press the “Run test” button:
If your integration works, then:
Congratulations! You've successfully integrated Cloudhooks with Google Sheets to automatically track Shopify orders. This powerful combination allows you to:
Remember, this is just one example of how Cloudhooks can enhance your e-commerce operations. As you become more comfortable with the platform, you can explore additional integrations and automations to further streamline your business processes.
While the integration we've built is functional, there are always ways to enhance security and efficiency. Here are some suggestions for improvement:
It's crucial to keep your API key secret and never share it publicly. For production use, consider implementing a more secure method of storing and accessing your API key. One excellent option is to use Google Secret Manager.
Google Secret Manager offers several benefits for managing sensitive information like API keys:
To use Google Secret Manager with your Google Apps Script:
This Stack Exchange article provides a detailed explanation of how to access Secret Manager from Google Apps Script.
As your integration needs grow and evolve, continually reassess and improve your security measures to protect your data and your customers' information.