Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

162
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda