Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Cloud HTTP function by webhook: Request body is missing data

Im integrating the Zoom API with my Firebase app, and to do so I'm relying on Zooms pre-made webhooks to run an HTTP function on my Firebase for various events like "meeting started" and "meeting ended". Zoom API reference: https://marketplace.zoom.us/docs/guides/webhooks

This is the Google Cloud function that the Zoom API is calling:

exports.zoomTestA = functions.https.onCall((req, res) => {
    console.log(req);
    let data = req.body;
    var xmlData = data.toString();
    console.log(xmlData);
});

Here is the payload sent by Zoom:

{
  "event": "meeting.ended",
  "payload": {
    "account_id": "LTf-KjgUTR2df-knT8BVEw",
    "object": {
      "duration": 0,
      "start_time": "2019-05-07T14:02:51Z",
      "timezone": "",
      "topic": "Alexander Zoom Meeting",
      "id": "864370042",
      "type": 1,
      "uuid": "2h/SWVrrQMu7fcbpLUly3g==",
      "host_id": "Ty6ykNolSU2k1N4oc0NRcQ"
    }
  }

This causes this error to appear in my Google Cloud console:

Request body is missing data. { event: 'meeting.ended',
  payload: 
   { account_id: 'LTf-KjgUTR2df-knT8BVEw',
     object: 
      { duration: 0,
        start_time: '2019-04-30T14:23:44Z',
        timezone: '',
        topic: 'Alexander\'s Zoom Meeting',
        id: '837578313',
        type: 1,
        uuid: 'WotbHO3RRpSviETStKEGYA==',
        host_id: 'Ty6ykNolSU2k1N4oc0NRcQ' } } }

The request body that Zoom sends is not wrapped in in a "data: {}" tag as required by Google Cloud functions. I've found solutions to this problem if you can control the payload here: Dart json.encode is not encoding as needed by Firebase Function .

My problem is that I am unable to alter the request that the Zoom API sends. Is there any way I can still accept the request in my Google Cloud function? Or is there any way to alter the format of the request sent by Zoom? I'm unable to find references for either.

One potential solution would be to set up another server that receives the request by Zoom, format it to Google Cloud functions specifications, and then pass it on to my Google Cloud function. I would however like to avoid stepping out of the Google Cloud eco-system.

Is this problem solvable on the Google Cloud platform?

like image 744
NoteTheNote Avatar asked May 07 '19 14:05

NoteTheNote


1 Answers

So I figured it out. In Firebase / Google Cloud functions you can either make HTTP-functions with

functions.https.onCall((req, res) => { var data = req.body;

and

functions.https.onRequest((req, res) => { var data = req.body;

The difference seems to be that onCall is made for being used within the Firebase/ Google Cloud functions environment. However if you wan external functions you need to use onRequest as this does not require specific formatting of the payload.

Using onRequest instead solved all my problems.

like image 140
NoteTheNote Avatar answered Sep 24 '22 13:09

NoteTheNote