Asked  6 Months ago    Answers:  5   Viewed   107 times

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) {
            } else {
                console.log("Create Payment Response");

but I'm constantly getting an error:

Error: getaddrinfo ENOTFOUND
    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?



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.

Tuesday, June 1, 2021
answered 6 Months ago

Update 2019-04-18

There is now a very simple way to deploy scheduled code on Cloud Functions through Firebase.

You can either use a simple text syntax:

export scheduledFunctionPlainEnglish =
functions.pubsub.schedule('every 5 minutes').onRun((context) => {
    console.log('This will be run every 5 minutes!');

Or the more flexible cron table format:

export scheduledFunctionCrontab =
functions.pubsub.schedule('5 11 * * *').onRun((context) => {
    console.log('This will be run every day at 11:05 AM UTC!');

To learn more about this, see:

  • The Scheduling Cloud Functions for Firebase blog post introducing the feature.
  • The documentation on scheduled functions.

Note that your project needs to be on a Blaze plan for this to work, so I'm leaving the alternative options below for reference.

If you want to schedule a single invocation of a Cloud Function on a delay from within the execution of another trigger, you can use Cloud Tasks to set that up. Read this article for an extended example of how that can work.

Original answer below...

There is no built-in runat/cron type trigger yet.

For the moment, the best option is to use an external service to trigger a HTTP function periodically. See this sample in the functions-samples repo for more information. Or use the recently introduced Google Cloud Scheduler to trigger Cloud Functions through PubSub or HTTPS:

enter image description here

I also highly recommend reading this post on the Firebase blog: How to Schedule (Cron) Jobs with Cloud Functions for Firebase and this video: Timing Cloud Functions for Firebase using an HTTP Trigger and Cron.

That last link uses to trigger Cloud Functions, and works for projects that are on a free plan. Note that this allows anyone to call your function without authorization, so you may want to include some abuse protection mechanism in the code itself.

Tuesday, June 1, 2021
answered 6 Months ago

The most likely cause for something like this has nothing to do with your code - it has to do with the Firebase plan you're subscribed to.

The "Spark plan", which is the completely free tier (and the one most people start off with), does not allow outbound networking connections except to Google's HTTPS services.

Even for development and testing, I suggest going with the "Blaze plan". It allows for network connections. Although it does have utilization prices listed (both for processing and network connections), the Info button indicates that there is a free usage level each month before these prices kick in, and that level is generally enough to do development and testing.

Friday, July 30, 2021
answered 4 Months ago

I see three steps in here:

  1. Calling a Cloud Function from Android.

    This is the same as calling any other HTTP URL from Android. See Calling a Cloud Function from Android through Firebase

  2. Parsing parameters from the call in your Cloud Function

    A HTTP triggered Cloud Function is really just an Express handler. So parsing the post works the same as for other Express handlers. The Firebase documentation for HTTP functions has some examples and links to other documentation.

  3. Posting to the database from a Cloud Functions

    All the samples in the functions-samples repo include the Firebase Admin SDK. This SDK allows you to access many Firebase features, such as the database, from within your function. But there's also an example in this repo.

Friday, August 20, 2021
answered 4 Months ago

After talking with Firebase support, I learned this bug was introduced in the npm dependency @firebase/database: 0.1.10. You will have this dependency if you also have the latest firebase-admin dependency.

The warning

shouldn't have any impact on the function's overall processing.

If you want to remove the warning, you can force the npm dependency of @firebase/database: 0.1.9. I tested this adjustment and the warning was removed from my Firebase Console Logs.

The support agent also stated the fix has been made, but not released, so I would expect @firebase/database: 0.1.11+ to not experience this bug.

Monday, September 27, 2021
Michał Turczyn
answered 2 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :