Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FireStore REST API call

I am using postman to get data from my firestore api

https://firestore.googleapis.com/v1beta1/projects/myapp-ef511/databases/countries

but I am getting this,although my rules are public

{
    "error": {
        "code": 401,
        "message": "Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.",
        "status": "UNAUTHENTICATED"
    }
}

How can I achieve this?I am planning to use retrofit in future.

like image 618
Katy Colins Avatar asked Feb 01 '18 09:02

Katy Colins


2 Answers

Go to Firebase console and follow the below steps.

  1. Go to Project Settings (top left corner gear icon)
  2. In General tab -> Under 'Your project' section it will show Project ID & Web API Key (will use it in url) enter image description here

  3. Now go to your Firestore database and get the document name e-g users

enter image description here

Finally just hit the below url with your desired values of Project ID, Web API Key and Document

https://firestore.googleapis.com/v1/projects/[Project ID]/databases/(default)/documents/[Document]?key=[Web API Key]

Example of real url:

https://firestore.googleapis.com/v1/projects/firestore-rest-api-test/databases/(default)/documents/players?key=AIzaSyDsCtB9PiFTtkJiDRmFEakbKvoohPRAGJU

NOTE: make sure you set your project rules on test mode to make it work. Otherwise use authentication first to make it work

like image 151
Shujat Munawar Avatar answered Oct 02 '22 17:10

Shujat Munawar


The REST API requires either a Firebase Authentication ID token or Google Identity OAuth 2.0 token. The main difference between the two is that a Firebase Auth ID applies security rules and the Google ID does not. This guide on working with the Firestore REST API should help.

like image 41
Juan Lara Avatar answered Oct 02 '22 17:10

Juan Lara