0

Maybe a duplicated question, but this time I have tried my best in my explanation.

Being on my Firebase console, when I click on "Database" option on the left side of the screen, it is presented to me that we have two different databases, the "Realtime Database" and the "Cloud Firestore".

enter image description here

This is the current look of my Realtime Database:

enter image description here

This is the current look of my Cloud Firestore:

enter image description here

REALTIME DATABASE TEST

On Postman, I do select PATCH option, and to define what I will put on the address bar, I follow the synthax:

https://PROJECT-NAME.firebaseio.com/PATH.json?auth=YOUR-DATABASE-SECRET-CODE

For me, it becomes:

https://eletronica-ab6b1.firebaseio.com/database333.json?auth=DZSQwLoNWAneWA9BcEfAgnelmY965pq98HF4pIT0

That's not my real secret key, don't worry.

And as content of my request, I go to Body, select 'raw' and 'JSON' on the list, and below is the content:

{"name": "PAUL"}

Exactly as you can see here:

enter image description here

After click SEND on Postman, the write to the REALTIME DATABASE occurs in fact:

enter image description here

So the write to REALTIME DATABASE is working via Postman.

CLOUD FIRESTORE TEST

Here is my problem, I'm not having sucess with Cloud Firestore.

On Postman, I do select GET option, and to define what I will put on the address bar, I follow the synthax:

https://firestore.googleapis.com/v1/projects/YOUR_PROJECT_ID/databases/(default)/documents/COLLECTION/DOCUMENT

For me, it becomes:

https://firestore.googleapis.com/v1/projects/eletronica-ab6b1/databases/(default)/documents/colA/docA.json?auth=DZSQwLoNWAneWA9BcEfAgnelmY965pq98HF4pIT0

Exactly as you can see here:

enter image description here

And I do receive this message as response:

{
  "error": {
    "code": 400,
    "message": "Invalid JSON payload received. Unknown name \"auth\": Cannot bind query parameter. Field 'auth' 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 \"auth\": Cannot bind query parameter. Field 'auth' could not be found in request message."
          }
        ]
      }
    ]
  }
}

It is strange that if I try to change the project name on the request, for example, from original "eletronica-ab6b1" to "eletronica-999zzz", shomething that should not exist, the response is the same as above, exactly the same.

Why it is so easy to write to REALTIME DATABASE and seems to be not easy to write to CLOUD FIRESTORE DATABASE? Is it not possible to write to Cloud Firestore in a simple way like is done with Realtime Database? Is Cloud Firestore based on tokens? If yes, how do I get a token via Postman, and then use that token to write to Cloud Firestore database?

Regards.

1 Answer 1

1

Cloud Firestore does not support access via secret key. To use the REST API you will need a Google OAuth access token (for administrative access) or a Firebase Auth ID Token (normal user access). It will then need to be passed to the server in an Authorization header of the form:

Authorization: Bearer ${insert_token_here}

I'd recommend reading the docs for additional information about how to obtain the appropriate tokens.

Sign up to request clarification or add additional context in comments.

2 Comments

Ok, thanks, I understtod the header. But about get a "Firebase Auth ID Token", how could I get one token in a simplier way than using any type of code? Can I get or create a token inside the console? I don't like these documentations from Firebase.
The Google OAuth Playground has some pretty simple steps for getting an access token, but both ID Tokens and Access Tokens expire after an hour for security reasons so it's not something you'll be able to just keep around.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.