Search API Connector Documentation

Print

Import Coinbase Data to Google Sheets

In this guide, we’ll walk through how to pull cryptocurrency market data from the Coinbase Digital Currency API directly into Google Sheets, using the API Connector add-on for Sheets. For this example we’ll only access Coinbase’s open, unauthenticated endpoints, so we don’t need to get an API key. Coinbase doesn’t provide that much data via these endpoints (CoinGecko is generally better in that respect), but it is easy to use and useful for getting a comprehensive list of exchange rates in one go.

BEFORE YOU BEGIN

Click here to install the API Connector add-on from the Google Marketplace.

PART 1: CREATE YOUR COINBASE API REQUEST URL

We’ll follow the Coinbase API documentation to access the latest exchange rate data for Bitcoin.

  • API root: https://api.coinbase.com
  • Endpoint: /v2/exchange-rates
  • Query String: ?symbol={{currency}}
    Query String Example: ?currency=BTC

Putting it together, we get the full API Request URL:

https://api.coinbase.com/v2/exchange-rates?currency=BTC

PART 2: PULL COINBASE API DATA INTO SHEETS

We can now enter all our values into API Connector and import Coinbase API data into Google Sheets.

  1. Open up Google Sheets and click Add-ons > API Connector > Open.
  2. In the Create tab, enter the API URL we just created.
    coinbase-img1
  3. Leave the Headers section empty. The market data part of the Coinbase API is public, so we don’t need any headers or other authentication. We don’t need extra authentication either, so just leave that set to None.
  4. Create a new tab, and click ‘Set current’ to use that tab as your data destination.
  5. Name your request, and click Run. A moment later you’ll see the latest exchange rate data for Bitcoin appear in your Google Sheet:
    coinbase-img2
  6. If you’d like to see the data in columns instead of rows, create a second sheet and include the Sheets function =transpose(BTC!1:2)

PART 3: MORE EXAMPLE API URLS

Experiment with endpoints and query strings as described in the documentation to see other types of currency and crypto data from the API. For example, you can try the following URLs, one at a time (substitute in other currency symbols or dates, if you like).

  • list of all currencies and corresponding symbols
    https://api.coinbase.com/v2/currencies
  • current spot price of any currency pair (the spot price is usually between the buy and sell price)
    https://api.coinbase.com/v2/prices/BTC-USD/spot
  • historical price snapshot of currency pair at a specified date
    https://api.coinbase.com/v2/prices/BTC-USD/spot?date=2020-01-01

P.S. For dozens of other step-by-step guides for connecting crypto (and other) APIs to Google Sheets, click here: Knowledge Base

Previous Import CoinAPI Data to Google Sheets
Next Import CoinGecko Data to Google Sheets

9 thoughts on “Import Coinbase Data to Google Sheets”

  1. Hello, firstly I greatly appreciate all your work on this tool, it is simply incredible.

    I am trying to get Coinbase OAUTH2 to work. I want OAUTH2 because I intend to have someone else use their own locked down page in my sheet. OATH2 will allow us to individually authenticate and not have to enter in API keys.

    My issue:
    I’ve attempted to add in a custom OAUTH2 connection using Coinbase’s Authorize/Token urls:
    Authorize URL: https://www.coinbase.com/oauth/authorize
    Access Token URL: http://www.coinbase.com/oauth/token
    I created a Coinbase OAUTH app, and I used the redirect/callback URL for API Connect as described in this post.
    I created a custom API Connect OAUTH Connection and entered in my clientid/secret info after creating the Coinbase OAUTH2 app@Coinbase. (maybe that’s the problem, its not OAUTH2, but just OAUTH?)

    When I click the Connect button to authenticate, it appears to work – Coinbase pops up with my account and asks to give access. I accept.

    Then I get an error when it goes back to the callback URL (the callback url is in the address bar for this message)- It says this:
    Access Error
    An error has occurred: Error: Token response not valid JSON: SyntaxError: Unexpected token: I content: “Invalid request. Instead of a GET request, you should be making a POST with valid POST params. For more information, see https://developers.coinbase.com/docs/wallet/coinbase-connect“.

    I am not sure if I need to put the scope of what I want to access into the authorize url or not, but essentially the only information I want to access is in the wallet:buys:read scope.
    The url to access this is:
    https://api.coinbase.com/v2/accounts/:account_id/buys
    And each “account” is actually the “coin” wallet of the user, so I’d need to iterate through all of the accounts on the user, which is at this endpoint:
    https://api.coinbase.com/v2/accounts
    with this scope:
    wallet:accounts:read

    I tried to get as much info for you as possible so you didn’t have to re-learn everything I did.

    Please assist if you have the time to do so. I greatly appreciate any time you can afford to spend.

    (Coinbase integration guide here – https://developers.coinbase.com/docs/wallet/coinbase-connect/integrating)

    Reply
    • I think the main issue is that the Auth Code (used to then obtain the OAUTH token) is not returned as JSON, it is returned to the callback URL directly as a parameter. I tested pasting my authorize url into my internet browser by using the redirect url of “urn:ietf:wg:oauth:2.0:oob” and it shows the auth code in the title bar and in the URL itself.

      Is API Connect capable of grabbing the auth code without it being returned explicitly as JSON content?

      Reply
      • Hi Brandon! Thank you for all the detailed information, that helps with troubleshooting. API Connector’s custom OAuth2 connection expects the authorization code as a URL parameter so that shouldn’t be an issue. I tested and was able to authenticate as follows:

        1) created a new app here: https://www.coinbase.com/settings/api. This gave me the client ID and secret
        2) in API Connector, filled out the custom OAuth2 settings like this:
        Name: Custom Coinbase
        Authorization Base URL: https://www.coinbase.com/oauth/authorize?scope=wallet:accounts:read
        Token URL: https://api.coinbase.com/oauth/token
        Client ID:
        Client Secret:

        Once I did that I clicked connect and it seemed to work without any problem. I don’t have a Coinbase wallet but I ran a request to https://api.coinbase.com/v2/accounts and it pulled in data. Can you please try and see if it works for you?

  2. I’m not able to generate a spot price between two cryptocurrencies, like the current price from BTC to DOT for example.

    Is this possible?

    Reply
    • Yeah, their documentation isn’t that clear on this point, but it seems the spot price endpoint only supports conversions to USD. But you could get this data by running https://api.coinbase.com/v2/exchange-rates?currency=BTC and finding the price of DOT within the response.

      Reply

Leave a Comment