Home > Mobile >  Error 400: unable to create collection using Firestore rest API
Error 400: unable to create collection using Firestore rest API

Time:12-12

I'm trying to create a collection inside FIRESTORE by making a REST API call.

My current URL for this request is:

https://firestore.googleapis.com/v1/projects/mountain-bear-****/databases/(default)/documents/?collectionId=<new-collection>

I'm getting this error:

The requested URL /v1/projects/mountain-bear-****/databases/(default)/documents/?collectionId=grofers was not found on this server. That’s all we know.

I'm not sure if this is the way REST API calls for creating a collection has to be made. I tried looking at the docs and came back without finding much help.

What I'm trying to acheive:

  1. Create a collection with a custom name

Any help on this matter is highly appreciated

CodePudding user response:

With Firestore we don't create a Collection as such. A new Collection is created when the first Document of this Collection is created.

So for creating a doc in a new abcd collection, according to the REST API documentation, you need to call the following URL (see abcd at the end of the URL)

https://firestore.googleapis.com/v1/projects/mountain-bear-****/databases/(default)/documents/abcd

with a POST request and the request body shall contain an instance of a Document.

  • Related