Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase Cloud Functions throws a DNS error when calling an external API [duplicate]

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)
        });
});
like image 816
Ashit Vora Avatar asked Jul 04 '26 20:07

Ashit Vora


1 Answers

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.

like image 128
Josh Pittman Avatar answered Jul 06 '26 18:07

Josh Pittman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!