Back

how to perform a query on the appwrite database when consuming a rest api?

  • 0
  • Databases
0liveiraVictor
23 Mar, 2023, 03:08

How should I set the header to send a filtering attribute and a specific value?

TL;DR
I forgot to add an index in the database console, which caused an error when trying to fetch attribute data. The solution was to add the index.
Drake
23 Mar, 2023, 03:14

It wouldn't be a header. It would be a query string. See https://appwrite.io/docs/rest#query

0liveiraVictor
23 Mar, 2023, 03:22

In case, should I send my query string in the url of the consumer api? Is this?

Binyamin
23 Mar, 2023, 03:36

Yes, Exactly as so

TypeScript
https://cloud.appwrite.io/v1/databases/{databaseId}/collections/{collectionId}/documents?queries[]="equal("attribute", [value])"&queries[]="greaterThan("attribute", [value])"
0liveiraVictor
23 Mar, 2023, 04:00

I tried to use the indicated parameter, however I got the following error:

0liveiraVictor
23 Mar, 2023, 04:00
Binyamin
23 Mar, 2023, 04:01

Mm maybe remove the " before and after the query

Binyamin
23 Mar, 2023, 04:02
TypeScript
queries[]=greaterThan("attribute", [value])
0liveiraVictor
23 Mar, 2023, 04:03

hum, ok.

0liveiraVictor
23 Mar, 2023, 04:03

It worked. Thank you very much, @Binyamin!

Binyamin
23 Mar, 2023, 04:03

Yes my bad

0liveiraVictor
23 Mar, 2023, 04:13

I tried to fetch my attribute data, according to the query sent, but I got an error stating that the attribute is not valid.

{ message: 'Index not found: id_auth', code: 400, type: 'general_argument_invalid', version: '1.2.0' }

0liveiraVictor
23 Mar, 2023, 04:19

OK, guy. I managed to resolve. I forgot to add the index in the database console.

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more