Skip to main content
Jan 15, 2013 2:41 AM UTC
Duplicate

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 replies

Jan 15, 2013 4:52 PM UTC
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.
Translate
Jan 16, 2013 5:54 AM UTC
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
Translate
Jan 16, 2013 5:14 PM UTC
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.
Translate
Jan 17, 2013 10:01 AM UTC
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


Translate
Jan 18, 2013 7:40 PM UTC
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?
Translate
Jan 18, 2013 11:06 PM UTC
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.
Translate
Feb 24, 2020 8:04 PM UTC
No text available
Translate