Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

156
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda