Back

[Solved] ListDocuments server SDK not getting any results.

  • 0
  • Databases
  • Functions
punti_z
24 Mar, 2023, 18:11

Indeed unresolved still and now I am struggling with another weird one where my function deployment build keeps failing ... Restarted all containers but issue still persists so havnt been able to do any new code tests ..

TL;DR
Solved the issue with ListDocuments server SDK not returning any results. The problem was with asynchronous code, so the function was finishing before the API call was complete. A code sample was provided using try/catch/await instead of then/catchError. The issue was resolved and the code is now working as expected.
Drake
24 Mar, 2023, 18:50

usually, the problem is either syntax error or an exception thrown in the code. If you want help, feel free to create another post with details on your error and your code

punti_z
25 Mar, 2023, 23:42

@Steven @Binyamin figured out the function deployment but the query still doesn't return any results, removed the query and just straight listDocuments doesn't do anything either.. Any ideas where I could look to troubleshoot ?

Binyamin
26 Mar, 2023, 00:26

What is the error you're getting?

Drake
26 Mar, 2023, 01:35

Did you set an API key with enough scopes?

punti_z
26 Mar, 2023, 04:35

Yes, since this is still in dev, I have 1 key with full scope.. I am able to write to the DB just the list documents query doesn't do anything

punti_z
26 Mar, 2023, 04:36

No error, when I check the logs it just prints any print statements I have in the code but no error or response

punti_z
26 Mar, 2023, 04:37

The code is straight lift from documentation sample code.

Drake
26 Mar, 2023, 04:37

Would you please share more of your updated code?

punti_z
26 Mar, 2023, 04:38

I tried the same from client side and it works as expected just server side SDK doesn't return list of documents

punti_z
26 Mar, 2023, 04:38

Gimme 5

punti_z
26 Mar, 2023, 04:42

Well the code attached in the post is pretty much it, I have removed the "queries:" altogether but still the "result.then" block never triggers .. I assume API key based access is not restricted by collection or document level restrictions

Drake
26 Mar, 2023, 04:44

Do you have a catchError()?

punti_z
26 Mar, 2023, 04:44

So Key is not the issue and since its API key based request, I assume, collection and document based security is overridden and I should get results

punti_z
26 Mar, 2023, 04:45

Yup and that also has a print(error) but that doesn't trigger either when looking at logs

Drake
26 Mar, 2023, 04:46

Did you await the result before calling res.json()?

punti_z
26 Mar, 2023, 04:48

Future result = databases.listDocuments( databaseId: '[DATABASE_ID]', collectionId: '[COLLECTION_ID]', );

result .then((response) { print(response); }).catchError((error) { print(error.response); });

Drake
26 Mar, 2023, 04:48

And then?

punti_z
26 Mar, 2023, 04:48

This is exactly the code I am using, please let me know where do you want me to await

Drake
26 Mar, 2023, 04:49

Honestly, I recommend using try/catch/await over then/catchError unless you have some specific reason not to

punti_z
26 Mar, 2023, 04:51

Can you spoon feed me a 3 line sample code of how you want me to try doing it just so I know I am doing it right

Drake
26 Mar, 2023, 04:58
TypeScript
try {
  final result = await databases.listDocuments(...);
  print(result);
} catch (e) {
  print(e);
}
punti_z
26 Mar, 2023, 13:15

Hey @Steven thanks for the help, it does work now. Not sure what was broken before since my original code was straight lift from appwrite documentation. But thanks to you its working now. Cheers

punti_z
26 Mar, 2023, 13:15

[Solved] ListDocuments server SDK not getting any results.

Drake
26 Mar, 2023, 15:42

Because of the asynchronous code, your function was finishing before the API call was complete.

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