I am trying to call CoinMarketCap's public API but it always fails with following error:
error occured Error: getaddrinfo ENOTFOUND api.coinmarketcap.com api.coinmarketcap.com:443
When I call the URL from the browser it returns the result instantly. The code is pretty simple:
const functions = require('firebase-functions');
const axios = require('axios');
exports.getBtcPrice = functions.https.onRequest((req, res) => {
axios.get('https://api.coinmarketcap.com/v1/ticker/bitcoin')
.then( (response) => {
console.log(response);
res.send("data received");
})
.catch((error) => {
console.log(error);
res.send("error occured "+ error)
});
});
If you are on the free plan outbound networking with firebase functions only works with google services. They mention this is the cloud function section on the pricing page https://firebase.google.com/pricing/
You have to move to a paid tier if you want to use third-party APIs.