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]
Recommended threads
- New Build not visible on Domain
I pushed some new code to my Appwrite Site and the build succeeded and is shown as active. Yet, I can only see the new version of the site on Appwrite's provide...
- DNS bug
Hello, we found bug at the Appwrite Cloud Domains, when changing **only ** the Comment of CNAME, we get error DNS record already exists. Some DNS types do not ...
- Duplicate Billing Issue – Charged Twice ...
Hi Appwrite team, I noticed that my card was charged twice for the subscription payment ($25 each), even though I only intended to make a single payment. Coul...