How to load data from Trello to Google BigQuery
Extract your data from Trello
Trello exposes a very rich API to developers. It is the same API that is used internally to build the web and mobile Trello apps that we all use and love. It is possible to build a completely new application on top of the API using the different components and resources that it exposes, or just use it to pull out data as we plan to do in our case.
The Trello API follows the RESTful principles, and it can be accessed through HTTP. As a RESTful API, interacting with it can be achieved by using tools like CURL or Postman or using HTTP clients for your favorite language or framework. A few suggestions:
- Apache HttpClient for Java
- Spray-client for Scala
- Hyper for Rust
- Ruby rest-client
- Python http-client
Trello also offers an official Javascript client/wrapper for its API, which can be found here. It is also possible to find numerous other unofficial SDKs. All it takes is a quick search on Google or Github.
Trello API Authentication
The Trello API supports Authentication and Authorization by implementing the OAuth protocol. It’s important to understand that the Authentication Token, obtained through the OAuth workflow execution, gives your application the ability to make calls on behalf of your user from their context. This token grants access to the authenticated user’s boards, lists, cards, and other settings, depending on the permissions you requested in the authenticate method. So you have to handle it with care.
Trello rate limiting
To help prevent strain on Trello’s servers, our API imposes rate limits per API key for all issued tokens. There is a limit of 300 requests per 10 seconds for each API key and no more than 100 requests per 10-second interval for each token. If a request exceeds the limit, Trello will return a 429 error.
Endpoints and available resources
The Trello API exposes a large number of resources together with their associated HTTP endpoints that allow the users to interact with the platform as the web and mobile applications of Trello do. The most important resources are the following:
- Board: anything related to the boards a user can create and manage in Trello
- Card: operations about the cards that can be created inside boards
- Checklist: it allows the creation and manipulation of checklists inside cards
- Label: operations related to labels that can be created inside cards
- List: operations on lists
- Member: operations related to members of a board
- Notification: operations about the notification system of the platform
- Organization: manage organizations inside Trello
So, let’s assume that you have a board that helps you track one of your projects. The methodology doesn’t matter at this point. What is important is that you most probably will have cards associated with tasks. These cards are holding the information that you would like to pull, store in a database like Google BigQuery and analyze it further. First, we assume that we know the ID of our board,
- our board id is 4eea4ffc91e31d1746000046
First, we want to get all the lists that this board includes. To do that, we execute a GET request on the following URL:
JAVASCRIPT
https://api.trello.com/1/boards/4eea4ffc91e31d1746000046/lists?cards=open&card_fields=name&fields=name&key=[application_key]&token=[optional_auth_token]
If the request is successful, we will get back a response like the following:
JAVASCRIPT
[{"id": "4eea4ffc91e31d174600004a","name": "To Do Soon","cards": [{"id": "4eea503791e31d1746000080","name": "Finish my awesome application"}]}, {"id": "4eea4ffc91e31d174600004b","name": "Doing","cards": [{"id": "4eea503d91e31d174600008f","name": "Learn about the Trello API"}, {"id": "4eea522c91e31d174600027e","name": "Figure out how to read a user's board list"}]}, {"id": "4eea4ffc91e31d174600004c","name": "Done","cards": [{"id": "4eea501f91e31d1746000062","name": "Get a key to use in my API requests"}, {"id": "4eea502b91e31d1746000071","name": "Find out where the Trello API documentation is"}]}]
The above JSON response includes all the lists that our product has. Each least will contain cards with tasks, and for example, if we have a card inside the Done list, it means that the associated task is completed.
After we get a list of all the lists, we can start fetching the cards of each list. Again we do that by executing a GET request to the appropriate endpoint, using the IDs of the lists that we have extracted from the previous response. A typical URL for fetching the cards of a list looks like the following:
JAVASCRIPT
https://api.trello.com/1/lists/4eea4ffc91e31d174600004a/cards?key=[application_key]&token=[optional_auth_token]
And the result of a successful request to the above endpoint will result in something with the following structure:
JAVASCRIPT
[{"id": "4eea503791e31d1746000080","badges": {"votes": 0,"viewingMemberVoted": false,"subscribed": false,"fogbugz": "","checkItems": 0,"checkItemsChecked": 0,"comments": 0,"attachments": 0,"description": false,"due": null},"checkItemStates": [],"closed": false,"dateLastActivity": "2011-12-15T19:53:27.228Z","desc": "","descData": null,"due": null,"email": null,"idAttachmentCover": null,"idBoard": "4eea4ffc91e31d1746000046","idChecklists": [],"idLabels": [],"idList": "4eea4ffc91e31d174600004a","idMembers": [],"idMembersVoted": [],"idShort": 3,"labels": [],"manualCoverAttachment": false,"name": "Finish my awesome application","pos": 65536,"shortLink": "XlG8S7ll","shortUrl": "https://trello.com/c/XlG8S7ll","subscribed": null,"url": "https://trello.com/c/XlG8S7ll/3-finish-my-awesome-application"}]
We have retrieved all the relevant to our project information from our board. We just need to remodel our data in an appropriate way to query it on a database like Google BigQuery and, of course, ensure that we properly load the data to it. After we do that, we are ready to start querying our Trello data and learning everything related to the performance of our teams and projects.
Prepare your data to be sent from Trello 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 must 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 Trello to Google BigQuery
If you want to load data from Trello to Google BigQuery, you have to use one of the following supported data sources.
- Google Cloud Storage
- Sent data directly to BigQuery with a POST request
- Google Cloud Datastore Backup
- Streaming insert
- App Engine log files
- 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. In its 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.
JAVASCRIPT
POST /upload/storage/v1/b/myBucket/o?uploadType=media&name=myObject HTTP/1.1Host: www.googleapis.comContent-Type: application/textContent-Length: number_of_bytes_in_fileAuthorization: Bearer your_auth_token your Trello data
and if everything went ok, you should get something like the following as a response from the server:
JAVASCRIPT
HTTP/1.1 200Content-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:
If you are using one of the above languages and you are not coding for the Google App Engine, you can use it to access the 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 to actually load the data into it, 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 load 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:
- Apache HttpClient for Java
- Spray-client for Scala
- Hyper for Rust
- Ruby rest-client
- Python http-client
The best way to load data from Trello 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.
RudderStack, with one click, integrates with sources or services, creates analytics-ready data, and syncs your Trello to BigQuery right away.