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

179
Views
javascript body is empty on api - but not empty when sending the request

I'm creating a simple API request where I post the basket information of a sale on my woocommerce site to my API. Unfortunately, the body of the api call keeps being empty. I'm clearly missing something really stupid.

var saleObjects = []

//Get the product names
document.querySelectorAll("td.product-name").forEach(function(item){
    var saleItem = {};
    saleItem.title = item.innerText;
    saleObjects.push(saleItem);
});
        
//Get the product prices
document.querySelectorAll("td.product-total").forEach(function(item, i) {
    saleObjects[i].price = item.innerText
    saleObjects[i].commission = 0.05
    saleObjects[i].url = window.location.hostname
});

fetch(API_URL,{
    method: "POST",
    mode: 'no-cors',
    headers: {
        'Accept': 'application/json',
        'Content-Type': 'application/json'
    },
    body: JSON.stringify({saleObjects: saleObjects})
    }
)
.then(function(response) {
    return response.json();
})
.then(function(jsonResponse) {
    //console.log(jsonResponse)
});

On my backend I'm doing something like this:

console.log("body");
console.log(req.body);
console.log("saleObjects")
console.log(req.body.saleObjects);

var saleObjects = []

if (req.body.saleObjects == undefined) {
    return res.status(401).send();
}

I've been going over this several times with no avail: Fetch: POST JSON data

Am I doing something totally stupid?

about 4 years ago · Juan Pablo Isaza
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!