1

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?

1 Answer 1

2

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/

Sign up to request clarification or add additional context in comments.

1 Comment

Hm, yeah that would make sense that JotForm's call isn't even evaluating it. I'll have to take a look into using the SOAP api instead of the munchkin. Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.