Updating single fields and other random Firebase REST API tips

Dear amazing people,

I have been using Appgyver for exactly a month today, and while it has been hard for me as a non-tech newbie, I learnt quite a ton. I have collated micro documentation of the major tips I learnt on the way and thought it might be helpful for other Firebase backend users.

Tips currently cut across Authentication, updating documents fields and many more. I highly encourage collaboration to add to this list of tips, and I hope you find these as useful as I did.

Ooh, and if you find another lost copy of this on the forum kindly alert me, I had tried to upload this earlier and had bad internet connection so I don’t know here that went.

Cheers.

REST API

How to Update a document using the PATCH method for REST API.

Use the following URL.

How to Update a single field using the PATCH method for REST API. Reference Resources

Use the following URL.

How to get a document using GET method for REST API

Use the following URL.

How to get a field from a document using Get method for REST API

Use the following URL.

How to get a collection of documents using REST API

Use the following URL.

How to delete a one or more field(s) form a document using PATCH method for REST

Use the following URL. However, in the body of the HTTP request, do not add any update for the field. This does the function of deleting only that field.

How to create one or more new field(s) into a document using PATCH method for REST

Use the following URL. IN the body of the HTTP request, write the field name as key and Value only.

How to create a document using POST method for REST

Use the following URL. In the body of the HTTP request, write the intended field of the document.

How to create a document, with an assigned documentID using POST method for REST

Use the following URL, ensure to add ?documentid={DocumentID}. In the body of the HTTP request, write the intended field of the document.

How to create Subcollection with a Document inside of it using POST method for REST

Use the following URL. In the body of the HTTP request, write the intended field of the document.

How to store a file in Firebase storage and connect it to you database Using POST method on REST API

Use the following URL. In the body of the message, upload a binary file into the image.

How to retrieve a file in Firebase storage and connect it to you database Using GET method on REST API

If there is no authentication rule on the storage, use the following URL.

If there is an authentication rule on the storage, use the following URL.

How to retrieve a file in Firebase storage and connect it to you database Using GET method on REST API

If there is no authentication rule on the storage, use the following URL.

If there is an authentication rule on the storage, use the following URL.

Sample Field Format:

{

“fields”: {

	}

}

How to connect Collection from firestore REST API to Appgyver

  1. Copy the path: https://firestore.googleapis.com/v1beta1/projects/{projectID}/databases/(default)/documents/{CollectionID} from the firestore
  2. Open Appgyver composer platform and open the Data configurator. Add Data Resources and choose REST API intergration.
  3. Paste the https://firestore.googleapis.com/v1beta1/ as the Resources ID for the Base
  4. Go to the GET COLLECTION (GET) and past the projects/{projectID}/databases/(default)/documents/{CollectionID} as the Relative path.
  5. Run Test and Generate Schema.

How to Connect Data from FireStore to Appgyver

  1. Create Data Variable from the generated collection

How to create a record on Appgyver from Firestore

  • Fill in the details of the Create Record(POST) session of the resource

How to signup and verify a new user using email and password with POST method on REST API

Step 1: Sign-up

Use the following URL: https://identitytoolkit.googleapis.com/v1/accounts:signUp?key=[API_KEY]

And create in the request body, {“email”:"[user@example.com]",“password”:"[PASSWORD]",“returnSecureToken”:true}

You will get a response body like this:

{

“idToken”: “[ID_TOKEN]”,

“email”: “[user@example.com]”,

“refreshToken”: “[REFRESH_TOKEN]”,

“expiresIn”: “3600”,

“localId”: “tRcfmLH7…”

}

Step 2: Send verification code:

