How to call Firebase Callable Functions with HTTP?

11,330

Solution 1

EDIT: The details of the protocol have been formally documented now.

HTTPS Callable functions must be called using the POST method, the Content-Type must be application/json or application/json; charset=utf-8, and the body must contain a field called data for the data to be passed to the method.

Example body:

{
    "data": {
        "aString": "some string",
        "anInt": 57,
        "aFloat": 1.23
    }
}

If you are calling a function by creating your own http request, you may find it more flexible to use a regular HTTPS function instead.

Solution 2

You can use Firebase CLI firebase functions:shell to invoke onCall(..) functions.

A significant bonus with this approach is that from the shell you can run the functions available in your local env. - Firestore calls, etc - without having to actually deploy those functions to the cloud project.

Steps:

  1. Run cmd: firebase functions:shell
  • This will give you the prompt firebase >
  1. At the prompt call the func, and pass empty body if no params
  • firebase > someFuncAbc({})

Thanks to answer in this thread: https://stackoverflow.com/a/62051894/2162226

Yes, this answer deviates from the OP that requests how to do this with HTTP .. but adding here as an alternate way to make the calls simply from the CLI, without having to set HTTP headers, set up the HTTP client like curl or Postman, etc.

Share:
11,330
creativecreatorormaybenot
Author by

creativecreatorormaybenot

Updated on June 09, 2022

Comments

  • creativecreatorormaybenot
    creativecreatorormaybenot about 2 years

    I realised that the new Callable Cloud Functions can still be called as if they were HTTP events, i.e. they can still be reached under http://us-central1-$projectname.cloudfunctions.net/$functionname. When doing that I receive an error message in my Cloud Functions Log:

    Request has invalid method. GET 
    

    This means that HTTP-GET does not work, but is there a way to call the functions? Maybe they are using HTTP-CONNECT.