Skip to content
Back

Appwrite functions are not accepting/reading JSON body

  • 0
  • Cloud
rameshkec85
5 Jul, 2025, 10:26

curl --location 'https://fra.cloud.appwrite.io/v1/functions/custom-login/executions'
\ --header 'X-Appwrite-Project: '
\ --header 'Content-Type: application/json'
\ --header 'X-Appwrite-Key: '
\ --data-raw '{ "email": "", "pin": 123 }'

Appwrite functions are unable to read json body.

Nodejs : 22 used starter sample

I got stuck since 4 hours to get started with Simple function which accepts body from the client apps.

Can anyone help me on this ?

import * as sdk from "node-appwrite"; import bcrypt from "bcryptjs";

export default async ({ req, res, log, error }) => { const client = new sdk.Client() .setEndpoint(process.env.APPWRITE_ENDPOINT) .setProject(process.env.APPWRITE_FUNCTION_PROJECT_ID) // .setKey(req.headers['x-appwrite-key'] ?? ''); .setKey(process.env.APPWRITE_API_KEY); // API key must be from a privileged scope

const db = new sdk.Databases(client); const users = new sdk.Users(client); try { const response = await users.list(); log(Total users: ${response.total});

} catch(err) { error("Could not list users: " + err.message); }

let body = {};

try { log(req: ${req}); log(req.bodyRaw: ${req.bodyRaw}); log(req.bodyText: ${req.bodyText}); log(req.bodyJson: ${req.bodyJson}); log(req.bodyText);
log(JSON.stringify(req.bodyJson));
log(JSON.stringify(req.headers));
log(req.scheme);
log(req.method);
log(req.url);
log(req.host);
log(req.port);
log(req.path);
log(req.queryString);
log(JSON.stringify(req.query));

body = JSON.parse(req.body || '{}'); } catch (e) { log(e.message) return res.json({ error: 'Invalid JSON' }); }

**Response: ** Total users: 17 -> req: [object Object] req.bodyRaw: [Blank] req.bodyText: [Blank]

TL;DR
Appwrite function is not reading JSON body from the client apps. Node.js code attempts to parse the request body as JSON but fails. Check the request logging and parsing to troubleshoot the issue.
Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more