i am trying to fetch firebase database in functions but I can't figure out what's causing the error. here's my code
exports.test = functions.https.onCall(async (data, context) => {
console.log(data)
const sessionID = data.sessionID
const snapshot = await admin.database().ref('/test/'+sessionID).once('value');
console.log(snapshot);
return snapshot
})
this is how I am calling it from client side javascript
function callServer(){
var signInCartIn = firebase.functions().httpsCallable('signInCartIn');
var cartInfo = {
"sessionID":"23234",
"log":"6425",
"cuso_id":"cus_IP83EOJ9843s",
"pjo_id":"tm_1HoKt34xY1b"
}
signInCartIn(paymentInfo).then(function(result) {
// Read result of the Cloud Function.
}).catch(function(error) {
// Getting the Error details.
var code = error.code;
var message = error.message;
var details = error.details;
console.log(message)
// ...
})
}
I keep getting this error when I call the function
Unhandled error Error: Query.once failed: First argument must be a valid event type = "value", "child_added", "child_removed", "child_changed", or "child_moved".
what is causing the error and how can I fix it?
snapshot.val()instead of snapshot (assnapshotitself isnot a JSON object). But that shouldn't be causing the error you get. Theonce()call looks fine to me. Are you sure that error is coming from this code?