Associate lead from external app to marketo

saurabhmehta13
Level 2

Associate lead from external app to marketo

In my external website (which is a react application) on click of a button (sign up button), I need to send marketo email.

When I embed marketo form, enter data in the form and submit, lead is getting associated in marketo. Email is also getting triggered by smart campaign.

However as per my UI requirements, I can't have marketo form in my page.

I am trying out the approach mentioned here -https://developers.marketo.com/blog/merge-anonymous-visitor-activity-when-visitor-fills-out-form/

I am calling munchkins associateLead function when a button is clicked in my page. 

Following is the code:

 

 

 

document.addEventListener("click", function (event) {
          if (event.target.id === "SignUP") {
            Munchkin.munchkinFunction(
              "associateLead",
              {
                Email: decodeURIComponent("myemail%40gmail.com"),
                FirstName: decodeURIComponent("Saurabh"),
                LastName: decodeURIComponent("Mehta"),
              },
              "my_api_private_key"
            );
          }
        });
})();

 

 

But in the network tab I could see 401 invalid request token error.

Here is the request URL in network tab - 

 

 

http://myinstance.com/webevents/associateLead?_mchNc=1587141013155&_mchKy=secret_api_key&_mchAtEmail=fname.lname78%40gmail.com&_mchAtFirstName=Saurabh&_mchAtLastName=Mehta&_mchId=some_id&_mchTk=_mch-localhost-15864149018-50069&_mchHo=localhost&_mchPo=3000&_mchRu=%2F&_mchPc=http%3A&_mchVr=158&_mchEcid=&

 

 

What am I missing here?

I am really stuck at this point. Really appreciate any inputs on this issue.

 

1 REPLY 1
SanfordWhiteman
Level 10 - Community Moderator

Re: Associate lead from external app to marketo

You can post a hidden Marketo form, there's no need to affect your UI.

 

associateLead can only be used if the hash is generated on your server. It must not be generated in the browser. And since it requires that you know the Email Address in both cases, you should use the hidden form. The main reason not to use the form is if the extra Filled Out Form in the ActLog is truly disruptive.