0

So I am trying to run a query with the firebase rest api using Godot

to give you an idea this is the way that I make an update for a document:

func update_document(http: HTTPRequest) -> void:
    var fields = {}
    fields.Name = {"stringValue": "Martin"}
    var document := { "fields": fields }
    var body := to_json(document)
    var url := "https://firestore.googleapis.com/v1/projects/my_project_id/databases/(default)/documents/Users"
    http.request(url, _get_request_headers(), false, HTTPClient.METHOD_PATCH, body)

Now Iam trying to make a query that return the 100 best scores, I am trying ,first, running a simple query but is not Working, it´s returning error 400:

    func query_document(http: HTTPRequest) -> void:
        var fields = {
        "structuredQuery": {
            "from": [{
                "collectionId": "Users"
                }],
            "where": {
                "fieldFilter": {
                    "field": {
                    "fieldPath": "total"
                    },
                    "op": "EQUAL",
                    "value": {
                    "intetgerValue": "10",
                    }
                }
            }
        }
                }
        var document := { "fields": fields }
        var body := to_json(document)
        var url := "https://firestore.googleapis.com/v1beta1/projects/myproject_id/databases/(default)/documents:runQuery"

http.request(url, _get_request_headers(), false, HTTPClient.METHOD_POST,body)
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • 1
    To get the top 100 scores you can use a query. See https://firebase.google.com/docs/firestore/reference/rest/v1/projects.databases.documents/runQuery and its worked data type: https://firebase.google.com/docs/firestore/reference/rest/v1/StructuredQuery – Frank van Puffelen Feb 10 '21 at 15:34
  • @FrankvanPuffelen yes but where I have tu put the query?? I am sending it in the body like when you update a document but is returning error 400 – Martin Pellicer Feb 11 '21 at 15:30
  • I find the API explorer in the pages I linked invaluable for figuring out such problems. If you're having a hard time making that work for you, it's much more likely someone can help if you edit your question to show what you tried. – Frank van Puffelen Feb 11 '21 at 15:36
  • 1
    @FrankvanPuffelen thanks, I updated the question I can´t understand the docs because it´s very different using Godot – Martin Pellicer Feb 11 '21 at 15:50

1 Answers1

0

The select was missing, adding the select make it work.