Search code examples
phpmarketo

Marketo REST API to add to leads db. Successful result, but cannot see lead and no confirmation email


I'm using the Marketo REST API to add leads. Everything appears to be working fine, but I cannot find where the leads end up. The form is set up to send the submitter a confirmation email and that is not being sent.

First I get the form's data using the /rest/asset/v1/form/FORMID.json endpoint. Next I get all of the form fields using the /rest/asset/v1/form/FORMID/fields.json endpoint. Then I render the custom HTML for all of the fields and display it on the website's front-end. The form submission is done with AJAX and I send the data from PHP to the Marketo REST API. This all works fine.

Marketo returns a successful updated response when using an email address that has already been submitted:

stdClass Object
(
    [requestId] => f015#155f21eba78
    [result] => Array
        (
            [0] => stdClass Object
                (
                    [id] => 1035656
                    [status] => updated
                )

        )

    [success] => 1
)

And if it's a new email it returns a successful created response. Everything seems like it should be working perfectly, however I can't find the submissions.

Any ideas where these submissions could be ending up, and why they're not showing up as leads from the form? And why the confirmation email that's supposed to be sent for every successful submission is not being sent?


Solution

  • I belive, that the Form and Form Fields API endpoints serve a completely different purpose. Instead of helping to compose or render forms, these should be used to manage forms from remote systems.

    Another reason not to use these endpoints plainly to query the form fields is that these requests also count towards to your daily API usage limits. In a bigger Marketo instance that is a precious resource.

    In case your backend is simply to receive the AJAX requests and pass the values to the Sync Leads endpoint (POST /rest/v1/leads.json) than I would rather use an embedded Marketo form on the client side. The html code for the embed code is like so:

    <script src="//app-lon06.marketo.com/js/forms2/js/forms2.min.js"></script>
    <form id="mktoForm_{{FORM_ID}}"></form>
    <script>MktoForms2.loadForm("//app-abc01.marketo.com", "{{MUNCHKIN_ID}}", {{FORM_ID}});</script>
    

    Actually, this would be a good method to debug your current process as well. (If the result of that form submission shows up in your Marketo correctly, than the issue most probably is in the backend code.) Also, please note that when the form is rendered this way, the submitted dataset will hold some additional fields like _mkt_trk and _mktoReferrer, which might affect the result of the processing.

    As for posting to /rest/v1/leads.json: the fields representing a lead in the input array in the request body don't have to match the fieldset of any form. In fact as the documentation states

    The request must also have an input parameter, which is an array of lead records. Each lead record is a JSON object with any number of lead fields. The keys included in a record should be unique for that record.

    Having said all that, it should be clear now, why pushing a lead to the /rest/v1/leads.json endpoint does not trigger the Form Fillout event. A workaround to that could be to use the Push Lead endpoint (POST /rest/v1/leads/push.json) with which you can also set a programName and programStatus parameter. That will not just create the Lead record, but also will also associate the Lead with the defined program. In your Marketo instance the only thing you will need to modify is the Smart List of your campaign that now observes the Form fillout.

    Yet another note: still, all these requests are counting towards your API limits. Consider using the embedded form –mentioned above– instead. By leveraging the javascript API you can set up an AJAX like behavior as well. Like so:

    MktoForms2.loadForm("//app-abc01.marketo.com", "{{MUNCHKIN_ID}}", {{FORM_ID}}, function(form) {
        // Add an onSuccess handler
        form.onSuccess(function(values, followUpUrl) {
            // Get the form's jQuery element and hide it
            form.getFormElem().hide();
            // Return false to prevent the submission handler from taking the lead to the follow up url
            return false;
        });
    });