Error: HTTP Error 400, The Request has errors. Firebase Firestore Cloud Functions

16,203

Solution 1

This was happening to me too, then I realized that at the 2nd level, firestore only allows documents and not collections.

I was attempting to listen to this path:

/collection/document/{wildcard}

You can either do something like

/collection/{wildcard}

or

/collection/document/collection/{wildcard}

Solution 2

I had this problem as well. In my case it was because my trigger path had a trailing slash in the document path.

So changing:

functions.firestore
  .document('some_path/{pushId}/')

To:

functions.firestore
  .document('some_path/{pushId}')

Fixed it it for me. It seems like this is caused by a variety of issues and the firebase cli does not do a good job at explaining the reasons why.

Solution 3

For me none of the answers helped me. In the end I got a list of steps (from Google) to pinpoint the problem. If you run:

firebase --debug --only functions deploy

it will give a more detailed error-message, what was in my case:

HTTP RESPONSE BODY <?xml version='1.0' encoding='UTF-8'?><Error><Code>EntityTooLarge</Code><Message>Your proposed upload is larger than the maximum object size specified in your Policy Document.</Message><Details>Content-length exceeds upper bound on range</Details></Error>

Solution 4

Okej this is what you need to look at.

since you have

exports.yourFunctionName = functions.firestore.document

the thing you need to look at is the .document

Your path MUST point to a document and not to a collection.

so this will not work :

/level1/{level1Id}/level2 <- it points to a collection

this will work :

/level1/{level1Id}/level2/{level2Id}

cloud function will look for when a document has an action

Hope this will help anybody

Solution 5

The problem is that you only reference a collection and not a document like:

exports.myFunctionName = functions.firestore
      .document('users').onWrite((event) => {
        // ... Your code here
      });

You need to reference the document like:

exports.myFunctionName = functions.firestore
  .document('users/marie').onWrite((event) => {
    // ... Your code here
  });

You can also use a wildcard like:

exports.myFunctionName = functions.firestore
  .document('users/{userId}').onWrite((event) => {
    // ... Your code here
  });

It's described in here: https://firebase.google.com/docs/functions/firestore-events

Hope I could help

Share:
16,203

Related videos on Youtube

Loyal
Author by

Loyal

Updated on June 03, 2021

Comments

  • Loyal
    Loyal about 3 years

    While I run the command firebase deploy I get this error:

    i deploying functions

    i functions: ensuring necessary APIs are enabled...

    i runtimeconfig: ensuring necessary APIs are enabled...

    ✔ runtimeconfig: all necessary APIs are enabled

    ✔ functions: all necessary APIs are enabled

    i functions: preparing functions directory for uploading...

    i functions: packaged functions (4.04 KB) for uploading

    ✔ functions: functions folder uploaded successfully

    i starting release process (may take several minutes)...

    i functions: creating function followerNotification...

    ⚠ functions: failed to create function followerNotification

    ⚠ functions: HTTP Error: 400, The request has errors

    ⚠ functions: 1 function(s) failed to be deployed.

    Functions deploy had errors. To continue deploying other features (such as >database), run: firebase deploy --except functions

    Error: Functions did not deploy properly.

    Having trouble? Try firebase deploy --help

    Everything else works without problems. Only when I trying to make something with Firebase Firestore.

  • Matt Logan
    Matt Logan about 6 years
    Same issue here! Weird that there's no descriptive error message for this.
  • Blue
    Blue over 5 years
    I feel like this is a bit more noise, then an actual answer. You've basically just implemented Nikolai's solution. You should either edit their answer to include an example, or consider gaining enough reputation for a comment/upvote.
  • Aidan Davis
    Aidan Davis over 5 years
    It's a genuine answer. I've considered gaining more reputation - and answering questions like this is the way to do so. I am just trying to add value where I can, and due to my current reputation (because I haven't spent a lot of time giving back to stack overflow, this was the only way I could).
  • Nicoara Talpes
    Nicoara Talpes about 5 years
    the first two functions are the same!
  • Cyrus Zei
    Cyrus Zei almost 5 years
    Okej, this cant be the answer since it does not matter how many levels you go. You can nest this as much as you want. Look at my answer
  • Ayyappa
    Ayyappa over 4 years
    @ivan : Easily you saved me 3-4 hours! Thanks for that :)
  • Jack
    Jack over 3 years
    Thanks! From some playing around, it looks like function names have a max length of 64 characters.
  • Masahiro Aoki
    Masahiro Aoki about 3 years
    it helped. I did not know maximum length of functions name is 63
  • Ethan
    Ethan almost 3 years
    This is the most versatile answer that can work for anyone encountering this error message, thanks!
  • ImperfectClone
    ImperfectClone almost 3 years
    I had BOTH this issue and the one from the currently-accepted answer by Ivan
  • ImperfectClone
    ImperfectClone almost 3 years
    This message is still as cryptic in July 2021, including via the web editor for cloud functions. A combination of this answer and removing an errant slash from the path as suggested in adamduren's answer was the solution for me.