Lindauson
Lindauson

Reputation: 3461

What format should data sent to a Google Cloud Functions onCall request be in?

I have the most simple Google onCall cloud function:

// [START]
exports.echo = functions.https.onCall(async (data, context) => {
  return {
    value: "echo"
  };
});
// [END]

I submit the following in the Google cloud console test:

{"data":"somedata"}

I am getting the following error:

{"error":{"message":"INTERNAL","status":"INTERNAL"}}

It seems there is an issue with the object that I am passing. Can anyone tell me what the correct format is? What am I missing here?

P.s: I am ultimately trying to connect an onCall function with a client application via Firebase/fire, but that is also giving the same error.


Here's the trace:

/workspace/node_modules/firebase-functions/lib/common/providers/https.js:349:16 at fixedLen (/workspace/node_modules/firebase-functions/lib/providers/https.js:66:41) at /workspace/node_modules/firebase-functions/lib/common/providers/https.js:385:32 at processTicksAndRejections (internal/process/task_queues.js:95:5) Unhandled error TypeError: res.on is not a function at /workspace/node_modules/firebase-functions/lib/common/providers/https.js:350:17 at new Promise () at /workspace/node_modules/firebase-functions/lib/common/providers/https.js:349:16 at fixedLen (/workspace/node_modules/firebase-functions/lib/providers/https.js:66:41) at /workspace/node_modules/firebase-functions/lib/common/providers/https.js:385:32 at processTicksAndRejections (internal/process/task_queues.js:95:5)


Here's the index.ts:

import * as functions from "firebase-functions";

// The Firebase Admin SDK to access Cloud Firestore.
import admin = require("firebase-admin");

// Triggers
import { echo } from "./triggers/echo"

admin.initializeApp();


// Exports
module.exports = {
    // OnCall
    echo: functions.https.onCall(echo)
};

Upvotes: 2

Views: 294

Answers (1)

Lindauson
Lindauson

Reputation: 3461

A few things:

  1. The arrow function signature was incorrect.
  2. async is not required for this synchronous response.
  3. The correct type of the context parameter is CallableContext:
import * as functions from 'firebase-functions';

export const echo = functions.https.onCall((data:any, context:functions.https.CallableContext) => ({
    value: "echo"
}))

Upvotes: 1

Related Questions