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
- Any example for using Appwrite with Verc...
Can not find an example on this.
- Issue with database event trigger for a ...
I created a function hosted it on aperture connected it to my domain, in the settings I added da collection to listen to any time a new document is created , it...
- Sites deployments don't auto start after...
Hey, I recently found out that when our docker service restarts (for whatever reason, usually me poking around in config) each site deployment need to be manual...