Re: Importing Data from a Webhook into Marketo via Munchkin API

Anonymous
Not applicable

Importing Data from a Webhook into Marketo via Munchkin API

I'm having an issue importing data from a webhook into marketo. This data is coming from a Jotform (www.jotform.com). I'm sending the data from the form to a webhook on my web server. The code in the webhook is:

<?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_ACCT_ID");
  mktoMunchkinFunction(
   'associateLead',
   {
      Email: <?php echo "'" . $theEmail . "'"; ?>,
      FirstName: <?php echo "'" . $theName . "'"; ?>,
   },
   '<?php echo hash('sha1', 'our-secret-key' . "'" . $theEmail . "'"); ?>'
);
</script>
<!---------------------------------------------------------------->


And obviously, "OUR_ACCT_ID" and "our-secret-key" are using our actual values.

However, no data is coming into Marketo at all. Any ideas where I'm going wrong? I can get the munchkin script to work if the user actually visits that php file and brings the $_POST values from the form with them ... but it doesn't work if the values are sent over a webhook to my php file with JSON. Any help would be awesome, I can't figure out why it won't connect. Thanks!
Tags (1)
3 REPLIES 3
Kenny_Elkington
Marketo Employee

Re: Importing Data from a Webhook into Marketo via Munchkin API

Hey Eric,

You should remove the final comma from the 'associateLead' array.  Instead of this:

FirstName: <?php echo "'" . $theName . "'"; ?>,

It should be this:


FirstName: <?php echo "'" . $theName . "'"; ?>

Anonymous
Not applicable

Re: Importing Data from a Webhook into Marketo via Munchkin API

Kenny,

Thanks for the response. However, it still doesn't work with removing the comma. I've tried several different variations of the code and can't get anything to work. My webhook endpoint is simply a PHP file in the root of my web server, and has public access. I can confirm the file works, as I'm able to print $theName and $theEmail to a file and they include the correct values. But for some reason the script doesn't seem to run or send any data.

Does it have anything to do with the fact that the user is not actually visiting the page where this code is run? The form sends the submission data over a webhook (HTTP callback) behind the scenes to this endpoint - which is on an entirely different server.
Kenny_Elkington
Marketo Employee

Re: Importing Data from a Webhook into Marketo via Munchkin API

Hey Eric,

Where is the JS itself being executed?  Are you retrieving that script via an XHR, and then executing it client-side?  If so what has you testing shown?  Is the associateLead GET being sent out of the browser?  Could you provide an example of a call that comes out?