Reputation: 1254
I need to extract the params from http url in firestore cloud function,
HTTP URL
https://us-central-xxxxxxxxxxx.cloudfunctions.net/somefunction?name=ABC&age=80
Firestore Cloud function
export const somefunction = functions.https.onRequest(async (request, response) => {
var name = // need to extract name from request
var age = // similarly need to extract age from request
}
Can anyone help me out with this ?
Upvotes: 4
Views: 4817
Reputation: 3667
I have a similar issue where I cannot get req.url
and req.query.abc
as asked in Cannot get req.path and req.query.abc with firebase functions
As mentioned in the comments of Call Firebase cloud function via GET and return parameters this is happening only on development.
After searching for a long time I came across this article https://howtofirebase.com/cloud-functions-migrating-to-node-8-9640731a8acc where it said firebase-tools
have to be of 4.0.0 version. I've updated my firebase-tools
to 4.0.0 and I can get the query parameters normally
Upvotes: 1
Reputation: 3713
You can use the request
object to access the query parameters similar to what you do in Express Js
export const somefunction = functions.https.onRequest(async (request, response) => {
var name = request.query.name
var age = request.query.age
}
If the request was from a POST request then you can use request.body.*
for accessing values.
Upvotes: 6