Process lead data with JavaScript after form submission and before Webhook

0 Likes

Process lead data with JavaScript after form submission and before Webhook

 

I'm using a WebHook to post lead info to an external RESTful API upon successful form submission.  This works perfectly...almost.
 
Because RESTful APIs are URL-based, the information is assumed be come through as URL-encoded.  Certain characters have different meaning when URL-encoded.  For example "+" means a blank space.  Some users filling out my form have legitamate "+" in their emali address (e.g. "name+last@email.com"), which are getting interperted as blank spaces by the 3rd party app (e.g. "name last@email.com").
 
I would like a way to process the lead data before it makes it to the Webhook. Basically, I'd like to pass the webhook template a version of lead.Email Address that has been passed through javascript's encodeURIComponent function.
 
I hope this is clear, and that there's an answer to this.
 
thanks,
Mark
7 Comments
Anonymous
Not applicable
One thing I do right now in these cases is write a very simple PHP wrapper around my function that handles the encoding the way I want. Not quite as elegant as having Marketo do it, but usually a lightweight solution.
Anonymous
Not applicable
Thanks, Erik.

So, perhaps Webhooks aren't right for this task.  

As a starting point for a PHP wrapper, would you recomend this Marketo Form Proxy v1.1.0?  Somethhing else?

--mark
Anonymous
Not applicable
Well, actually I meant using a webhook to call PHP which then did custom encoding and then called the API. As an example, here is how I was calling Twillio's SMS API:

<?php
require "Services/Twilio.php";
 
$AccountSid = "xxx";
$AuthToken = "xxx";
 
$client = new Services_Twilio($AccountSid, $AuthToken);
$from = 'xxx';
 
try {
$client->account->sms_messages->create($from, $_POST["number"], $_POST["message"]);
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}
echo "Sent";
?>

Instead of just passing in the details POST'ed in, you could encode them in some other way first.
Anonymous
Not applicable
Great tip.  Thanks!  

So I've written PHP script that defnitely works standalone at cleaning up $_POST data and calling the API in question (yay), but it doesn't seem to be getting hit by the webhook (boo!).

Any ideas?

--mark


Anonymous
Not applicable
I'm still stumped as to why my perfectly working PHP script works when accessed via web browsers doesn't seem to be getting hit my a WebHook that's associated with a valid trigger.

I see Erik's wrapper script returned "Sent"  Is that a requirement?
Anonymous
Not applicable
No, the "Sent" thing is just for debugging when I visit it through a web-browser. Not needed at all.

Not sure why the webhook isn't calling your webserivce though.
kh-lschutte
Community Manager
Status changed to: Already have it