0

I have a Google AppScript that appends one single row to a Google Sheet. The post works fine when I use Postman, and the row is added as expected. Now I am using Firebase Functions to post in an onCreate. In node.js:

exports.userOnCreate = functions.firestore.document('User/{uid}').onCreate(async (userSnap, context) => {
    if (userSnap.data().subscribe) {
        const data = {
            submittedOn: Date.now(),
            email: userSnap.data().email,
        };

        await axios.post(GOOGLE_SHEETS_SUBSCRIBE, data)
            .then((res) => {
                console.log(`Status: ${res.status}`);
                console.log('Body: ', res.data);
            }).
            catch((err) => {
                console.error(err);
            })
    }
});

My Functions log shows it returns with a status of 200, but the row is not added. In my AppScript executions log, it shows Running for 60 seconds, and then updates to Unknown status.

I have 'execute the app as me', and 'allow access to anyone, even anonymous.'

Please help! Thank you.

Candace
  • 81
  • 7
  • Show your apps script. Add console.log() at each step and see which line causes the problem. You may need to switch to standard Google cloud project to view logs – TheMaster Sep 23 '20 at 20:51
  • I am really struggling to find the logs. I am not sure how to switch GCP. I am in GCP but not sure how it links to Apps Scripts. I can see logs there but it doesn't have any of the output I am looking for. – Candace Sep 24 '20 at 15:29
  • See https://stackoverflow.com/a/63851123 and https://stackoverflow.com/a/64002160/ – TheMaster Sep 24 '20 at 15:35
  • 1
    thank you very much – Candace Sep 24 '20 at 16:21

1 Answers1

0

There was an issue with axios not sending the data. I had to install qs and change the post to:

await axios.post(GOOGLE_SHEETS_SUBSCRIBE, qs.stringify(data))
Candace
  • 81
  • 7