đź“… Fireside Chat: Future of Analytics on the Modern Data Stack with Hex, Transform, and RudderStack

Register Now →
By Rudderstack Team

How to load data from the Square to Google BigQuery

Square is a simple and powerful POS software for businesses. What if I want to get more data-driven and gather all my data from Square to my BI or custom analytics stack or my data warehouse like BigQuery? How can I analyze the data generated with Square?

This guide will provide you with a clear picture of how to load data from Square to Google BigQuery. We will use Square’s API to access and extract e-mail related data and load it into Google BigQuery for further analysis.

Alternatively, you may check out RudderStack to load your data from Square to Google BigQuery in minutes for you.

How to Extract my data from Square?

As a platform, Square exposes a number of different APIs that cover different needs.

  • E-commerce API, with which you can take payments using
  • Register API, which can be used to build your applications for in-store or mobile payments.
  • Item & inventory management API.
  • Sales reporting & Analytics API.
  • Employee management API.

Square is currently maintaining two versions of the API, Connect v1 and Connect v2. There’s also an SDK for the Register API. You might need to use v1 and v2 of the Connect API, as not all endpoints have been implemented in the second and newest versions. Mixing the two API versions is encouraged by Square.

All the APIs that Square exposes are web APIs. As Web APIs following the RESTful architecture principles, they can be accessed through HTTP. As a RESTful API, interacting with it can be achieved using tools like CURL or Postman or by using HTTP clients for your favorite language or framework. A few suggestions:

Square also maintains official SDKs or libraries for the following languages:

Because of the popularity of Square, a number of unofficial libraries/SDKs are also implemented, so a quick search on Google or Github will help you find a library for your favorite framework or language.

Square API Authentication

To use the Square API, you first need to register a new application with Square. By doing that, you are also generating credentials that will be used to access the API endpoints.

To register your application:

  1. Go to https://connect.squareup.com/apps and sign in to your Square account.
  2. Click New Application and enter a name for your application.
  3. Click Create App.

The application dashboard displays your new app’s credentials. One of these credentials is the personal access token. This token gives your application full access to your own Square account. Copy its value to use in the next step.

Square API rate limiting

If Connect API endpoints receive too many requests associated with the same application or access token in a short time window, they might respond with a 429 Too Many Requests error. If this occurs, try your request again at a later time. The current rate is on the order of 10 QPS.

This might change in the future and is not officially documented to handle our requests and responses properly.

Pull data from the Square platform

As mentioned earlier, Square exposes a number of APIs for different applications. Thus each one offers different opportunities for pulling useful data out of it. In this post, we will focus on how to get meaningful data out of the Square Connect API that can be used for analytics.

The Square Connect API allows us to use the Square platform to execute payment transactions, so many endpoints are related to these tasks. However, we do not need to access these endpoints for analytic purposes. In a payment system, what we need to track and use as data for further analysis is related to what is happening in our system.

For example, we would like to track when a new payment has happened, when something went wrong with a transaction, etc. We need to monitor the system for specific events and make sure that we store these events in a data warehouse solution like Google BigQuery for further analysis.

Square Connect API, offers a notification through webhooks mechanism to receive notifications any time an important event happens in our system.

We can use this mechanism to track and record events from the Square Platform for analytics. For example, we can receive real-time webhook notifications as a merchant accepts payments. Get started with webhooks with the following steps:

  1. Open your application’s settings from the application dashboard and select the Webhooks tab.
  2. Click Enable Webhooks if it isn’t already enabled.
  3. In the Notification URL field, specify the URL of your webhook page and click Save.
  4. Subscribe to webhook notifications from your merchant account by sending the following curl request to the Update Webhooks endpoint (providing your access token and location ID where indicated):
curl -X PUT -H "Authorization: Bearer PERSONAL_ACCESS_TOKEN" -H "Content-Type: application/json" -d "[\"PAYMENT_UPDATED\"]" https://connect.squareup.com/v1/LOCATION_ID/webhooks

By doing the above, we request the Square Connect API to notify us every time a new payment is happening to track these events. The API is near real-time, and you will receive the notification in no more than 60 seconds from the moment it happens.

The event that will be sent to our webhook will look like this:

"merchant_id": "18YC4JBH91E1H",
"location_id": "JGHJ0343",
"event_type": "PAYMENT_UPDATED",
"entity_id": "Jq74mCczmFXk1tC10GB"

As the above event does not include information that can be used directly, we will have to extract the “entity_id” value and use it to poll the “RetrieveTransaction” endpoint to get the full details of the event. If we do that, we will get a full response like the following: