Writing a code to consume the REST API https://api.coindesk.com/v1/bpi/currentprice.json with Google Spreadsheets .

Google Sheets doesn’t have a built-in way to directly call external APIs. However, you can achieve this using Google Apps Script, a Javascript-like scripting language for extending Google Sheets functionality.

Here’s the code to consume the CoinDesk API and write the USD price to a specific cell in your Google Sheet:

Instructions:

  1. Open your Google Sheet.
  2. Go to Tools > Script editor.
  3. Paste the code above into the script editor.
  4. Replace "A1" with the actual cell address where you want to write the USD price.
  5. Save the script (File > Save).
  6. Run the script by clicking Run > getBitcoinPrice.

This script fetches the Bitcoin price from the CoinDesk API and writes it to the specified cell.

Important Notes:

  • This script retrieves data only when you run it manually. To automatically update the price at regular intervals, you’ll need to use a trigger (requires Google Apps Script knowledge).
  • Consider adding error handling to gracefully handle potential issues like API failures or invalid responses.

This is a basic example. You can modify it to:

  • Extract different data points from the JSON response.
  • Write the data to different cells or format it as needed.