Import GitHub Data to Google Sheets
In this guide, we’ll walk through how to pull data from the Github API directly into Google Sheets, using the API Connector add-on for Google Sheets. We’ll first get a personal access token (aka API key) from Github, and then set up a request to pull in code repository details from Github to your spreadsheet.
- Part 1: Get your Github Personal Access Token
- Part 2: Create your API Request URL
- Part 3: Pull Github API data into Sheets
- Part 4: More Example GitHub API URLs
PART 1: GET YOUR GITHUB PERSONAL ACCESS TOKEN
- Log in to Github and navigate to https://github.com/settings/tokens. Click either “Generate a personal access token” or the “Generate new token” button.
- This will take you to a screen to set up scope details for your token. For our purposes here we don’t need any additional scopes, so just enter a description into the required Note field and scroll to the bottom.
- Click the “Generate token” button at the bottom of the page:
- Your GitHub personal access token is now ready:
- One last step: Basic Access Authentication requires us to encode our authentication info to base 64. You can do this opening up Developer Tools in your browser (F12 on Windows/Linux or option + ⌘ + J on OSX). In the console, type in the following and click enter:
encodedData = "Basic " + window.btoa('YOUR_USERNAME+YOUR_PERSONAL_ACCESS_TOKEN')
Substitute your own Github username and personal access token values from above. It should look like this (don’t forget the plus sign in the middle):
- Copy the output that appears in Developer Tools to your clipboard, excluding the quotation marks at the beginning and end of the string. (If you have any problems with the above, check the article on Encoding Credentials to Base 64 (Basic Authentication) for alternative methods).
- Congrats, you’re done! You’re now ready to access the Github API, and can start pulling Github data into Google Sheets.
PART 2: CREATE YOUR API REQUEST URL
- API root: https://api.github.com
- Endpoint: /search/repositories
- Parameters: q=SEARCH_TERM
Putting it all together, we get a full API Request URL:
https://api.github.com/search/repositories?q=google tag manager
PART 3: PULL GITHUB API DATA INTO SHEETS
We can now enter all our values into API Connector and start importing Github data into Google Sheets.
- Open up Google Sheets and click Add-ons > API Connector > Open.
- In the Create tab, enter the API URL we just created.
- Under Headers, enter a key-value pair like this (again, you don’t need to enter this header if you’re connecting through the OAuth2 connections manager):
Authorization Basic YOUR_BASE64_ENCODED_TOKEN
- If you’re using the OAuth2 connection manager, select GitHub from the drop-down authentication method. Otherwise, just leave authentication as “None”.
- Create a new tab and click ‘Set current’ to use that tab as your data destination.
- Name your request and click Run. A moment later you’ll see Github data populate the Github tab in your Google Sheet:
PART 4: MORE EXAMPLE GITHUB API URLS
You can experiment with endpoints as described in the documentation to see other types of Github data. If you just want to jump in and get an idea, you can play around with the URLs you enter in the API URL path field. Try the following (one at a time):