Use the following URL: [https://identitytoolkit.googleapis.com/v1/accounts:sendOobCode?key=API_KEY]

Create a request payload:

{"requestType":"VERIFY_EMAIL","idToken":"[FIREBASE_ID_TOKEN]"}

How to Create a Search box that autosuggests: Link

10 Likes

Hey,
I am new to Appgyver and I would like to say thanks for posting this, it is nice to have a cheatsheet to help with trying to know what to do.

CAREFULL : not “documentid” but “documenId”

1 Like

I tried creating a documentId with post and it worked great, the only thing is I had to write the new document ID inside the URL. Is there a way that we can have an input value fromfrom an input field on the UI that could change the URL’s documentId?

That should be possible via using a page variable :slight_smile: If you are unsure how to work with variables, check out these videos: Core Lesson 1 - Variables & Formulas - AppGyver

How do we form the update mask to edit a field in a nested array or map or to add a new item to a nested array? I have searched all the firebase docs and can find nothing about it.

Can you please show me an example of a body request as only key/value please?

[quote=“Startup_Builder, post:1, topic:6230”]
How to create one or more new field(s) into a document using PATCH method for REST

Use the following URL. IN the body of the HTTP request, write the field name as key and Value only.

How to create one or more new field(s) into a document using PATCH method for REST

Use the following URL. IN the body of the HTTP request, write the field name as key and Value only.

Can you please show me an example of a body request as only key/value please?

1 Like

It’s not body request, request body.

Here is the example…

{

“fields”: {


             "userName": {"stringValue": "hello"} ,
             "userEmail": {"stringValue": "world"}, 
             "AddMore" :{"stringValue" :"variable"} 

           }  

}

Fields is a key word… Hope this will help!

For more details you can refer this forum post… Deleting user profile from firestore database along with Firebase Auth @Daniel_Perley1

May I ask if anyone can help me on how to update a single field using PATCH method. I have the following URL in the HTTP request :

https://firestore.googleapis.com/v1/projects/{projectID}/databases/(default)/documents/{collectionID}/params.client_id?updateMask.fieldPaths={field_name}

I used a page parameter “client_id” which is equal to an existing {documentId} in Firebase. Appgyver can’t recognise “params.client_id” as variable in the URL and created a new document in the name of “params.client_id” with the updated field.

If I don’t use the updateMask.fieldPaths, the PATCH method works very well and recognise the Page Parameter but just update all the field instead of one field. May I know what’s wrong with the above URL? Thanks.

@Mevi

Hi, I follow this and have a PageVar which pass a page parameter to another page. From there I put in the URL. Unfortunately, it seems Appgyver can’t recognise my “params.client_id” as variable and created a new document with “params.client_id” as documentID in Firebase, instead of the value of the variable.

Would you see what is the problem with this URL? Thanks

https://firestore.googleapis.com/v1/projects/{projectID}/databases/(default)/documents/{collectionID}/params.client_id?updateMask.fieldPaths={fieldname}

@Michael_Dumoulin

Hi, is there any luck you solved your problem on using variable for documentId inside the URL ? If yes, would you please share with me ? Many thanks.

Set the following variables:

And in your http request:
image

1 Like

@Fred_Kuzyk
Thanks so much! It works!! From your example I realise I was missing the " " on using the mask in formula. :+1:

appVars.resourceURL+appVars.relativepath+params.client_id+“?updateMask.fieldPaths=phone”

Sorry, I am stuck again on how to create a sub collection. I want to create sub collection named “UBO” in each of the document, and the sub collection I need a new document. Is there any specific code to add the subcollection?

I created the below URL by formula and using POST method. However, it doesn’t work. What is the problem to this URL(formula)?

appVars.resourceURL+appVars.relativepath+“?documentId=”+params.client_id+“/UBO”+“?documentId=”+pageVars.English_name

where :
appVars.resourceURL = https://firestore.googleapis.com/v1/
appVars.relationpath = projects/{projectID}/databases/(default)/documents/{collectionID}
params.client_id = {documentId}

I finally figure it out myself. The first documentId don’t need to use the code “?documentId=” to create, but the 2nd level documentId requires this. Don’t know the logic but it works. Below for those having the same problem for reference.

appVars.resourceURL+appVars.relativepath+“/”+pageVars.{documentId}+“/{subcollectionID}+”?documentId="+pageVars.{field_name}

1 Like

Hi everyone,

has anyone seen a problem with the PATCH method, using an updateMask, whereby it works in postman but not in appgyver?

I get the following error when doing it in appgyver:

“message”:string"Invalid JSON payload received. Unknown name “”: Root element must be a message."

Thanks

Please stop posting false and incomplete info.

so much of this is so wrong and this is why we need a tutorial fact checker