Make.com API Integration Tutorial

Make.com API Integration Tutorial

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.
  • The sendData function uses the axios.post method to send a POST request to Make.com.
  • The request headers include 'Content-Type': 'application/json' and 'Authorization': 'Bearer your-access-token'.
  • If the response status is 200 and data is returned, the success flag is set to true. Otherwise, an error is logged and the success flag is set to false.
Scroll to Top