//rest of code
//flow
let message= {
name: "lzgoflow",
language: "en_US",
category: "MARKETING",
components: [
{
type: "body",
text: "hello there",
},
{
type: "BUTTONS",
buttons: [
{
type: "FLOW",
text: "lzgo",
flow_id: 937561724890552,
navigate_screen: "lzgo flow",
flow_action: "navigate",
},
],
},
],
};
axios({
method: "POST",
url:
"https://graph.facebook.com/v12.0/" +
phone_number_id +
"/messages?access_token=" +
token,
data: message,
headers: { "Content-Type": "application/json" },
})
.then((response) => {
console.log("Message sent successfully:", response.data);
})
.catch((error) => {
console.error("Error sending message:", error.message);
});
}
res.sendStatus(200);
} else {
res.sendStatus(404);
}
});
This is my node.js code that request sending WhatsApp flows message, but every time I run it it gives me this error
Error sending message: Request failed with status code 400
I checked all the details (flow id, name and language code) it is all the same but it still gives me that error.
I think you have mixed the two API calls mentioned in the documentation. Seems like the message variable you have used is building request body for Creating a template but the Post call URL you are sending is for sending the template as in the example here.