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
- MariaDB refuses to connect to appwrite
Earlier, I tried updating my Appwrite version from 18.1.x to the latest release because my Flutter package required it to function properly. I used the official...
- Console display all Databases as TablesD...
While looking at an issue with <@1231860789355347971> we saw that the console was displaying ALL databases as `TablesDB` even if the real type in the API is `le...
- HTTP Error 500 ''
Hello to everyone, I'm a Flutter developer and actually I'm developing an app using Appwrite.. during my tests and also massive ones I've noticed something we...