Firebase Firestore REST POST Request - Query and Filter using structured query

Viewed 511

URL:

https://firestore.googleapis.com/v1beta1/projects/projectname/databases/(default)/documents/:runQuery

POST buffer:

{ "structuredQuery": {"from": [{"collectionId": "example","allDescendants": true}],"where": {"fieldFilter": {"field": {"fieldPath": "Invoiceno"},"op": EQUAL,"value": {"stringValue": "1"}}}}}

Response:

[{
  "error": {
    "code": 400,
    "message": "Invalid JSON payload received. Unknown name \"{ \"structuredQuery\": {\"from\": [{\"collectionId\": \"example\",\"allDescendants\": true}],\"where\": {\"fieldFilter\": {\"field\": {\"fieldPath\": \"Invoiceno\"},\"op\": EQUAL,\"value\": {\"stringValue\": \"1\"}}}}}\": Cannot bind query parameter. Field '{ \"structuredQuery\": {\"from\": [{\"collectionId\": \"example\",\"allDescendants\": true}],\"where\": {\"fieldFilter\": {\"field\": {\"fieldPath\": \"Invoiceno\"},\"op\": EQUAL,\"value\": {\"stringValue\": \"1\"}}}}}' could not be found in request message.",
    "status": "INVALID_ARGUMENT",
    "details": [
      {
        "@type": "type.googleapis.com/google.rpc.BadRequest",
        "fieldViolations": [
          {
            "description": "Invalid JSON payload received. Unknown name \"{ \"structuredQuery\": {\"from\": [{\"collectionId\": \"example\",\"allDescendants\": true}],\"where\": {\"fieldFilter\": {\"field\": {\"fieldPath\": \"Invoiceno\"},\"op\": EQUAL,\"value\": {\"stringValue\": \"1\"}}}}}\": Cannot bind query parameter. Field '{ \"structuredQuery\": {\"from\": [{\"collectionId\": \"example\",\"allDescendants\": true}],\"where\": {\"fieldFilter\": {\"field\": {\"fieldPath\": \"Invoiceno\"},\"op\": EQUAL,\"value\": {\"stringValue\": \"1\"}}}}}' could not be found in request message."
          }
        ]
      }
    ]
  }
}
]

I have given this for POST REST function, but i am unable to get the data.

3 Answers

I believe the issue is in your fieldFilter, where you are using the op as EQUAL and it should be "EQUAL" with quotes, try changing it to the following and it should work:

"fieldFilter": 
{
    "field": 
    {
        "fieldPath": "Invoiceno"
    },
    "op": "EQUAL",
    "value": {"stringValue": "1"}
}

"fieldFilter": { "field": { "fieldPath": "Invoiceno" }, "op": "EQUAL", "value": {"stringValue": "1"} }{ "structuredQuery": {"from": [{"collectionId": "example","allDescendants": true}],"where": {"fieldFilter": {"field": {"fieldPath": "Invoiceno"},"op": EQUAL,"value": {"stringValue": "1"}}}}}

Related