Im using the whatsapp api to generate a file and send it to whatsapp api. I first test all parameters by postman and everything was great, postman generated this code:
const myHeaders = new Headers();
myHeaders.append("Authorization", "Bearer token");
myHeaders.append("Cookie", "ps_l=0; ps_n=0");
const formdata = new FormData();
formdata.append("file", fileInput.files[0], "/C:/Users/Sub2/Documents/Hoja de trabajo.docx");
formdata.append("type", "document");
formdata.append("messaging_product", "whatsapp");
const requestOptions = {
method: "POST",
headers: myHeaders,
body: formdata,
redirect: "follow"
};
fetch("https://graph.facebook.com/v19.0/{{media_id}}/media", requestOptions)
.then((response) => response.text())
.then((result) => console.log(result))
.catch((error) => console.error(error));
If you use this code it will upload the file to the whatsapp api.
The problem is that in node js its giving an error: {"error":{"message":"(#100) The parameter messaging_product is required.","type":"OAuthException","code":100,"fbtrace_id":"AAql5W804gIHMiKVCxX7InY"}}
The parameter messaging_product is required, but this code: formdata.append("messaging_product", "whatsapp");
add that parameter, i dont know what’s the problem. The only code part that is different in my node code is this formdata.append("file", fileStream);
im using the exceljs to generate a file, Thank you for any suggestions.