I use axios in a pet project and have a code sample from the BambooHR API (https://documentation.bamboohr.com/reference#request-custom-report-1). They use node-fetch, so I was rewriting it to axios. The sample code is:
const fetch = require("node-fetch");
const url =
"https://api.bamboohr.com/api/gateway.php/companyDomain/v1/reports/custom";
const options = {
method: "POST",
qs: { format: "JSON" },
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
fields: ["firstName", "lastName"],
title: "AllOfThem",
}),
};
fetch(url, options)
.then((res) => res.json())
.then((json) => console.log(json))
.catch((err) => console.error("error:" + err));
I translated it into a AXIOS post:
let res = await axios.post(
"https://api.bamboohr.com/api/gateway.php/" + domain + "/v1/reports/custom",
{
title: "AllOfThem",
fields: ["firstName", "lastName"],
},
{
auth: {
username: seckey,
password: "x",
},
params: { format: "JSON" },
headers: { Accept: "application/json" },
}
);
But I get a 400 'Bad request'. What do I wrong?