Search code examples
restgoogle-cloud-firestore

firebase - Firestore REST API starting query


Hello I am new to firestore and I'm trying to use the rest API to query from a collection called Users, find all users who have a field called about with the value test2

This is my POST request :

https://firestore.googleapis.com/v1beta1/projects/{myprojectid}/databases/(default)/documents/Users:runQuery

Body:

{
"structuredQuery": {
    "where" : {
        "fieldFilter" : { 
        "field": {"fieldPath": "about"}, 
        "op":"EQUAL", 
        "value": {"string": "test2"}
        }
    },
    "from": [{"collectionId": "Users"}]
    }
}

I get a response

{
    "error": {
        "code": 400,
        "message": "Invalid JSON payload received. Unknown name \"structured_query\" at 'document': Cannot find field.",
        "status": "INVALID_ARGUMENT",
        "details": [
            {
                "@type": "type.googleapis.com/google.rpc.BadRequest",
                "fieldViolations": [
                    {
                        "field": "document",
                        "description": "Invalid JSON payload received. Unknown name \"structured_query\" at 'document': Cannot find field."
                    }
                ]
            }
        ]
    }
}

Can someone tell me what I am doing wrong ? Thanks a lot. I'm stuck and unable to proceed.


Solution

  • In your URL get rid of the Users.

    https://firestore.googleapis.com/v1beta1/projects/{myprojectid}/databases/(default)/documents:runQuery