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

96
Visualizações
How to unmarshal array in POST request

I am trying to make a POST request to an API server and I am sending an array of JSON, the problem is that I get this error:

cannot unmarshal array into Go value of type models.UserRequest

I tried to unmarshal it using a factory and then initializing the objects, but I still get this error, how can I fix this error and make my request? Here is my code:

import fetch from 'node-fetch';
import xlsx from 'xlsx';
const baseUrl = "";
const apiToken = "";
const accountId = "";
const wb = xlsx.readFile('users.xlsx');
const ws = wb.Sheets['users'];
const data = xlsx.utils.sheet_to_json(ws);
// console.log(data)
const options = {
  method: "POST",
  headers: {
    Authorization: `Bearer ${apiToken}`,
    "gtmhub-accountid": accountId,
    "Content-type": "application/json; charset=UTF-8",
    Accept: "application/json, text/plain, */*",
  },
 

  body: JSON.stringify(
    data
  ),
};


const createUser = (url, settings) => {
  return fetch(`${url}/users`, settings)
    .then((response) => response.text())
    .then((data) => console.log(data))
    .catch((error) => {
      console.log(error.message);
    });
};

createUser(baseUrl, options);
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You should be able, that you send right object structure to you api service. Also this seems like as the problem on the api service side

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