Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

194
Views
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);
  }
};
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

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

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!