Create query in Firestore and Appgyver

Hi everyone I have been trying for a while to run a query on my Firestore Database through Appgyver but without success.

I created a Data Resources with REST API Direct Integration with this URL: https://firestore.googleapis.com/v1/projects/MYPROJECTID/databases/(default)/documents/users/

And if I launch it as is I can see all users. What I would need is to say: only show me users with “userid = 1234”, so something like this:

https://firestore.googleapis.com/v1/projects/MYPROJECTID/databases/(default)/documents/users?userid=1234

How is it possible to do it from Appgyver?
I also tried to create a composite index in Firestore but that didn’t help.

Any help is important
Thank you!

i think u have to do a get record method if u want just a user with that id
search for authontication of firebase and appgyver in youtube for iyed halwani

Hi Rauf, no, maybe I explained myself badly. I need to query my users and check conditions so that they can be selected, for example: “Name = James” or “age = 30”, etc …
Normally when I write some code I create an endpoint to which I pass my parameters (ex. Name or Age) and then a query is executed inside the endpoint (ex. Select * where name = ‘James’) which returns me the list of records that match the query parameters. How do I do all this with AppGyver and Firestore ???
I don’t know if I was clearer :slight_smile: Thanks!

Hi, can anyone help me? I tried to follow the guide here: Query Firestore but was unsuccessful. HTTP request always returns me the entire list of items without applying the query. Furthermore, one thing that is not clear to me from the guide is at point 8: how can I associate a data variable? The data variable is chained with a Data Resources, but here we are using an HTTP request function. Who helps me understand? Thank you

Please share, what you have in the body of your HTTP request (according to point 5 in the guide). Maybe we can find a deviation there…

Regarding point 8 I don’t understand what you struggle with. Please share some screenshots to describe your logic for that matter.

Hi @stayfoolish this is my http req body:

{“structuredQuery”: {“from”: [{“collectionId”: “users”}],“where”: {“fieldFilter”: {“field”: {“fieldPath”: “userid”},“op”: “EQUAL”,“value”: {“stringValue”: “AAAAA123456”}}}}}

regarding point 8, you say to use HTTP output to set a data variable, but Appgyver does not allow me to create this type of variable if a Data Resources is not set first, however if I am retrieving my data through a HTTP Request, I don’t need to configure any Data Resources. I err !?

Thank you for the details:

  • the body looks fine to me. You should not get the entire collection based on this, but only the user with the id ‘AAAAA123456’. I suggest that you run it at postman.com and check if you get the right results there.
  • yes, you should set the Data Resource.

just to be precise, “userid” is a custom field of my collection, NOT the collection id (that is automatically assigned by Firebase).
Postman response with a Status: 400 Bad Request :frowning:

ok but why should I create a Data Resource if I am accessing the data through an HTTP Request ??

thank you !

Query:

  • to debug the code, I suggest that you doublecheck that you followed precisely the steps in the guide. Please add screenshots from postman, so we can support you in finding the deviation.
  • also please doublecheck in postman that you receive the collection, if you don’t apply the query code.

Data Resource:

  • you should create the data resource, so you can create a data variable that fits to its schema.

Hi Postman responds correctly with the collection when I don’t pass any parameters.
I am attaching a screenshot by attaching the query:

and without query:

Please compare to step 3 of the guide:
image

yes i had already tried but i got an error

(also because it seems very strange to me to have to do a POST, since I don’t have to save any data but only read.)

i think this video can help you

Hi, I followed your video but my select does not extract the document I need.
Here is a screenshot.

As you can see the searched element is present but it should be the only one, instead if you scroll through that same screen, we also find the other users (other screenshot)

I hope I have explained

ok, we’re getting closer :wink:

  • Please share the end of the URL that is hidden in the screenshot (marked with (1)).

  • it is partly hidden, but it looks like your URL is to long: When I compare to the firestore structure that you share in the other posts here, it must not contain the part ‘users’ at location (1) but only at location (2). Instead it should end with the document, that is superior to the collection you want to query. In your case I assume it needs to be shortened to
    https://firestore.googleapis.com/v1/projects/MYPROJECTID/databases/(default)/documents:runQuery
    Please compare to point 2 in the guideline.

Bye!
Here is the url that was hidden (point 1 of your screenshot):
https://firestore.googleapis.com/v1/projects/muvapp-75a48/databases/(default)/documents/users

I tried to correct the url as you suggested making it become:
https://firestore.googleapis.com/v1/projects/muvapp-75a48/databases/(default)/documents:runQuery

Now I get all the data! Great!!

Now I try to do all this in Appgyver!

Thank you very much !!
Claudio.

Hello,
I tried to bring in AppGyver but without success.
I created an HTTP REQUEST and if I assign its output to a page variable with the formula “outputs [” HTTP request “]. ResBodyRaw” I can see the acquired data.

However, this does not give me the opportunity to work on that data.
According to point 8 of the guide, I should have a data variable with the following formula: MAP (outputs [“HTTP request”]. ResBodyParsed, item.document)
This doesn’t work for me though (see screenshot):

any suggestions ?

The red letters do not always mean, that the code is wrong. Give it a try and check, if your data variable is filled correctly.

If the data variable isn’t filled correctly, you can start debugging by using the code togehter with encode_JSON in a ‘alert’ flow function and investigate the result there.

@stayfoolish this is precisely the problem I’ve been facing for a while. I started with the guideline you posted. Everything is well and good until I arrive at Step No.8.

You mention something about chaining the output to a ‘data variable’

2 things about data variables (my undertanding):
a) you need to create a data resouce to initiate a data variable
b) even if I make a ondevice resource, I’m assuming it stores every output ever received on the storage.

My questions to you are:
A) When you say, chain the output to a data variable (step.8), do you mean to create a ondevice storage resource?

B) Can the responses received be used with the repeat with property?

I feel like I’m missing your point. Please comment on this matter so that It’ll server many novices such as myself navigate this.