Import GitHub Data to Google Sheets

Import GitHub Data to Google Sheets

Last Updated On August 16, 2019
You are here:
< Back

In this guide, we’ll walk through how to pull data from the Github API directly into Google Sheets, using the free 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

  1. 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.
    github-api-img1
  2. 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.
    github-api-img3
  3. Click the “Generate token” button at the bottom of the page:
    github-api-img4
  4. Your GitHub personal access token is now ready:
    github-api-img5
  5. 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:
    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):
    github-api-img6
  6. 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, you can also try a tool like Basic Authentication Header Generator to generate your header.)
  7. 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

We’re going to follow the Github API documentation to search for repositories matching a specific search term.

  • API root: https://api.github.com
  • Endpoint: /search/repositories
  • Parameters: q={search term}
    Parameters Example: q=google tag manager

Putting it all together, we get the full API Request URL:
https://api.github.com/search/repositories?q=google tag manager

PART 3: ENTER VALUES INTO API CONNECTOR

We can now enter all our values into API Connector and start importing Github data into Google Sheets.

  1. Open up Google Sheets and click Add-ons > API Connector > Create New API Request.
  2. In the Create Request interface, enter the Request URL we just created
    github-api-img7
  3. Under Headers, enter a key-value pair like this:
    Authorization Basic {your encoded API token}

    You should be able to paste in the value you got in step 6 above.

    It should look like this:
    github-api-img8

  4. Create a new tab. You can call it whatever you like, but here we’ll call it ‘Github’. While still in that tab, click ‘Set’ to use that tab as your data destination.
  5. Name your request. Again we’ll call it ‘Github’
  6. Click Run and a moment later you’ll see Github data populate the Github tab in your Google Sheet:
    github-api-img9

PART 4: NOTES AND EXPANSIONS

  1. Experiment with endpoints as described in the documentation to see other types of Github data. For example, you can change the API URL path to https://api.github.com/users to see a list of users.

Comments:0

Leave a Reply

Your email address will not be published.