I am trying to send an array of objects in a post request but when I try to access the array with req.body it is just showing {object} and none of the objects content is being sent. Is there something wrong with my request?
here is my request:
Post http://localhost:3000/users/newOrder
Content-Type: application/json
{
"firstName": "Craig",
"lastName": "Mar",
"address1": "10 a st",
"address2": "apt 2",
"email": "c@yahhoo.com",
"town": "red bank",
"state": "nj",
"zip": "07701",
"shippingCost": 12.00,
"orderCost": 25.00,
"productsArray": [{
"id": "4a482549-79aa-4798-8a3b-a19746cd645a",
"title": "Microsoft Xbox X/S Wireless Controller Robot White",
"price": 57,
"quantity": 1,
"total": "57.00",
"image": "https://storage.googleapis.com/fir-auth-1c3bc.appspot.com/1692255251854-xbox.jpg"
},
{
"id": "827ab3f1-b5d5-436a-93cc-7a4a28aefd3b",
"title": "Sony WH-1000XM3 Bluetooth Wireless Over Ear Headphones with Mic (Silver)",
"price": 773,
"quantity": "2",
"total": "1546.00",
"image": "https://storage.googleapis.com/fir-auth-1c3bc.appspot.com/1692947383286-714WUJlhbLS._SL1500_.jpg"
}
]
}
a console log of the req.body is the following:
{
firstName: 'Craig',
lastName: 'Mar',
address1: '10 a st',
address2: 'apt 2',
email: 'c@yahhoo.com',
town: 'red bank',
state: 'nj',
zip: '07701',
shippingCost: '12',
orderCost: '25',
productsArray: [ '[object Object]', '[object Object]' ]
}
if i try to access the values of the objects in the products array with dot notation i am getting undefined any ideas where i am going wrong? I have also tried a curl request but get the same result.