58

Trying to make a request to Paypal's API using PayPal-node-SDK

exports.requestPayment = functions.https.onRequest((req, res) => {
    return new Promise(function (fullfilled, rejected) {
        paypal.payment.create(create_payment_json, {}, function (error, payment) {
            if (error) {
                rejected(error);
            } else {
                console.log("Create Payment Response");
                console.log(payment);
                res.status(200).send(JSON.stringify({
                    paymentID: payment.id
                })).end();
                fullfilled(payment);
            }
        });
     });
});

but I'm constantly getting an error:

Error: getaddrinfo ENOTFOUND api.sandbox.paypal.com api.sandbox.paypal.com:443
    at errnoException (dns.js:28:10)
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:76:26)

Things I've tried:

  1. Making a request to a totally different host, still ENOTFOUND
  2. Wrapping the request with cors(req,res, ()=>{...})
  3. Prepending https:// to the host

What is the problem?

Doug Stevenson
  • 236,239
  • 27
  • 275
  • 302
user47376
  • 2,173
  • 2
  • 17
  • 26

5 Answers5

126

You'll need to be on a paid plan to make external API requests.

Firebase's Blaze plan (pay as you go) has a free allotment for Cloud Functions. https://firebase.google.com/pricing/

James Daniels
  • 6,324
  • 4
  • 20
  • 26
  • 1
    Any reference to it? I have the same issue and before I make a purchase I'd like to know for sure that it's the issue. – Alx Mar 14 '17 at 11:40
  • 3
    You should see warnings on your function logs + it's probably buried on the pricing page somewhere. BTW I'm a DevRel on Cloud Functions for Firebase ;) – James Daniels Mar 14 '17 at 18:22
  • 2
    Footnote 3: The Spark plan only allows outbound network requests to Google owned services. On the Blaze plan, Cloud Functions provides a perpetual free tier. – James Daniels Mar 14 '17 at 18:23
  • 2
    Thanks for details! Really appreciate it. Once I pulled out my creditcard it worked just as expected! – Alx Mar 17 '17 at 22:34
  • 4
    This saved me an extra hour or two of debugging. Thanks! – wooters May 11 '17 at 02:38
  • 3
    Is this the same for a call to api hosted on another project's cloud function? I am getting `getaddrinfo ENOTFOUND` error when I do isomorphic-fetch to `https://us-central1-joanne-lee.cloudfunctions.net/getUrls/portrait` – bob Jan 15 '18 at 21:20
  • Ohhhhhh dearr, you know when you sit there, and you just can't figure it out ... well thank you James, your answer has saved me. – Michael Stokes May 18 '18 at 19:55
  • 1
    I had a problem accessing `script.google.com/macros/s/.../exec`. I circumvented the limitation using the Apps Script API. It's conceivable you can call external resources in Apps Script, and then use Firebase to call the Apps Script. See https://gist.github.com/dan1wang/baf25ff2a45e6c53880e89185b0f29da – daniel May 31 '18 at 16:46
  • 1
    When comparing the The Blaze Plan prices you may see some small fees of around 10 cents for millions or thousands of calls, but actually you get to use up the Spark plans free quota before you're even using the blaze plan quotas. https://stackoverflow.com/questions/45683767/does-firebase-blaze-plan-have-the-spark-plans-quota#answer-45684576 – SeanMC Mar 01 '19 at 02:47
  • 1
    after I upgraded to the blaze plan, my application is now able to make external calls – BipinR Mar 19 '19 at 03:02
  • 1
    @SeanMC: Thanks for that good information. Now when developing I can just switch to Blaze plan and don't need to care about this issue – Hoang Trinh Aug 27 '19 at 06:56
  • I chose blaze plan, even after that I am seeing same error. helloWorld: Function execution started 2020-04-04T20:46:07.525152372Z D helloWorld: Billing account not configured. External network is not accessible and quotas are severely limited. – Amrit Raj Apr 04 '20 at 20:52
3

in my situation I had to wait and let what ever lag was happening pass. Now it's fine again.

1

You need to include service account to the admin initialization. this fixed the same issue for me

EngrEric
  • 4,134
  • 1
  • 5
  • 6
1

Switch to the Firebase "Blaze" plan, which includes the free usage tier of the Spark plan before incurring any costs. Use the Blaze pricing calculator to see what you'd be charged for a given usage.

The first 5GB of outbound (egress) networking is free, which is the same as what "native" Google Cloud Functions would give you.

kynan
  • 11,847
  • 6
  • 71
  • 79
0

I was having this issue because of weak internet, change the internet connection.