Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parameters in Firebase Cloud Functions HTTPS

How can I set some parameters on my HTTPS functions in Firebase? I am building an app, and while building the app, I have managed to grow my mailing list. Now I want to send mails out, but I want to make sure that they can unsubscribe before I send anything out.

I am using Firebase for everything, and I have managed to make a function that sends mails out to every subscribed mail.

I am also able to "unsubscribe" a specific mail, but that is hardcoded, and not at all an optimal solution.

exports.testUnsub = functions.https.onRequest((req, res) => {
  var db = admin.database();
  var ref = db.ref("mailingList/-KhBOisltrOmv57Mrzus");
  ref.child("subscribed").set(false);
  console.log("-KhBOisltrOmv57Mrzus has unsubscribed from mailing list.");
});

In the mail I send there is an URL, which triggers this HTTPS function. I want to set a parameter on that URL so it becomes dynamic. Something like:

https://us-central1-<project-id>.cloudfunctions.net/testUnsub?listID=xxxxxxxxxxx

I am looking for anything that can get me on the right direction.

like image 911
Jaafar Mahdi Avatar asked Jun 25 '17 08:06

Jaafar Mahdi


1 Answers

It's important to know that the req and res parameters to your https function are Express.js Request and Response objects.

The Request object contains all the data about the request coming from the client, including the query that the client sent in the URL. It will take the form req.query.name_of_the_parameter.

like image 163
Doug Stevenson Avatar answered Nov 08 '22 12:11

Doug Stevenson