Reputation: 177
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".
This is the current look of my Realtime Database:
This is the current look of my Cloud Firestore:
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:
After click SEND on Postman, the write to the REALTIME DATABASE occurs in fact:
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:
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.
Upvotes: 0
Views: 454
Reputation: 26333
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.
Upvotes: 1