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
- How to Avoid Double Requests in function...
I'm currently using Appwrite's `functions.createExecution` in my project. I want to avoid double requests when multiple actions (like searching or pagination) a...
- Project in AppWrite Cloud doesn't allow ...
I have a collection where the data can't be opened. When I check the functions, there are three instances of a function still running that can't be deleted. The...
- Get team fail in appwrite function
I try to get team of a user inside appwrite function, but i get this error: `AppwriteException: User (role: guests) missing scope (teams.read)` If i try on cl...