
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 triggers the function but doesn’t log the payload, in the docs it’s said to use req.bodyjson but I keep getting this error : SyntaxError: Unexpected end of JSON input at JSON.parse (<anonymous>) at get bodyJson (/usr/local/server/src/server.js:125:21) at Module.default (file:///usr/local/server/src/function/src/main.js:15:26) at execute (/usr/local/server/src/server.js:220:42) at action (/usr/local/server/src/server.js:237:27) at process.processTicksAndRejections (node:internal/process/task_queues:105:5) at async /usr/local/server/src/server.js:26:5

import { Client, Users } from 'node-appwrite';
// This Appwrite function will be executed every time your function is triggered export default async ({ req, res, log, error }) => { // You can use the Appwrite SDK to interact with other services // For this example, we're using the Users service const client = new Client() .setEndpoint(process.env.APPWRITE_FUNCTION_API_ENDPOINT) .setProject(process.env.APPWRITE_FUNCTION_PROJECT_ID) .setKey(req.headers['x-appwrite-key'] ?? ''); // const users = new Users(client);
// try { // log(req); // Raw request body, contains request data log(JSON.stringify(req.bodyJson)); // Object from parsed JSON request body, otherwise string // log(JSON.stringify(req.headers)); // String key-value pairs of all request headers, keys are lowercase log(req.url); // Full URL, for example: http://awesome.appwrite.io:8000/v1/hooks?limit=12&offset=50 log(req.host); // Hostname from the host header, such as awesome.appwrite.io log(req.port); // Port from the host header, for example 8000 // pcIndex.upsert([ // { // id: '1', // values: [1, 2, 3], // metadata: { // name: 'bunny-bite', // }, // }, // ]); // } catch (err) { // error('Could not list users: ' + err.message); // }
return res.json({ success: true, }); };

This is my code it’s just to log the event

import { Client, Users } from 'node-appwrite';
// This Appwrite function will be executed every time your function is triggered
export default async ({ req, res, log, error }) => {
// You can use the Appwrite SDK to interact with other services
// For this example, we're using the Users service
const client = new Client()
.setEndpoint(process.env.APPWRITE_FUNCTION_API_ENDPOINT)
.setProject(process.env.APPWRITE_FUNCTION_PROJECT_ID)
.setKey(req.headers['x-appwrite-key'] ?? '');
// const users = new Users(client);
// try {
// log(req); // Raw request body, contains request data
log(JSON.stringify(req.bodyJson)); // Object from parsed JSON request body, otherwise string
// log(JSON.stringify(req.headers)); // String key-value pairs of all request headers, keys are lowercase
log(req.url); // Full URL, for example: http://awesome.appwrite.io:8000/v1/hooks?limit=12&offset=50
log(req.host); // Hostname from the host header, such as awesome.appwrite.io
log(req.port); // Port from the host header, for example 8000
// pcIndex.upsert([
// {
// id: '1',
// values: [1, 2, 3],
// metadata: {
// name: 'bunny-bite',
// },
// },
// ]);
// } catch (err) {
// error('Could not list users: ' + err.message);
// }
return res.json({
success: true,
});
};
Formatted the next guy who tries to debug

Thank you
Recommended threads
- Best practice for calling 3P APIs with p...
Hey everyone! Looking for guidance on the recommended approach for securely calling third-party APIs from my Appwrite-hosted application. **Current Setup:** - ...
- Function not creating documents
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, Databa...
- 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 { ...
