0

My firestore DB structure: 2020/abhishek/friend-requests/ where 2020 is a collection, abhishek is a document and friend-requests is a collection inside the document.

What am I trying to do?

I'm trying to create a new document inside friend-requests using REST API.

What I did so far?

I made a POST request to this endpoint: https://firestore.googleapis.com/v1/projects/fuze-eee88/databases/(default)/documents/2020/abhishek/friend-requests/?documentId=newdocument

Request body:

{
  "fields": {
    "status": {
      "booleanValue":"true"
    }
  }
}

The error I get:

{
    "error": {
        "code": 400,
        "message": "Document parent name \"projects/fuze-eee88/databases/(default)/documents/2020//abhishek\" lacks a resource id at index 55.",
        "status": "INVALID_ARGUMENT"
    }
}
0

1 Answer 1

0

Seems you are getting that error because the document with the ID newdocument already exists in your Firestore database.You have to choose a unique ID for every new document that you add to Firestore database. You may try using a different ID, such as newdocument1 instead of new document.

You can have a look at below sample url

https://firestore.googleapis.com/v1/projects/<YOUR_PROJECT_ID>/databases/(default)/documents/<YOUR_COLLECTION_NAME>/<YOUR_DOCUMENT_ID>/<YOUR_SUBCOLLECTION_NAME>/?documentId=<YOUR_UNIQUE_ID>

After editing the above url as per your configuration will become:

https://firestore.googleapis.com/v1/projects/fuze-eee88/databases/(default)/documents/2020/abhishek/friend-requests/?documentId=newdocument1

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

Comments

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.