beck
beck

Reputation: 3027

How can I access Firestore database via http-get restful API?

I've created an cloud firebase type database in firebase. Plz have a look at the image below. But How to access the datas from API(get)? If I use real time database, simply 'https://[PROJECT_ID].firebaseio.com/users/jack/name.json' this url gives the json data. But using cloud firebase database, I'm unable to get json data. I've tried to use "https://firestore.googleapis.com/v1beta1/EmployeeApp/name=employeeapp-66646/newsFeed/" but it doesn't work.

enter image description here

Upvotes: 9

Views: 7567

Answers (2)

Frank van Puffelen
Frank van Puffelen

Reputation: 598708

Here is an example of a URL for one of my databases:

https://firestore.googleapis.com/v1beta1/projects/project-8080059325282098184/databases/(default)/documents/52679469/docid

An explanation of the variable parts in here:

  • project-8080059325282098184 is my project ID.
  • (default) is the name of the database. At the moment you can't specify a name for your database, so yours will be (default) too.
  • 52679469 is the name of my collection.
  • docid is the name of my document

The JSON I get back:

{
  "name": "projects/project-8080059325282098184/databases/(default)/documents/52679469/docid",
  "fields": {
    "field1": {
      "stringValue": "value1"
    }
  },
  "createTime": "2018-10-06T14:16:24.090837Z",
  "updateTime": "2018-10-06T14:16:24.090837Z"
}

In this response:

  • name is the full path of this document.
  • fields is the data of the document.
  • createTime and updateTime are the metadata for the document.

Upvotes: 22

Renaud Tarnec
Renaud Tarnec

Reputation: 83058

The following URL will do the trick:

https://firestore.googleapis.com/v1beta1/projects/employeeapp-66646/databases/(default)/documents/newsFeed

Have a look at the doc here, for detail on how to build the URL.

Upvotes: 8

Related Questions