Reputation: 326
This is my first attempt at creating a webhook endpoint, and I'm running into some issues. I'm sending a webhook from a JotForm to a php file on my server. The php is executing perfectly, but I also have some scripts in the file that reference an external script and run a function.
The end goal is to send the submission data from the jotform to our Marketo CRM using Marketo's API. However, the scripts in the endpoint don't seem to execute. This same script works perfectly if I set it up so the user actually hits a page with this script on it, but it doesn't work if I try to execute it through a webhook behind the scenes. Any idea what I'm missing? Here's the code in its entirety:
<?php
//Strips all slashes in an array
function stripslashes_deep($value){
$value = is_array($value) ?
array_map('stripslashes_deep', $value) :
stripslashes($value);
return $value;
}
$result = stripslashes_deep($_REQUEST['rawRequest']);
//Convert json to php variable
$obj = json_decode($result, true);
//Initialize input variables
$theName = $obj['q1_name'];
$theEmail = $obj['q3_email'];
?>
<!----------------Marketo Munchkin API------------------------------>
<script src="http://munchkin.marketo.net/munchkin.js" type="text/javascript"></script>
<script>
mktoMunchkin("OUR_MARKETO_ID");
mktoMunchkinFunction(
'associateLead',
{
Email: <?php echo "decodeURIComponent(\"" . rawurlencode($theEmail) . "\")" ?>,
FirstName: <?php echo "decodeURIComponent(\"" . rawurlencode($theName) . "\")" ?>
},
'<?php echo hash('sha1', 'our-secret-key' . $theEmail); ?>'
);
</script>
<!---------------------------------------------------------------->
The "OUR_MARKETO_ID" and "our-secret-key" in the code contains our credentials.
Is there another way I should be executing the JS?
Upvotes: 1
Views: 1671
Reputation:
This same script works perfectly if I set it up so the user actually hits a page with this script on it, but it doesn't work if I try to execute it through a webhook behind the scenes.
That seems to indicate that whatever is calling your webhook isn't evaluating the javascript at all. JotForm probably calls your webhook with a simple HTTP client or even a low-level Curl command, not a real browser that executes javascript.
I think you need to ditch javascript and use PHP. Doing all of this server-side is the only way to ensure that it runs regardless of what kind of client calls your webhook.
Looks like Marketo provides a SOAP api which you could use in PHP. Perhaps the synchLead
method is what you need:
http://developers.marketo.com/documentation/soap/synclead/
Upvotes: 2