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

97
Views
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 answers
Answer question

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 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!