ajaxrestmarketo

Creating Leads in Marketo using REST API


I am trying to create leads in Marketo using their /rest/v1/leads.json endpoint. The process is working, but will not save 2 custom values for the lead - but the Name, email, phone etc are all getting saved for the new lead. The form is not a Marketo generated form, and I ran across this...

"The Munchkin admin page also allows you to enable the Munchkin API. With the Munchkin API, you can integrate third party software with Marketo and your web site; do custom tracking of events such as multimedia playback; and use your own, non-Marketo-generated forms to cookie users and/or create new leads in the Marketo database."

If I am using a non-Marketo-generated form - do I have to use the Munchkin API? I also noticed that there wasn't much in the 'field mapping' area of the admin for these custom fields - but I'm not sure if that matters when creating the lead or not thru the API.

Here is what the call looks like:

$.ajax({
    type: 'POST',
    url: 'https://xxx-xxx-xxxx.mktorest.com/rest/v1/leads.json?    access_token=tokenhere',
    data: '{    "action":"createOnly","lookupField":"email","partitionName":"name","input":[     {"firstName":'+$( "#first_name" ).val()+',"lastName":'+$( "#last_name"     ).val()+',"Email":'+$( "#email" ).val()+',"Phone":'+$( "#phone"    ).val()+',"Company":'+$( "#company" ).val()+',"Country":'+$( "#00NC00000050DlB"   ).val()+',"Industry":'+$( "#industry"        ).val()+',"googleclickid":'+gclid+',"googleVisitorID":'+accountId+'}]}',
    dataType : 'jsonp',
    crossDomain:true,
    success: function(data) { 
    },
    contentType: "application/json",
    dataType: 'json'
});

(gclid & accountId have a values)

The fieldname XLS looks like this:

googleclickid    googleclickid    Google click id

googleVisitorID  googleVisitorID  Google Visitor ID

Solution

  • You should be able to create Leads including all custom fields using the REST API. No need to use the Munchkin API. Make sure you include the correct field names: in Admin > Field Management you can download an XLS with the field names for the REST API. There are also some system fields that cannot be modified using the REST API.

    EDIT: Based on the additional info you provided, fix the following:

    To test, I would recommend using an interactive tool like cURL or Postman before updating your script. That allows you to see any error messages and adjust your code accordingly.

    (If this solves your issue, please plus the answer; I'm trying to get to 50 reputation so I can comment :-)