I'm trying to get the list of documents with the Appwrite function, unfortunately, I can't get any value.
const sdk = require("node-appwrite"); module.exports = async function (req, res) { const client = new sdk.Client(); // You can remove services you don't use const database = new sdk.Databases(client); if ( !req.variables["APPWRITE_FUNCTION_ENDPOINT"] || !req.variables["APPWRITE_FUNCTION_API_KEY"] ) { console.warn( "Environment variables are not set. Function cannot use Appwrite SDK." ); } else { client .setEndpoint(req.variables["APPWRITE_FUNCTION_ENDPOINT"]) .setProject(req.variables["APPWRITE_FUNCTION_PROJECT_ID"]) .setKey(req.variables["APPWRITE_FUNCTION_API_KEY"]) .setSelfSigned(true); } const DbCollection = "64bb1ee4200b221e0675"; const usersCollection = "64bb1f396ed41ad9c1d8"; const prayerPartnerCollection = "6545e03a11aa6b5ba77a"; const prayerPartnerHistoryCollection = "6545e4ba5bcad02198c0"; const notificationCollection = "654cd8010d7f67c0d238"; const promise = database.listDocuments(DbCollection, usersCollection); promise.then( function (response) { res.json({ myResponse: response, }); }, (error) { console.log(error); res.json({ myError: error, endPoint: req.variables["APPWRITE_FUNCTION_ENDPOINT"], projectId: req.variables["APPWRITE_FUNCTION_PROJECT_ID"], functionApi: req.variables["APPWRITE_FUNCTION_API_KEY"], }); } ); };
over the past 7hrs, I have been reading appwrite documentation on how to make this code work, but nothing I do seems to work, i have to try PHP runtime yet, nothing its working.
please what am I doing wrong?
@Drake good day Sir,
Sir please can you make me understand what I'm doing Wrong on this code?
is this a cloud ? or self hosted?
Please don't tag people as it can be very disruptive. You can post and wait for anyone to respond.
FYI, it's best to wrap code in backticks to format a bit nicer. You can use 1 backtick for inline code (https://www.markdownguide.org/basic-syntax/#code) and 3 backticks for multiline code (https://www.markdownguide.org/extended-syntax/#syntax-highlighting.
It's really hard to read the code, but the problem could be that the function is returning before the promise is resolved. I recommend not using promise.then
. Instead, use async await.
Pls take a look at it here
Hello @Drake @Core @Mosh Ontong
I'm very aware everyone is on a busy schedule, can you please quickly take a look at what I'm doing wrong.
Thank you very much
@Zionnite let's not tag Core here please, especially since there are folks interacting in the thread
Steven has already responded on the StackOverflow question. Have you had a chance to review his answer and try the solution?
Recommended threads
- How to Avoid Double Requests in function...
I'm currently using Appwrite's `functions.createExecution` in my project. I want to avoid double requests when multiple actions (like searching or pagination) a...
- Project in AppWrite Cloud doesn't allow ...
I have a collection where the data can't be opened. When I check the functions, there are three instances of a function still running that can't be deleted. The...
- Get team fail in appwrite function
I try to get team of a user inside appwrite function, but i get this error: `AppwriteException: User (role: guests) missing scope (teams.read)` If i try on cl...