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

180
Visualizações
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
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