Reputation: 579
Hi i am new firebase functions and trying to push data to firestore, With below code i am able to push message to firestore and it is working,
exports.addMessage = functions.https.onRequest(async (req, res) => {
// Grab the text parameter.
const original = req.query.text;
// Push the new message into Firestore using the Firebase Admin SDK.
const writeResult = await admin.firestore().collection('messages').add({original: original});
// Send back a message that we've successfully written the message
res.json({result: `Message with ID: ${writeResult.id} added.`});
});
with this url i am able to push text
http://localhost:5001/myProj/us-central1/addMessage?text=sss
I need to push some data in array of object in place of text, What changes i have to do with above code.
object like:
data: { booking_id: "0",
channels: "4",
country: "GB",
date: "2020-05-12",
currencies: "GBP",
total: "5000" }
Upvotes: 0
Views: 106
Reputation: 83058
If you want to pass an object in your Cloud Function, you should add it to the body of a POST request and parse it as explained in this part of the documentation and fully detailed in this official Sample (see the following line of code).
More concretely, in the Cloud Function you should do:
const booking_id = req.body.booking_id;
const channels = req.body.channels;
//...
and to call it via curl you should do as follows:
curl -H 'Content-Type: application/json' /
-d '{"booking_id": "0", "channels": "4", "country": "GB", ...}' /
https://us-central1-<project-id>.cloudfunctions.net/....
Upvotes: 1