I know this has been answered 38 million times elsewhere but I’m dumb. Please hammer it into my brain.
faxResponse
is returning undefined. I’m trying to do something like the below:
const Base64String = async (req, res) => {
let faxResponse = await postFax(req.body);
console.log(faxResponse); // undefined
if (faxResponse.status == "fail") {
return res.status(200).send({
statusCode: 400,
message: faxResponse.error,
});
} else {
return res.status(200).send({
statusCode: 200,
data: {
...req.body,
},
faxResponse,
});
}
};
const postFax = async ({
login,
pass,
faxnum,
faxsrc,
recname,
file1,
data1,
}) => {
const VITELITY_URL = `https://api.vitelity.net/fax.php?login=${login}&pass=${pass}&cmd=sendfax`;
let formdata = new FormData();
formdata.append("faxnum", faxnum);
formdata.append("faxsrc", faxsrc);
formdata.append("recname", recname);
formdata.append("file1", file1);
formdata.append("data1", data1);
await fetch(VITELITY_URL, {
method: "POST",
body: formdata,
redirect: "follow",
})
.then((res) => res.text())
.then((result) => {
console.log(result);
})
.catch((err) => console.log(err));
};