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

90
Views
Sending data using post method via fetch returns an empty object

This is my function for addEventListener for the click event

export const showTicket = async function() {
  try {

    // GETTING USER DATA
    const response = await fetch("/api/v1/users/me");
    const data = await response.json();


    //
    const user = data.data.data;


    // CREATING VISITOR 
    const visitor = {
      VisitorNumber: user.visitorId,
      FirstName: user.firstName,
      LastName: user.lastName,
      Company: user.company,
      JobTitle: user.profile,
      Email: user.email,
      Mobile: user.mobile,
      Nationality: user.nationality,
      Country: user.country,
      Category: user.type,
    };

    // SENDING VISITOR OBJECT TO ANOTHER API

    const url = "/api/v1/eticket/visitor";

    const options = {
      method: "POST",
      header: {
        "Content-Type": "application/json",
      },
      body: JSON.stringify(visitor),
    };

    if (!user.eventId) {
      const response1 = await fetch(url, options);

      const data1 = await response1.json();

    }

    const ticketMarkup = `<div class="ticket">
  <div class="ticket__logo"> <img src="/images/vp-expo-logo.png"> </div>
  <div class="ticket__data">
  <p>Your ticket is ready to be printed</p>
 </div>
  <button class="btn ticket__print-ticket" data-visitor-id=${user.visitorId}> Print Ticket </button>
  <button class="btn update-data"> Update Data </button>
  </div>
  `;

    showPopup(ticketMarkup);
  } catch (err) {
    console.log(err);
  }
};

so first I am getting the user details from the api '/api/v1/users/me' which is working fine and I am able to retrieve the data and the I create a variable 'Visitor' using the user properties.

Then I have to send the visitor variable as a body to another api ('/api/v1/eticket/visitor') so that it can receive the body as req.body

But on the '/api/v1/eticket/visitor' the req.body shows as an empty object.

Here's the opening part of the controller for this receiving api ('/api/v1/eticket/visitor')

exports.addOneVisitor = async function(req, res, next) {
  try {
    const visitor = req.body;
    console.log(req.body);


Please advise what am I doing wrong?

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

0

Silliest Mistake Ever!!.. but one I keep repeating all the time. I am answering my own question as a reminder to me (and to anyone out there who makes the same typos repeatedly!)..

It's headers and not header when you write the options part for a fetch request.

Hope this helps someone to not lose 2 days of their life over a missing 's'

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!