Hey everyone,
I've been on a journey for the past five years to automate my business processes but, like many of us, lack the coding expertise (and budget for hiring a developer) to get it all done. That's where ChatGPT came in—helping me create a Google Apps Script that automates specific catalog data exports from Square right into Google Sheets. Now, I’m sharing what I’ve learned and built with the hope that others can benefit and maybe even join in to improve this tool further!
This project is essentially a Google Sheet with built-in Apps Script that connects directly to Square’s API. All you need is a Square API key from your developer dashboard. The script will pull catalog data into Google Sheets and organize it across columns. It’s something I actively use in my own business, and while it’s still a work-in-progress, it’s saved me hours of manual data handling already.
Make a Copy of the Sheet: Start by making a copy of the Google Sheet provided. From there, you’ll need to insert your API key to enable Square API access.
Understand the Basics of API Keys: This script requires an API key from your Square Developer account. Keep in mind that API keys are powerful and must be protected. If used improperly, they can access a lot of data, so ensure you understand the basics of API security.
Using the Script: The script will pull and populate the following data fields automatically:
Some fields might not be fully functional yet (like advanced custom attributes), but I’m not too focused on those at the moment. Feel free to adjust or contribute if any fields are a priority for you.
How to Use the Square API Menu:
Proceed with Caution: While I’m sharing this tool, please use it responsibly. I’m not responsible if something breaks or if API keys are mishandled. Always test with dummy data if you’re unsure.
This tool is far from perfect and still a bit rough around the edges, so I welcome anyone interested in refining it. I believe that sharing tools like this can empower others to grow their business acumen without needing to rely on expensive development resources.
I’ll paste the code below for review, but please note that I’m not here to troubleshoot individual issues. This is a community project, and I encourage anyone willing to share improvements, additional functionality, or even just feedback.
Happy automating, and looking forward to seeing how others might enhance this!
Thanks to @bryan-square on the developer forums for the assists that got this across the finish line for me to a level where I can being to automate ordering and other regular activities with a headless script that pulls all the details I need to "get started" hopefully I can start to get vendor information next 🙂
V1.0:
Can't paste code here due to length so here is a pastebin: https://pastebin.com/hVncux2e
V1.1:
Logic corrected in is active to account for items that are "active at all future locations" but inactive at some locations: https://pastebin.com/CKN2WAVA
V1.0:
Can't paste code here due to length so here is a pastebin: https://pastebin.com/hVncux2e
V1.1:
Logic corrected in is active to account for items that are "active at all future locations" but inactive at some locations: https://pastebin.com/CKN2WAVA
woah, thanks for this @JTPets!!
I don't know how to tag the correct Brian from the other forum, but he helped me get a couple of last pieces of data that for me made this sheet useable vs fun to play with!
V1.1:
Logic corrected in is active to account for items that are "active at all future locations" but inactive at some locations: https://pastebin.com/CKN2WAVA
My sheet is exporting fine, but my image IDs and URLs are all empty even though in Square I have images on the items. Any suggestions?
Now that you've exported the data using an API call, you might be wondering, 'What’s next?' To keep the data safe from accidental deletions or edits, we’ll move it to a separate document. I've created a new document and set up an Apps Script within it to automatically pull the data into a fresh sheet, formatting it for easy sorting and use.
This script automatically copies data from a "source" Google Sheet to a "target" Google Sheet when the target sheet is opened. It also adds a menu option called "Custom Tools" with a "Refresh Data" button to manually trigger data updates.
Update the Source and Target Sheet IDs:
Sheet Names:
function onOpen() {
const ui = SpreadsheetApp.getUi();
ui.createMenu('Custom Tools')
.addItem('Refresh Data', 'copyData')
.addToUi();
// Automatically run copyData when the sheet is opened
copyData();
}
function copyData() {
// Open the source and target spreadsheets
const sourceSpreadsheet = SpreadsheetApp.openById("SOURCE");
const sourceSheet = sourceSpreadsheet.getSheetByName("API-Export");
const targetSpreadsheet = SpreadsheetApp.openById("DESTINATION");
const targetSheet = targetSpreadsheet.getSheetByName("AutoCatalogUpdate");
// Get the range of data in the source sheet
const sourceRange = sourceSheet.getDataRange();
const sourceValues = sourceRange.getValues();
// Clear the target sheet and paste the values
targetSheet.clearContents();
targetSheet.getRange(1, 1, sourceValues.length, sourceValues[0].length).setValues(sourceValues);
// Freeze the header row
targetSheet.setFrozenRows(1);
// Sort the data by Column C (3rd column) alphabetically, excluding the header
targetSheet.getRange(2, 1, sourceValues.length - 1, sourceValues[0].length).sort({ column: 3, ascending: true });
}
Once I did that I created a ton of simple spreadsheet filters to get automatic updates to formulas for sheets like. Your filters may be different depending on the columns downloaded, but these are simple examples for you to work with:
No URL - could be hidden, deleted, or many reasons
=ARRAYFORMULA({AutoCatalogUpdate!A1:AN1; FILTER(AutoCatalogUpdate!A2:AN, ISBLANK(AutoCatalogUpdate!D2:D))})
No Tax - Items with no tax for audits (all my items should have tax)
=ARRAYFORMULA({AutoCatalogUpdate!A1:AN1; FILTER(AutoCatalogUpdate!A2:AN, ISBLANK(AutoCatalogUpdate!AC2:AC))})
No Categories - Can't sell it if they can't find it
=ARRAYFORMULA({AutoCatalogUpdate!A1:AN1; FILTER(AutoCatalogUpdate!A2:AN, ISBLANK(AutoCatalogUpdate!Y2:Y))})
Negative Inventory - Sold below 0
={ AutoCatalogUpdate!A1:AQ1; FILTER(AutoCatalogUpdate!A2:AQ, (AutoCatalogUpdate!AM2:AM < 0) + (AutoCatalogUpdate!AN2:AN < 0)) }
Others I am working with:
Transfers - for items OOS in 1 location but not another
Order calculator - combines active status, and min stocks to generate order qty
More to come as i move forward with automations....
With a few data points from a normal square catalog export I have no created an auto updating workbook that generates orders and costs automatically I just select a vendor from a drop down:
@alexschiff AI FTW! but this is a feature I would LOVE to see square automate for me as a desktop function, purchase orders based on minimum stock levels, with alerts for items that are out of stock at one or more lcoations (a feature I still need to add)
Awesome job! Thanks for sharing this.
I always love a good set of API code!
I might need to collaborate with you on a little bit of API code I've been working on that I can't seem to figure out how to get what I'm trying to do. Usually the square API is pretty robust and gives me what I want. I'm not really sure why I'm stuck on this one. I might reach out to you. 😊
No idea what i'm doing but happy to collaborate 🙂 I keep using the ChatGPT o1-preview model and whenever I can't get the code to work I search API documentation for what im looking for and copy and paste the entire webpage into the chatbot and go "Does this help? PASTE"
It almost always fixes whatever is broken lol
Hey @JTPets, thanks to you and your robot friend for piecing this together! It's the closest I've found to what I'm after.
One issue I'm experiencing is that it's serving me images the return a 404 (For example: https://expera.square.site/uploads/1/4/9/4/149459479/s179156[Redacted]67_p1_i1_w297.png)
I thought it might be a permissions issue and I've tried asking my own robots, but I'm not sure of the right questions so I'm just going around in circles. Any ideas?
I gave my api key full access - that could he a permissions issue also ensure you are using the most recent code off my github as I have made a few tweaks for my own use that might have been broken here
Ok, I've used the Github code and connected an API key with all boxes checked, but it's still grabbing the URLs that serve a 404 error.
In the Link column it serves working URLs (https://expera.square.site/product/sikabond-150-premium-floor-pail-/1), but the correlating image URL in the Image column (https://expera.square.site/uploads/1/4/9/4/149459479/s179156[Redacted]67_p1_i1_w297.png) which doesn't work.
When I get the image address from the functioning product page, it gives https://149459479.cdn6.editmysite.com/uploads/1/4/9/4/149459479/s179156[Redacted]67_p1_i1_w297.png?w... which does work, even in private browser windows.
If I access the Square image library and find the same product, it gives the URL https://items-images-production-f.squarecdn.com/files/0e3e1fd8f4d9e5fe41ffbeb20397e932bc7c5469/origi... which is also publicly accessible.
I've tried for products that are in stock and different locations with no joy. I'm stumped!
Square Community
Square Products