Does firestore have a json url to show data? - firebase

with firebase I use these urls a lot to quickly view my data in the browser:
- https://YOUR_DB.firebaseio.com/YOUR_COLLECTION.json
- https://YOUR_DB.firebaseio.com/YOUR_COLLECTION/YOUR_DOCUMENT.json
It gives a json representation of the data for that particular collection or document.
Is there an equivalent in Firestore?

Those URLs are the REST API of the Firebase Realtime Database.
While there is a REST API for Cloud Firestore it works very differently.

Related

How to automatically set updatedAt and createdAt on a Firebase document using PATCH over REST API?

We use the Firebase REST API, specifically the PATCH method to both create and update documents in Firestore.
How do we get Google Firestore to behave like a DB by auto-populating createdAt and updatedAt fields in the documents with SERVER side values?
Again REST API is what we're using.
Thanks.
Didn't see anything in Google's docs and read a lot of chaos on the topic in various blogs.
Firestore is a NoSQL database and does not support auto generated timestamp fields. Even in databases like MongoDB, usually ORMs like Mongoose are used handle this. You would have to manually add those 2 fields are included in all requests and use security rules to ensure that values in the request are valid.
Checkout Cloud Firestore REST API - Add server timestamp to use serverTimestamp() with REST API so you won't have to pass actual timestamps from client side.
In case you use Firebase SDKs later, you can use converters as mentioned in this answer Add auto created_by and create_at fields in firestore.

Always returns null in Firebase REST API with postman

I'm trying to send a request for My firebase database to get all the data by Postman and my data inserted manually but always the result is null
and my URL is
I tried two below URLs with no luck:
https://myprojectId.firebaseio.com/mycollectionName.json?auth=Database secret Auth
and
https://myprojectId.firebaseio.com/rest/mycollectionName.json?auth=Database secret Auth
The URLs you are using are for the Realtime Database REST API, not for the Cloud Firestore REST API.
The doc for the Cloud Firestore REST API is here. Look at this specific section for fetching documents and collections.

Postman API to connect to Firebase Realtime DB

I am confused as to how to connect to my Firebase DB using, say Postman to send the REST requests.
In the screenshot below, you can see my DB structure and GET request.
Specifically, the GET request in Postman looks like this,
https://fir-crud-api-b1cec.firebaseio.com/products/test.json?auth=xxxx
while the DB is structured as such
products > test.json
Would appreciate any advice to point me in the right direction. Thanks!
Your URL suggests that you want to use the Realtime Datbase REST API, but your screenshot suggests that your data is in Firestore. These are different databases with different APIs.
If you want to work with data in Firestore, you should use the Firestore REST API instead.
The screenshot on the left shows the Cloud Firestore database, while in PostMan you are trying to access the Realtime Database. While both databases are part of Firebase, they're completely separate, and have completely separate REST APIs.
If you want to access Cloud Firestore from PostMan, have a look at its REST API. Fair warning that this API is significantly more complex than the one for the Realtime Database.
If you want to continue using the Realtime Database REST API, make sure to create your data structure in the Realtime Database in the Firebase console.

Can we push data into firebase real time database using url query string?

i want push some data to my real time database firebase, I have my database structure like this
I've successfully done inserting data using query string with PHP using $_GET method in free web hosting, but it has limited hit request and i don't want to pay for web hosting, since I know firebase is free, I would like to use it.
ok so, i want to push the data using url query string. when i hit the url like
https://gps-iot-8a30e.firebaseio.com/koordinat?created_at=2020-01-01&latitude=6.231435&longitude=6.231454
the data should be added to 'koordinat' reference and automatically generate the key id. is there any way to insert data like that? What should i do? should I make some sort of REST API server? any help would be appreciated. thanks.
There is no way to add data to the Firebase Realtime Database REST API with a GET request. The new data will always have to be in the body of the request, which GET requests don't support.
See the Firebase documentation on ways to save data with the REST API.
What you can do is create a custom endpoint on for example Cloud Functions that takes the request you send from your PHP, and then converts that into a format that the Realtime Database supports. If you're doing this on Cloud Functions, you might as well use the Node.js SDK that Firebase provides, instead of dealing with the REST API there.

How do I authenticate Firebase functions/admin requests to Firestore

I was able to complete the process of generating a Firebase auth token on the front end, sending it to a Firebase Cloud Function, and using auth.verifyIdToken to decode it and pull out the user ID.
I want to use Cloud Firestore, but I have no idea how to use the user token/ID when making requests to Cloud Firestore from Firebase Functions. My goal is to then have those variables available when creating Cloud Firestore security rules.
a) Do I need to pass those variables in the Firestore request?
Example:
postsRef.where({uid //somehow?}, 'published', '==', true).get();
b) Should I use auth.setCustomUserClaims? Is that the only option when working from the Admin SDK?
c) What is different in usage between the ID and the decoded token? Should I pass both to Cloud Firestore? Is that even possible?
Let me know what you think, any info is helpful.
Thanks,
What you're trying to do is actually not possible. When you query Firestore from backend code using one of the server SDKs (including the Firebase Admin SDK), the query will always bypass all security rules. There is no way to change this behavior. Rules only apply to direct access from web and mobile clients.
What you'll have to do instead is duplicate the work of the rule in your backend code to make sure all the conditions are correct before making your query.

Resources