This is the REST API call I make to create a new document in my firestore database
POST https://firestore.googleapis.com/v1beta1/projects/[xxx]/databases/(default)/documents/items
Here is the payload that I add to the body of the post method:
{
"name": "projects/[xxx]/databases/(default)/documents/items/6001156905205",
"fields": {
"Name": {
"stringValue": "Freshpak Rooibos Tea 80Pk"
},
"Description": {
"stringValue": "Enjoy a cup of Freshpak Rooibos your no 1 Rooibos tea.
}
},
"createTime": "2018-02-21T14:20:55.753234Z",
"updateTime": "2018-02-21T14:20:55.753234Z"
}
I get the below error message:
{
"error": {
"code": 400,
"message": "document.name must not be set",
"status": "INVALID_ARGUMENT"
}
}
When I remove the "name" property from the payload it creates the record in firebase but the document Id is then auto generated. I would like the Id to be 6001156905205.
Am I doing something wrong?
Thanks Gert
You need to specify the document ID that you want to use, as a query parameter, as detailed here. The createTime and updateTime are output only, so they will automatically be set by Cloud Firestore.
POST https://firestore.googleapis.com/v1beta1/projects/[xxx]/databases/(default)/documents/items?documentId=6001156905205
{
"fields": {
"Name": {
"stringValue": "Freshpak Rooibos Tea 80Pk"
},
"Description": {
"stringValue": "Enjoy a cup of Freshpak Rooibos your no 1 Rooibos tea.
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With