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

134
Views
Cloud Function retrieving a value based on URL parameter

I am trying to write a Cloud Function in node where I can return a token from a parameter. The URL I use is... https://us-central1-nmnm03.cloudfunctions.net/GetAccount?taccount=Asd

my function is this... and its wrong. I suspect I am not assigning TT properly.

var functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
exports.GetAccount = functions.https.onRequest((req, res) => {
        const t = admin.database().ref('/newaccout/'+req.query.account)
        const tt = t.child(token)
            res.send( "res is " + tt );
  });

req.query.account is the Key. One of the Items in the document is token ideally, I would like to get something like... {"token":"23453458885"}

Could I get a node hint please... thanks

about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Though, I am not a firebase geek. What it seems from the documentation is that you will have two events that you can use to listen for retrieving child data. You can read further more here. The given options are used for different cases. Please follow through the mentioned link to have clear view.

Inside your cloud function you can try doing following:

const t = admin.database().ref('/newaccout/'+req.query.account)
t.on('child_added', function(data) {
  res.json({
     token: data.token
  })
})

Or maybe like this:

const t = admin.database().ref('/newaccout/'+req.query.account)
t.once('value', function(snapshot) {
   //Process it like above
   //But here you will get al child elements at once
});
about 4 years ago · Santiago Trujillo Report

0

It looks like you are expecting to query the value found at a database reference stored at t. Unfortunately, you haven't actually performed a query yet. tt is just yet another Reference object that points to a location in the database. You should use the once() method on Reference to query a database location. Also bear in mind that you are using a variable called token, but you haven't defined yet in your code. To me, that looks like it would generate an error to me.

You might be well served by looking at a bunch of the sample code.

about 4 years ago · Santiago Trujillo 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!