
This is the code to print all value

And the first img is the output it gave to me

req.bodyRaw
is a string so when you stringify that, jsonBody
results in a nested string. When you parse that, parsedJsonbody
becaomes a string

please try using req.body.hi

Okay, let me try it and get back to you

As an aside, I could not get
req.body.whatever
to work. I had to do
let parsedBodyRaw = JSON.parse(req.bodyRaw);
// And then I could access 'whatever' via
parsedBodyRaw.whatever

Okay will try that out

Still didn't work, let me try the other guy suggestion, and see how it goes

💯💯💯💯💯❤️❤️❤️❤️❤️❤️ Thanks so much, It works I have been debugging this for a very long time, and you kinda make it look easy.
I appreciate your time ❤️

Hi, so I have gotten it to work, thanks for joining in to debug this with me I really appreciate this ❤️❤️❤️❤️❤️❤️❤️❤️,
💯 To appwrite once again

Can't get body data in the req module for node.js

Yep, I probably spent a good 30 minutes banging my head against the wall before figuring that out. Not entirely sure why the req.body
route doesn't work

Yer, me too, made me question my field of study 😅. Not really sure if I would have guess this if you haven't said so.

Maybe the appwrite team need to look more into this.

Yeah, I would be curious to see if it's a "we're the dumb ones" or if there's actually a bug in the req
module

Not entirely sure why the
req.body
route doesn't work
what do you mean?

At risk of you highlighting something dumb that I've overlooked (as has been my habit the past couple days)..
export default async ({ req, res, log, error }) => {
// these would just return nothing/empty string
log(req.body.blah)
log(JSON.stringify(req.body.blah))
// these worked
const parsedBodyRaw = JSON.parse(req.bodyRaw);
log(parsedBodyRaw.blah)
log(JSON.stringify(parsedBodyRaw.blah))
}

what are you sending to the function? how are you executing your function? what is req.body
?

Executing via manual execution in Appwrite Console as well as REST
Sending:
{ "myKey": "myValue" }
Function Code
export default async ({ req, res, log, error }) => {
// req.body
log("req.body");
log(req.body);
log("req.body.myKey");
log(req.body.myKey);
log("JSON.stringify(req.body.myKey)");
log(JSON.stringify(req.body.myKey));
// req.bodyRaw
let parsedBodyRaw = JSON.parse(req.bodyRaw);
log("parsedBodyRaw");
log(parsedBodyRaw);
log("parsedBodyRaw.myKey");
log(parsedBodyRaw.myKey);
log("JSON.stringify(parsedBodyRaw.myKey)");
log(JSON.stringify(parsedBodyRaw.myKey));
Output
req.body
{ "myKey": "myValue" }
req.body.myKey
undefined
JSON.stringify(req.body.myKey)
undefined
------------
parsedBodyRaw
{"myKey":"myValue"}
parsedBodyRaw.myKey
myValue
JSON.stringify(parsedBodyRaw.myKey)
"myValue"
Did I find a bug or am I big dumb idiot of the day? 🤞 😨

so it looks like req.body will only be parsed if the header specifies the content type is application/json:

Would you look at that...I might be biased but I would assume that JSON would be the default, especially with how the documentation and helper formats are all JSON

ya....that would make sense...

Wow, didn't knew that

Taught so too

[SOLVED] Can't get body data in the req module for node.js
Recommended threads
- Cannot create a user
Hi, I am using a lowcoder frontend and trying to create a user in Appwrite (python function). Unfortunately, all I got is an error: "Raw body: Error". It means...
- Where is tensorflow support? 3.11 ML doe...
and if i manually tried to add tensorflow i get Cannot access offset of type string on string no matter what
- OAuth2 Error: invalid success param url ...
Hi everyone! I'm trying to implement Google OAuth2 login in a React Native app (using the Android simulator) with Appwrite Cloud, and I'm getting the following ...
