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
- TOO_MANY_REDIRECTS after temporarily ena...
I am losing my mind over this, I enabled this setting because I was having issues with sites not making links with https. I enabled it, ran into issues, so I di...
- Unable to create Sites or Functions with...
Heya, I was looking at the appwrite documentation for Sites API with the server api: https://appwrite.io/docs/references/cloud/server-nodejs/sites I can’t fin...
- Triggers and call function in function p...
Hello, Today we are experiencing several issues with Appwrite Cloud. Functions triggered by events, or functions called from another function, are taking an e...