Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

79
Views
FirebaseCloudFunctions only returns null

I am trying to get a response from a Firebase cloud function, but the only thing I get back is null. The console output shows that the fetch command works and outputs the correct data.

exports.create = functions.https.onCall((data, context) => {
fetch("https://mywebsite.com/x", {
    method: "POST",
    headers: {
        "Authorization": "Bearer MyKey",
        
    },
    body: JSON.stringify({"myData":data.myData})
}).then(
    function(response) {
      if (response.status !== 200) {
        console.log('Looks like there was a problem. Status Code: ' +
          response.status);
        return;
      }

      // Examine the text in the response
      response.json().then(function(data) {
        console.log(data);
        
        
      });
      return data.json();
    }
  )
  .catch(function(err) {
    console.log('Fetch Error :-S', err);
  });

});

I tried using Promise, I tried returning is as json and just as return data nothing seems to work. The result is always null

The code I use to call it in my flutter app:

HttpsCallable callable =
        FirebaseFunctions.instance.httpsCallable('create');
    final response = await callable.call(<String, dynamic>{
      'myData': 'data',
      
    }).then((value) => print(value.data));
about 4 years ago ยท Juan Pablo Isaza
1 answers
Answer question

0

You're not returning anything from the top-level code in your function, which means that Cloud Functions terminates the container when the final } executes, well before the fetch call ever completes.

To both allow the fetch call to complete and return a value to the caller, be sure to return from the top-level of your cde:

exports.create = functions.https.onCall((data, context) => {
  // ๐Ÿ‘‡
  return fetch("https://mywebsite.com/x", {
    ...
about 4 years ago ยท Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
ยฉ 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!