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.bodyroute 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
- Local appwrite run functions --user-id n...
Hi, I'm running into an issue when testing Appwrite functions locally with user impersonation. I'm using a self-hosted Appwrite instance and running functions ...
- Function domain not available
Hello, even tho in docs you clearly describe that every function has its domain, I can not see it anywhere in any of my projects. How do I reveal the url of th...
- Inquiry: How to Reduce Cold Start Durati...
Hey! I was using Python for the function runtime, but after reading that Go has the fastest runtime, I switched my code over to Go. However, I'm still seeing co...