'How To make a post request from react to node/express api

All i need to do is to send my state of invoice details to database through post request but im having troubles doing it is this the right way to do it or am i missing something post function works fine if the query is only a string so the only problem is reading the body params

const postInvoices = () => {
    const URL = "http://localhost:8000/api/InvSave";
    axios
      .post(URL,InvDet)
      .then((response) => {
        console.log("DATA : ",response);
      })
      .catch((error) => {
        console.log(error);
      });  
  };

im sending the state on click

in my api i wrote :

router.route('/InvSave').post((request,response)=>{
try{
   const invoices =  request.body

   dboperations.PostInvoices(invoices).then(result => {
      response.status(201).json("api results :",result);
   })
}catch(err){
   console.error(err)
}
})
const PostInvoices = async (invoices) => {
  try {
    let pool = await sql.connect(configInsert);
    console.log("invoices code",CODE_ART)
    const q =
      "insert into Packingdetails values('1','"+
      invoices.CODE_ART +
      "','" +
      invoices.a_code +
      "','" +
      invoices.DESC_ART +
      "','" +
        invoices.TotalPc +
      "','" +
        invoices.date+    
      "')";
      console.log("query : "+q)
    let invs = await pool.query(q);
    console.log("saved");
    return invs.recordsets;
  } catch (err) {
    console.log("POSTINV : ", err.message);
  }
};


Solution 1:[1]

make sure you are using some kind of body-parser to parse your request console.log(invoices) to check if you are getting the correct invoices in request body

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 kes.mahawar