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

154
Views
Unable to Pass Data to Backend from Input

I have an API which will send an email to a user based off the input. This is the on lick submit. I can confirm the data is being console.log for the state.

const inviteUser = async () => {
        userRequest.get(`companyprofile/companyUser/invite/${companyuser._id}`, teamMemberEmail);
        console.log('invite sent to', (teamMemberEmail))
    }

With this api, i send the body to the API and then email based off the text, however when i log the field it does not appear at all and only shows as {}

router.get("/companyUser/invite/:id", async (req, res) => {
  // must update to company
  var stringLength = 25;

  const companyUser = await CompanyProfile.findById(req.params.id)

  const companyUserToken = await companyUser.inviteToken
  const companyAccessTokenStripped = await companyUserToken.substring(0, stringLength);
  //encrypt the accesstoken to invite users

  const url = `http://localhost:5000/api/auth/inviteToJoinTeam/${companyUserToken}/${req.body.email}`;
  // const url = `http://localhost:5000/api/companyprofile/companyUser/inviteToJoinTeam/${companyUserToken}`;
  console.log(req.body)

  const  mailOptions = {
    from: 'company@gmail.com',
    to: req.body.email,
    subject: `You have been invited to join ${companyUser.CompanyTitle}`,
    html: `${companyUser.companyTitle} has invited you to join their team <a href="${url}">${url}</a>`
  };

  transporter.sendMail(mailOptions, function(error, info){
    if (error) {
      console.log(error);
    } else {
      console.log('Email sent: ' + info.response);
    }
  });


  try {
    // const savedCompany = await newCompany.save();
    res.status(201).json(companyUserToken);
  } catch (err) {
    res.status(500).json(err);
  }
});

Can anyone see why i cannot pass this data and email the user? Appears to be an error with how it's passed but i can confirm that the endpoint works in postman if i just plug an email body in

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You are trying to send an email whenever the GET route is called. However, the data won't be sent inside as "req.body" as a GET request doesn't have a body.

If you are using GET method then the data is sent as query parameters.

router.get("/companyUser/invite/:email", async (req, res, next) => {
   console.log(req.params.email);
};

You can also either use a POST or PUT request in order to access the URL body

router.post("/companyUser/invite", async (req, res, next) => {
   console.log(req.body.email);
};
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!