I'm trying to write to a vendor's custom server which I do not have access to.The server does not have PHP and Curl installed.
So I am wondering is there any way I can simulate the Ajax request from the webhook itself without PHP and curl. This is the code I have so far.
<?php
?>
<script src="./js/jquery-3.4.1.min.js"></script>
<?php
$input = json_decode(file_get_contents('php://input'), true);
error_log(print_r($input, true));
$ZapierPostData = json_decode($_POST['data'], true);
$zapEmail = 'hooktest099@aaa.aaa';
$zapFull_name = 'hooktestor';
$zapContact = '011-1234-5678';
$zapcreated_on = '06/08/20 05:21AM';
$zapPreferred_branch = 'TTDI';
$zapUtm_campaign = 'FB202006 - Contact Lens';
$zapUtm_services = '8D649FB69397';
$zapUtm_medium = 'Malaysia';
$zapUtm_source = 'FB Lead Ads';
$zapUtm_term = $ZapierPostData['utm_term'];
if($zapEmail != '')
{
?>
<script>
var url = "https://mydomainname.com:81/api/";
var Lookrequest = {
"accessKey" : "A674FCFBDF643E6D",
"version" : "1.4",
"lookup" : "Preferred Branch"
};
postLook("leads/lookup", Lookrequest, function(result, data) {
if (result == false) {
alert("Error (" + data + ")");
} else {
var PostPreffBranch = "<?php echo $zapPreferred_branch; ?>";
$.each( data.list, function(i) {
var GetFullName = data.list[i].name;
//var incStr = PostPreffBranch.includes(GetFullName);
if(GetFullName == PostPreffBranch)
{
var FoundPreffBranchCode = data.list[i].code;
var Zaprequest = {
"accessKey" : "A674FCFBDF643E6D",
"version" : "1.4",
"name" : "<?php echo $zapFull_name; ?>",
"telephone" : "<?php echo $zapContact; ?>",
"email" : "<?php echo $zapEmail; ?>",
"preferredBranch" : FoundPreffBranchCode,
"referralType" : "<?php echo $zapUtm_source; ?>",
"marketingCampaign" : "D5552F037140",
"services" : "<?php echo $zapUtm_services; ?>",
};
Zapcreate(Zaprequest);
}
});
}
});
function postLook(method, Lookrequest, callback) {
$.post(url + method, Lookrequest, function (response)
{
return callback(true, response);
});
}
function Zapcreate(Zaprequest)
{
postZp("leads/create", Zaprequest, function(result, data) {
});
}
function postZp(method, Zaprequest, callback) {
$.post(url + method, Zaprequest, function (response)
{
//alert('final line');
//alert(JSON.stringify(response)); // this will show lead id or coremedica
//return callback(true, response);
});
}
</script>
<?php
}
?>
Alternatively what can I do when zapier pushes the data load to my webhook and my webhook will not trigger the jquery POST to write to the server?
Open to alternative solutions for this as well.
Thanks guys.