All Collections
πŸ”Œ Integrations
Zapier / Custom Webhooks
Zapier / Custom Webhooks
Maggie Buchanan avatar
Written by Maggie Buchanan
Updated over a week ago

If you need to send a service like Zapier, you can simply add a β€œcustom code” action to your buttons when you are capturing data in Amped.
​

Go to Button Actions -> Custom Code
​

This will run in the order it is in the Button Actions list


Built in "input" variable available from Custom Code

From a Custom Code block on Button Actions, you can use the already established variable 'input' which is an array for inputs that have been captured up to this point.


e.g. input.email or input.phone_number or any inputs you have set by their name.

‍

You can also access extra information about the current Campaign through the predefined variable of "metadata"


​metadata contains‍

  • metadata.campaign_id
    ​

  • metadata.campaign_title
    ​

  • metadata.variation_id
    ​

  • metadata.variation_name

‍

Copy and Paste-able Code for Custom Code Action

// βœ…  Edit the variables below to configure

var webhook_url = 'WEBHOOK_URL_HERE';

// payload is what will be sent to the webhook. We can fill it in with data that needs to be sent to the webhook.
var payload = {};

// 'input' contains any inputs captured. eg: the email input can be accessed through input.email
payload = input;

// If we also have user properties and we want to include them in the payload, we can access them from
var userProperties = JSON.parse(window.localStorage.getItem(`amped-${ampedConfig.accountId}-userProperties`));
if (userProperties){
payload.userProperties = userProperties;
}


// πŸ›‘ //////////////////////////////////////////
////////////////////////////////////////////////
// Leave this code as is unless you know what you're doing. This is sending request to webhook and continuing with Amped actions.
////////////////////////////////////////////////
fetch(webhook_url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(payload),
})
.then(response => {
if (response.ok) {
return response.json();
} else {
console.log('Amped.io: Custom Webhook Error: Network issue');
}
})
.then(data => {
console.log('Amped.io: Custom Webhook sent:', data);
})
.catch((error) => {
console.log('Amped.io: Custom Webhook error:', error);
});



////////////////////////////////////////////////
resolve(); // resolve(); tells your actions to continue. Othwerwise the campaign will load indefinitely, break, and it will timeout.



​

Did this answer your question?