Notes:
In Composer, as you create the custom schema, it generates an id property for each object. You have to erase it!
Composer will order properties by ascending name.
Your data will be on the stringValue property (ie: dirInm.codPost.stringValue)
Finally, I will be adding settings as I get them to work
Sure. Once I finish to figure out the settings for the other basic calls (query by field, patch and delete) I would be pleased if you make it part of your documents.
Alright, just ping us when you’re done, we’ll review it and set it up. The format for our docs is Markdown, so if you’re comfortable writing the steps in Markdown, that will be helpful.
Sorry guys, there is an error on the POST instructions. There should be no info on the URL placeholder. It seems that on writing I pasted the values of for GET (ONE).
Thanks for posting this. I was spinning my wheels trying to get the REST API to work.
I’ve been able to get the following to work …
GET all documents in a collection
GET one document by id
And I’m working on …
POST a new document to a collection
Update an existing record
Delete an existing record
Question 1: I’m stuck a trying to get POST to work and I can’t seem to match up the Custom Schema to the Firestore API Example. Do you have something with a simple example? Just a few fields so that I can match up exactly.
Question 2: How would you go about updating an existing record? Updates in Firebase seem to happen via a HTTP PATCH request.
Question 3: How would you suggest adding back security? Right now everything is wide open.
Currently the way to circumvent this is to use the HTTP request flow function, which you can then wrap in your own “Update in Firebase” flow function to get input/output schemas. It’s a bit inconvenient but doable.
For security, the only way to securely deliver an API key to a client app is to have a backend where the user can login with some credentials, and then the successful response returns the API key that is then stored as an app variable and possibly persisted via e.g. client-side storage. Of course preferably, this API key/authorization token is user-specific and gives just the required access.
It works pretty much like any other database. You get a key and pass it on the REST request. I suggest you do it on the base configuration tab of your appGyver Data configurator. I tried once and worked fine, but since I’m trying to figure out the REST API configuration for all usual calls, I reverted to the non secure connection in order to have less posible variables into account.
As for PATCH, I have not been able to get it to work, but still trying.
A final word on the schema: Firestore JSON is a tree of objects, with the final “branch” a stringValue/ timestampValue property with the actual data. On the REST API Data Configurator of AppGyver it looks like this:
Note the createTime, name and updateTime properties, which contain info about the document on Firestore: createTime and updateTime are automatically filled by Firestore on PUT/POST calls, while name (which contains the document id), if absent, it’s also auto filled.
Also, as you can see in the image, the map in Firestore translate to a mapValue property on the AppGyver schema, which is also an object that contains a fields property, and so on.
I was not able to get the POST to work using Create record flow function.
I can run the POST successfully in the DATA CONFIGURATOR when I use the Test API call response. Shows success and the record is created in the DB.
When I use Create record flow function. It doesn’t return an error however the record is not created in the database. When I look at the response body it’s listing all records in the DB. Not sure why it does this?
I was able to get a POST working using the HTTP request flow function. No error returned and the response body is correct.
Will be using the HTTP request flow function as a workaround.
Hello @Eduardo_Jaramillo and all.
I did follow your steps and manage to get the POSTing of a new document in Firestore to work. However with this step, Firestore auto generates the document ID.
Did anyone of you manage to get the POST to work with a Custom Document ID? have tried the URL placeholder stuff without any luck.
Thanks
Hello @Eduardo_Jaramillo,
That doesn’t appear to work either.
I have tried the document ID with and without the {} variable without any luck.
I did set the name to the below:
Note: in section “B”, the value for URL placeholder for “myDocID” is set to a chosen string eg “DocPosition5”
However, if i set the name to section “C” above (ie without the Custom ID), it does work, but then the Firestore auto generates the document ID. This also confirms a working “custom schema” i guess.
For both sections “A” and “B”, i do get the below error for the name:
Error: JSON error response from server: {“error”:{“code”:400,“message”:“Document parent
name “projects/myDataBase/databases/(default)/documents/myCollection” lacks “/” at index
56.”,“status”:“INVALID_ARGUMENT”}}.status: 400
Sorry, I forgot to include somethings important on the setup of the REST API and made a mistake on the content of name (it should only be the documentID, without the path). Sorry for the inconvenience and time lost.
The set up is as follows (instead of name the images have “id”):
Hello @Eduardo_Jaramillo,
It works like a charm. The trick as mentioned is the “?documentId={id}” in the relative path extention to the Firestore name.
Much appreciated.