How to get the current price of a cryptocurrency on google sheets from coinmarketcap

0 votes

On a google sheets cell I want to get only the current cryptocurrency price with this formula:

=ValueCrypto(A1)

I tried this function for coinmarketcap:

function ValueCrypto(crypto) { var url = "https://api.coinmarketcap.com/v1/ticker/" + crypto + "/?convert=EUR"; var response = UrlFetchApp.fetch(url); var data = JSON.parse(response.getContentText()); return data[0].price_eur; }


the function gives me the error "We no longer serving this endpoint here"

I also tried to change the endpoint and I added my API key into the function:

function ValueCrypto(crypto) { var url = "pro-api.coinmarketcap.com/v1/cryptocurrency/quotes/latest?symbol=" + crypto var requestOptions = { method: 'GET', uri: 'https://pro-api.coinmarketcap.com/v1/cryptocurrency/listings/latest', qs: { start: 1, limit: 5000, convert: 'EUR' }, headers: { 'X-CMC_PRO_API_KEY': 'myapikey' }, json: true, gzip: true }; var response = UrlFetchApp.fetch(url); var data = JSON.parse(response.getContentText()); return data[0].price_eur; }

and the errors now are Exception: Request failed for http://pro-api.coinmarketcap.com returned code 401. Truncated server response:

{ "status": { "timestamp": "2021-01-02T11:31:39.880Z", "error_code": 1002, "error_message": "API key missing.", ... 

Apr 6, 2022 in Blockchain by Rahul
• 9,670 points
1,119 views

1 answer to this question.

0 votes

Your code does not appear to use requestOptions which is where the API key is defined. Try passing it to UrlFetchApp like this:

var response = UrlFetchApp.fetch(url, requestOptions);

answered Apr 12, 2022 by Soham
• 9,700 points

Related Questions In Blockchain

0 votes
1 answer

How to get the current state of a smart contract?

Hey, you gotta provide the contract code, and ...READ MORE

answered Aug 1, 2018 in Blockchain by Perry
• 17,100 points
886 views
0 votes
1 answer

How to get data from Google Finance to Google sheets?

You need to have a from and ...READ MORE

answered Aug 21, 2018 in Blockchain by slayer
• 29,350 points
1,124 views
0 votes
0 answers

How to get AUD price of bitcoin at a particular date

I am trying to find out how ...READ MORE

Mar 1, 2022 in Blockchain by Soham
• 9,700 points
277 views
0 votes
1 answer

How to get a list of Coinbase CryptoCurrency Coins

The following code: import requests ...READ MORE

answered Apr 8, 2022 in Blockchain by Rahul
• 9,670 points
1,072 views
+1 vote
1 answer

Protocols used in a distributed/dlt system for the nodes to establish communication

yes all are over TCP/IP connections secured ...READ MORE

answered Aug 6, 2018 in Blockchain by aryya
• 7,450 points
1,129 views
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
1,663 views
0 votes
1 answer

Hyperledger Sawtooth vs Quorum in concurrency and speed Ask

Summary: Both should provide similar reliability of ...READ MORE

answered Sep 26, 2018 in IoT (Internet of Things) by Upasana
• 8,620 points
1,215 views
0 votes
1 answer

How To Get BTC Price on Binance from Binance API

In the Script environment for Apps, the ...READ MORE

answered Feb 28, 2022 in Blockchain by Soham
• 9,700 points
1,995 views
0 votes
1 answer

How can merkle trees help validate the content of a block in a blockchain

As long as they are centralized entities ...READ MORE

answered Feb 28, 2022 in Blockchain by Soham
• 9,700 points
495 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP