FireBase Firestore Custom ID (Post and Patch)

The following is a way to Post data to Firestore

Use Http Request from Flow Function Market and set properties below

URL

https://firestore.googleapis.com/v1/projects/[PROJECT_ID]/databases/(default)/documents/[COLLECTION_NAME]?documentId=)”+[YOUR_VARIABLE]

Replace everything in brackets with relevant information and remove brackets as well. Sample URL will be like :
https://firestore.googleapis.com/v1/projects/MyappgyverProject/databases/(default)/documents/Users?documentId=”+appVars.uid

HTTP METHOD Post

expand Optional Inputs

Headers leave as it is or change if you know what you should do

Request Body watch this videos Tutorial ( Appgyver / Firebase CRUD - 1 Setup Firebase - YouTube) 1 to 4 ,it will show you how to create or get a json body. sample body will be like :

{

“fields”: {

             "firstname": {"stringValue": "hello"} ,
             "lastname": {"stringValue": "world"} 

           }  

}

You can add more fields to the above body to get what you need.

Some of the Field data types to use : “stringValue” ,“integerValue”,“imageurl” .

Request Body Type leave as it is or change if you know what you should do

________________________________________________________

The following is a way to Patch data to Firestore

Patching is a more better way to send data or Post it, it allows you to update records or create new ones if a record with the same ID doesn’t exist. it allows you to create a new or replace the existing one. I don’t understand it well, but I’ve managed to make it work the way i need it to for now.

URL “(https://firestore.googleapis.com/v1/projects/[PROJECT_ID]/databases/(default)/documents/[COLLECTION_NAME]/)”+[YOUR_VARIABLE]

Replace everything in brackets with relevant information and remove brackets as well. Sample URL will be like :

https://firestore.googleapis.com/v1/projects/MyappgyverProject/databases/(default)/documents/Users/”+appVars.uid

HTTP METHOD Patch

expand Optional Inputs

Headers: leave as it is or change if you know what you should do

Request Body sample body will be like :

{

“fields”: {

        "firstname": {"stringValue": "hello"} ,
        "lastname": {"stringValue": "world"} 

       }  

}

Request Body Type leave as it is or change if you know what you should do

2 Likes

the editor will never let me save this when i enter it exactly like this

Hey Daniel, I don’t understand what you’re trying to say. Explain in detail or take a screen shot of what you’re trying to copy

I believe you’ve figured it out by now, but for other readers, the quotes must be correctly formatted, as follow:

{
"fields": 
    {
    "firstname": {"stringValue": "hello"}, 
    "lastname": {"stringValue": "world"}
    }
}

Thanks for sharing this precious instruction.
Just so I understand, the appVars.uid is the variable that holds the ID of the document I want to update?

Yes. In Ths case, that app variable holds uid from firebase Auth, you assign it after user login