This tutorial demonstrates how to send data to Make.com using JavaScript and Axios.
// Define a variable to track the success of the workflow
let workflowMakeSuccess = false;
// Mock user data for demonstration purposes
const userData = {
name: workflow.name, // User's name
email: workflow.email, // User's email
phoneno: workflow.phoneNumber, // User's phone number
message: workflow.Message, // User's message
timeout: "yes", // Timeout flag
};
// Asynchronous function to send data to Make.com
(async function sendData() {
try {
// Send a POST request to Make.com using Axios
const response = await axios.post('ENTER YOUR LINK HERE', userData, {
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer your-access-token' // Replace 'your-access-token' with your actual token
}
});
// Check if the response is successful
if (response.status === 200 && response.data) {
console.log('Data sent to Make.com successfully:', response.data);
workflowMakeSuccess = true; // Set success flag to true
} else {
console.log('Received unexpected status or no data:', response.status);
throw new Error('Failed to receive valid response from Make.com');
}
} catch (error) {
console.error('Error sending data to Make.com:', error.message);
workflowMakeSuccess = false; // Set success flag to false
throw new Error(`API communication failed: ${error.message}`);
}
})();
Explanation of the code:
workflowMakeSuccess: A boolean variable to track if the data was successfully sent.userData: An object containing user data to be sent to Make.com.sendData function uses the axios.post method to send a POST request to Make.com.'Content-Type': 'application/json' and 'Authorization': 'Bearer your-access-token'.