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
- After a GET request is passed to functio...
Create execution in the console can normally retrieve the get parameters。WHy?
- function subdomain ssl certs
The generated subdomain isn't getting a valid ssl cert, I was wondering if appwrite automatically generates one or uses a wildcard for *.functions.domain.com? ...
- Python Function Deployment hits General ...
The same deployment was working without issue yesterday and I have not hit any free tier limits yet. How do I figure out what's happening? Are you having issues...