
So Im having this issue where no error is thrown at all but my function isn't able to create documents inside my database.
import { Client, Databases, ID } from "node-appwrite";
export default async ({ req, res, log, error }) => {
if (req.method !== "POST")
return res.json({ message: "method not allowed", status: 405 }, 405);
const client = new Client()
.setEndpoint(process.env.APPWRITE_FUNCTION_API_ENDPOINT)
.setProject(process.env.APPWRITE_FUNCTION_PROJECT_ID)
.setKey(req.headers["x-api-key"]);
const databases = new Databases(client);
const body = req.bodyJson;
if (!body.level || !body.message || !body.timestamp)
return res.json({ message: "wrong log format", status: 400 }, 400);
const level = body.level.toLowerCase();
if (
level !== "info" &&
level !== "error" &&
level !== "debug" &&
level !== "warning" &&
level !== "notice" &&
level !== "crit" &&
level !== "alert" &&
level !== "emerg"
)
return res.json({ message: "invalid log level", status: 400 }, 400);
try {
await databases.createDocument(
process.env.DATABASE_ID,
process.env.COLLECTION_ID,
ID.unique(),
body
)
.then((result) => log(result.$id))
.catch((err) => error(err));
} catch (e) {
error(e);
return res.json({ message: "no access", status: 403 }, 403);
}
return res.empty();
};
Above is the function. I've given the key inside the header all permissions that I could. As I said there are no errors thrown or anything to indicate that the creation has failed but its not creating the document
Recommended threads
- GitHub Education Pack not activating App...
Hello Appwrite Team! 👋 I'm a verified member of the **GitHub Student Developer Pack** (approved August 15, 2025; valid until August 15, 2027). I've successful...
- Got server error 500 "general_unknown" w...
My function responds a small ogg audio data, the console showed successful executions, but I got a server error from the client sdk (Android/Kotlin): ```json { ...
- Bulk Operations in Function API KEY
When my appwrite function executes (hosted on appwrite console), the bulk operations don't execute (without error) unless I add a dev key as an API Key in the e...
