Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firestore REST API database listening

Do you know how to setup Firestore listening using REST API. This is my attempt:

url: "https://firestore.googleapis.com/v1beta1/projects/project_name/databases/(default)/documents:listen"
headers: {["Content-Type"] = "application/json"}

body: "{"addTarget": { 
            "once" : false, 
            "documents" : { 
                    "documents" : [ "projects/project_name/databases/(default)/documents/Users/USER_DOC_ID" ]
                        }
            }}"

Request verb: POST 

And the response:

  [{
    "error": {
      "code": 400,
      "message": "Invalid value (Object), ",
      "status": "INVALID_ARGUMENT",
      "details": [
        {
          "@type": "type.googleapis.com/google.rpc.BadRequest",
          "fieldViolations": [
            {
              "description": "Invalid value (Object), "
            }
          ]
        }
      ]
    }
  }
  ]

Most propably, my request body is invalid. I used this reference: https://firebase.google.com/docs/reference/rest/firestore/v1beta1/projects.databases/listen

How is the body should look like? Thanks in advance.

like image 656
Rajju Avatar asked Nov 09 '17 13:11

Rajju


People also ask

How do I listen to changes on Firestore?

You can listen to a document with the onSnapshot() method. An initial call using the callback you provide creates a document snapshot immediately with the current contents of the single document. Then, each time the contents change, another call updates the document snapshot.

When should you not use Firestore?

If you have a very time-sensitive app, like online auctions where you can't have unpredictable delays (no one likes to lose because of something that we don't control), you shouldn't really use Firestore. You will have a hard time hiding the hiccups and you will only anger your users.

Can I use REST API with Firebase?

We can use any Firebase Realtime Database URL as a REST endpoint. All we need to do is append . json to the end of the URL and send a request from our favorite HTTPS client.


1 Answers

The listen method is not available through the REST API. It is available through the RPC API.

like image 186
Juan Lara Avatar answered Oct 06 '22 05:10

Juan Lara