How to load data from Recurly to Google BigQuery

Extract your data from Recurly

The Recurly API allows applications to interact directly with its platform. In general, Recurly offers the following ways of integrating with their services:

  • Hosted Payment Pages. With this product, merchants can start immediately subscribing to their customers with minimal effort and without requiring significant technical skills.
  • js. A JavaScript library that can be used to integrate the functionality of Recurly in your product securely.
  • API. A Web API that exposes the full functionality of Recurly through its interface for integrating with it programmatically.

From the above three methods, we are interested in the last one as it is the only way that we can use to pull data from the Recurly platform. There’s also a plethora of SDKs so you can interact with the API from your language or framework of choice:

  • PHP (official)
  • Ruby (official)
  • Python (official)
  • .NET (official)

Recurly iOS SDK in official CocoaDocs organization

  • Android (official)
  • Java (unofficial)
  • Go (unofficial)
  • Node.js (unofficial)

The Recurly API is a RESTful web service. As a RESTful API, interacting with it can also be achieved by using tools like CURL or Postman or Apirise or by using HTTP clients for your favorite language or framework, instead of one of the previously mentioned SDKs. A few suggestions:

Recurly API Authentication

Recurly is using HTTP Basic Authentication using your API Key for credentials. All data are transferred over a secure SSL channel. Below an example using Curl that demonstrates how authentications works for Recurly:

SH
curl -H 'Accept: application/xml' \
-H 'X-Api-Version: 2.1' \
-H 'Content-Type: application/xml; charset=utf-8' \
-u [API Key]: https://[subdomain].recurly.com/v2/accounts

Recurly supports the use of multiple Private API keys, which can be used to integrate third-party services using unique, controlled credentials. With the following limitations:

Core & grandfathered Recurly plans are granted 5 private API keys.

The professional plan grants 10 API keys.

Rate Limits

By default, new Recurly sites have the following API rate limits:

  • Sandbox sites: 400 requests/min. All requests count towards the rate limit.
  • Production sites: 1,000 requests/min. Only GET requests to count towards the rate limit.

Once your site moves into production mode, Recurly will only rate limit GET requests. New subscriptions, account modifications, and other requests using POST PUT, or DELETE methods will not count against your rate limit.

The rate limit is calculated over a sliding 5-minute window. This means a production site could make 4,000 requests within one minute and not hit the rate limit so long as the site made less than 1,000 requests during the prior 4 minutes.

If an API request exceeds the rate limit, the API returns a 429 status code indicating Too Many Requests.

Prepare your data to be sent from Recurly to Google BigQuery

Before you load your data into BigQuery, you should make sure that it is presented in a format supported by it. For example, if the API you pull data from returns XML, you have to first transform it into a serialization that BigQuery understands. Currently, two data formats are supported:

You also need to make sure that the data types you are using are the ones supported by BigQuery, which are the following:

  • STRING
  • INTEGER
  • FLOAT
  • BOOLEAN
  • RECORD
  • TIMESTAMP

For more information, please check the Preparing Data for BigQuery page on the documentation.

Load Data from Recurly to Google BigQuery

If you want to load data from Recurly to Google BigQuery, you have to use one of the following supported data sources:

  1. Google Cloud Storage
  2. Sent data directly to BigQuery with a POST request
  3. Google Cloud Datastore Backup
  4. Streaming insert
  5. App Engine log files
  6. Cloud Storage logs

From the above list of sources, 5 and 6 are not applicable in our case.
For Google Cloud Storage, you first have to load your data into it. There are a few options on how to do this. For example, you can use the console directly as described here, and do not forget to follow the best practices. Another option is to post your data through the JSON API. As we see again, APIs play an important role in both the extraction and the loading of data into our data warehouse. It’s the simplest case, it’s just a matter of one HTTP POST request using a tool like CURL or Postman. It should look like the following example.

JSON
POST /upload/storage/v1/b/myBucket/o?uploadType=media&name=myObject HTTP/1.1
Host: www.googleapis.com
Content-Type: application/text
Content-Length: number_of_bytes_in_file
Authorization: Bearer your_auth_token
your Recurly data

and if everything went ok, you should get something like the following as a response from the server:

JSON
HTTP/1.1 200
Content-Type: application/json
{
"name": "myObject"
}

Working with Curl or Postman is good only for testing. If you would like to automate the process of loading your data into Google Bigquery, you should write some code to send your data to Google Cloud Storage. In case you are developing on the Google App Engine, you can use the library that is available for the languages that are supported by it:

  • Python
  • Java
  • PHP
  • Go

If you are using one of the above languages and are not coding for the Google App Engine, you can access Cloud Storage from your environment. Interacting such a feature-rich product like Google Cloud Storage can become quite complicated depending on your use case. For more details on the different options that exist, you can check Google Cloud Storage documentation. If you are looking for a less engaged and more neutral way of using Cloud Storage, you can consider a solution like Rudderstack.

After you have loaded your data into Google Cloud Storage, you have to create a Load Job for BigQuery actually to load the data into it, and this Job should point to the source data in Cloud Storage that have to be imported. This happens by providing source URIs that point to the appropriate objects.

The previous method described used a POST request to the Google Cloud Storage API for storing the data there and then loading it into BigQuery. Another way to go is to do a direct HTTP POST request to BigQuery with the data you would like to query. This approach is similar to how we loaded the data to Google Cloud Storage through the JSON API, but it uses the appropriate end-points of BigQuery to load the data there directly. The way to interact with it is quite similar, for more information can be found on the Google BigQuery API Reference and on the page that describes how to load data into BigQuery using POST. You can interact with it using the HTTP client library of the language or framework of your choice; a few options are:

The best way to load data from Recurly to BigQuery

So far, we just scraped the surface of what you can do with BigQuery and how to load data into it. Things can get even more complicated if you want to integrate data coming from different sources.

Are you striving to achieve results right now?

Instead of writing, hosting, and maintaining a flexible data infrastructure use Rudderstack that can handle everything automatically for you.

Sign Up For Free And Start Sending Data
Test out our event stream, ELT, and reverse-ETL pipelines. Use our HTTP source to send data in less than 5 minutes, or install one of our 12 SDKs in your website or app.
Don't want to go through the pain of direct integration? RudderStack's Recurly integration makes it easy to send data from Recurly to Google BigQuery.