Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why firebase emulator function says request body is missing data?

I'm running my local emulator suite and I'm constantly getting error messages for my curl requests. The following command:

curl -X POST http://localhost:5001/my-project/us-central1/myFunction \
    -H "Content-Type: application/json" \
    -d '{"productId": 123456, "quantity": 100}'  

Is always showing this in the emulator CLI:

>  {"productId":123456,"quantity":100,"severity":"WARNING","message":"Request body is missing data."}
>  {"severity":"ERROR","message":"Invalid request, unable to process."}

None of the code was executed in the function as it starts with a console log which is never printed here. Any thoughts?

like image 299
Mr.Drew Avatar asked Jun 16 '26 22:06

Mr.Drew


1 Answers

That error occurs when you use the onCall method. So, I would assume that you are using functions.https.onCall. As explained in this documentation:

It's important to keep in mind that HTTPS callable functions are similar but not identical to HTTP functions. To use HTTPS callable functions you must use the client SDK for your platform together with the functions.https backend API (or implement the protocol).

If you want to directly call the function via its endpoint then you should follow the protocol specification for https.onCall. One of its requirements is the request body should be a JSON object with data as its main key.

An example request JSON object should be like this instead:

{
    "data": {
        "productId": 123456,
        "quantity": 100
    }
}

For reference, here's the full curl request:

curl -X POST http://localhost:5001/my-project/us-central1/myFunction \
    -H "Content-Type: application/json" \
    -d '{ "data": { "productId": 123456, "quantity": 100 } }' 

For more information, you may check out this documentation:

  • Protocol specification for https.onCall
like image 124
Marc Anthony B Avatar answered Jun 19 '26 14:06

Marc Anthony B



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!