
Hi All,
On accessing properties of payload showing undefined on Appwrite cloud using node.js server sdk
Data:
messageFor: 'web',
token: 'test-token',
userToken: 'test-user-token',
deviceToken: 'test-device-token'
}```
Sample Code:
```module.exports = async function (req, res) {
const payload = req.payload;
res.json({
messageFor: 'messageFor - ' + payload.messageFor,
token: 'token - ' + payload.token,
userToken: 'userToken - ' + payload.userToken,
deviceToken: 'deviceToken - ' + payload.deviceToken,
});```
Sample Response:
```{
"messageFor":"messageFor - undefined",
"token":"token - undefined",
"userToken":"userToken - undefined",
"deviceToken":"deviceToken - undefined"
}```

On accessing properties of payload showing undefined

req.payload
is a string. You'll need to parse it

As per your suggestion, I have implemented the same but getting the below error.
Updated Sample Code
module.exports = async function (req, res) {
const payload = JSON.parse(req.payload);
res.json({
messageFor: 'messageFor - ' + payload.messageFor,
token: 'token - ' + payload.token,
userToken: 'userToken - ' + payload.userToken,
deviceToken: 'deviceToken - ' + payload.deviceToken,
});
Error Response
SyntaxError: Unexpected token m in JSON at position 10
at JSON.parse (<anonymous>)
at module.exports (/usr/code-start/src/index.js:126:24)
at /usr/local/src/server.js:68:19
at processTicksAndRejections (node:internal/process/task_queues:96:5)
I have google it and found it seems might be due to incorrect json string but couldn't able to identify where I am missing it

the data you're passing into the function is not valid JSON. you must wrap keys with double quotes

It worked! Thanks 🫡

Actually, I followed the sample JSON provided while executing from the console. Their keys are not wrapped with double quotes. Hope it will be fixed

yes, it has already been fixed in a newer version of Appwrite

[SOLVED] On accessing properties of payload showing undefined
Recommended threads
- upsert_documents is not work with jwt cl...
client.set_jwt(jwt) databases = Databases(client) databases.upsert_documents(General, Pallets, [{"$id": "684aeb3e0021e64c10f1", "name": 'тест '}]) This code al...
- Email OTP Mail Getting Delayed by 10 min...
I just noticed I am reciving delayed otp emails on frankfurt server we are on free plan now but we are planning to change to get on to paid plan can anyone plea...
- schedule functions not working
starting from 15:02 utc time my schedule function stops working. I was able to execute it using the GUI. The schedule is every 5 minutes and I can see a clock i...
