Updating specific fields to rest API

So I have been working on a barcode app for a while now, I managed to get it to work with an API that I created with Firebase realtime database.

To get the data from my API, everything works great, I even made an update record and create record in my data ressource, tested it, everything works. From there I can create new products and update all the fields but if I leave one blank it will stay blank in my database…

I have built an app to scan a barcode and check if that barcode is in my database, if it is it brings me to my update page and if it isn’t it brings me to a create new page. Up to now it all works but on my update page I cannot seem to get thelogic right so that I can change some fields and update them in my database…

What I want my app to do is this:
-Main page
-scan barcode
-if barcode exists, open “update page”
-on update page all the fields display the data fetched from the API
-I can then make changes to one or more fields
-after changes made I click a button that saves data in API

-if barcode does not exists, open “create new” page
-barcode is created in database and I can fill in all the fields for my API
-click on button to save the new barcode and all its children nodes from the fields I filled in.

I know to some this might seem really easy, but I am a newbie, I have watched a bunch of videos and read a lot but I can’t seem to find what I need to make this work.
If anyone can help me out that would be greatly appreciated, btw I love this community and you guys/girls are amazing!!

Hi Michael,

Im developing something similar, in your case, if you want to update some fields to specific document, you can use REST API PATCH METHOD (please consider if you doesn’t pass some existing field in the database through the request, it won’t be updated):

https://firestore.googleapis.com/v1/{your_project_id}/databases/(default)/documents/{Collection_id}/{Document_id}?updateMask.fieldPaths={fieldName1}&updateMask.fieldPaths={fieldName2}&updateMask.fieldPaths={fieldNameX}

And in the request body, you should pass the information to be updated into the field, something like this:

{fields: {"commune_name": {"stringValue": pageVars.test}, "commune_price": {"integerValue": pageVars.price}}}

I highly recommend this topic, it really helps to do almost everything with REST API:

Updating single fields and other random Firebase REST API tips - Community guide - AppGyver

Hope this can help you.

Hey Pedro thanks for the response, where and how exactly do I use the patch method? Is it in the formulas from the bindings, or do I need to make a new data variable to apply this method?

Use HTTP Request flow function for PATCH, you can find it from the flow marketplace :slight_smile: