Print

Import Coinbase Data to Google Sheets

In this guide, we’ll walk through how to pull public cryptocurrency market data from the Coinbase Digital Currency API directly into Google Sheets, using the API Connector add-on for Sheets.

Coinbase doesn't provide that much market data (most other crypto APIs are better in that respect), but it is easy to use and can be a useful alternative to some of the more popular crypto APIs.

Before You Begin

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

Part 1: Pull Data from Coinbase into Sheets

The easiest way to get started with the Coinbase API is through API Connector’s built-in integration.

  1. In Sheets, open API Connector and create a new request (Extensions > API Connector > Open > Create request)
  2. Select Coinbase from the drop-down list of applications
    coinbase-application
  3. Select an endpoint.  These endpoints are all open so you don’t need an API key. For this example we’ll choose the /prices/{currency_pair}/buy endpoint, which provides the current buy price for a cryptocurrency.
    coinbase-endpoints
  4. This endpoint requires that we enter a currency pair. We'll use BTC-USD
    coinbase-parameters
  5. Choose a destination sheet, name your request, and hit Run. A moment later you'll see the response data in your sheet.
    coinbase-response

Part 2: Create a Custom Request

Alternatively, you can run your own custom requests instead of using API Connector’s pre-built integration, using any of the URLs shown in the API documentation. Here's an example:

  • Application: Custom
  • Method: GET
  • Request URL: https://api.coinbase.com/v2/prices/BTC-USD/buy

Part 3: API Documentation

Official API documentation: https://docs.cloud.coinbase.com/sign-in-with-coinbase/docs/welcome

24 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) registered 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://login.coinbase.com/oauth2/auth?scope=wallet:user:read,wallet:accounts:read
        Token URL: https://login.coinbase.com/oauth2/token
        Client ID: value provided by Coinbase
        Client Secret: value provided by Coinbase

        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. Thanks for the suggestion. I don't have a Coinbase Pro account myself to test with, but after checking the docs I think the biggest challenge will be with adding in the signature they describe here: https://docs.pro.coinbase.com/#signing-a-message. You'd need some custom code for that.

    Update: You can use this sheet to connect to your private Coinbase account data: https://docs.google.com/spreadsheets/d/1mA31i-4E9yKQJ9rWBaICQBPesGfaGpazX6rZBz9JHqs/copy#gid=1147903952

    Reply
  3. 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
  4. Hello! I was wondering if it's possible to get 2 different currencies (let's say BTC and ETH) in one API GET request.

    I've tried setting 2 API URLs on the same connector but it doesn't work. I've tried setting 2 different connectors but the first one deletes de second one when it gets refreshed =/

    Reply
  5. Thank you so much for this very useful tool. I've been following some crypto. Is there a way to display in a box the evolution of a crypto in percent for the last month? Always the evolution from a month from now to now.

    Thank you!!
    Max in Indonesia.

    Reply
    • Sure, but Coinbase doesn't provide a lot of info so I'd use a different API for this. For example this API call to CoinMarketCap would give you 24h, 7d, 30d, 60d, and 90d percent changes for whatever coins you want:
      https://pro-api.coinmarketcap.com/v1/cryptocurrency/quotes/latest?symbol=BTC

      Reply
  6. Hi, thanks for the info.
    Do you know how connect to coinbase without addons. I mean, do you know how connect to coinbase from google sheet and get my wallet ?

    I try to figure out....

    Reply
  7. Hello, really nice sheet it worked for me and I was able to get e. g. my user_id intro google sheets.

    But is there an endpoint from coinbase with which I could import the total account balance, shown to me when I open the app, into google sheets?

    Thanks a lot.

    Reply
  8. Hey Peter, I don't have an active Coinbase account so I can't investigate this at the moment. I'll check and respond as soon as I can.

    Reply
      • I'm still unable to test this myself but I've re-checked the Coinbase docs on creating a signature, and don't see anything different from what's in the sheet. It says the signature is generated by "creating a sha256 HMAC using the secret key on the prehash timestamp + method + requestPath + body". In cell F11 of the signature generator sheet, I see a value of 1688961030GET/v2/user, which is the timestamp + method + requestPath (body isn't required for GET requests). In the next cell down, the sha256 is created. Does your value in F11 look different from that pattern?

  9. Thanks for your feedback. I don't have an account to test with (or any way to make one, as I live outside their available location) so I have no way to troubleshoot it. I'll remove the sheet to avoid confusion.

    Reply
    • I believe Coinbase updates its prices every minute or two, but the sheet doesn't automatically update unless you set up scheduling.

      Reply

Leave a Comment

Jump To