So Im having this issue where no error is thrown at all but my function isn't able to create documents inside my database.
TypeScript
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
TL;DR
Function is not creating documents in the database despite no error being thrown. The issue may be related to improper permissions or incorrect configurations. Ensure that the key provided in the header has all necessary permissions. Check if the database ID and collection ID are correct. Verify the formatting of the log data being sent to the function.Recommended threads
- After assigning a domain to my Dart func...
I’ve attached the images. Could anyone please explain how this execution is being performed?
- how to access the value of account statu...
- Redirect from clicking team invite link ...
Hi all! Pretty new to app development in general so this might be something more generic than appwrite, but I've found (after reading the docs for the Teams API...