Updating Lead Data in Marketo using the API

August 14, 2015 | by

Over a year ago we posted Updating customer and prospect information in Marketo using the API.  That post presented a code sample that could be run on a recurring basis to poll a external system for updates.  The idea was to retrieve the external data and push it into Marketo to update lead information.  The code sample presented used our SOAP API.  This post will show you how to use Create/Update Leads REST endpoint to accomplish the same goal.

Updating_Lead_Data_Overview

Program Input

It is likely that you will need to transform the data from the external system into a format that is consumable by Marketo REST APIs.  Since we’re using the Create/Update Leads API, the data must be formatted as JSON which is sent in the request body.  This is best explained by an example.

In the Java sample code below, we have placed mock lead data in an array of strings.  Each string following data for each lead: first name, last name, email address, job title.

The sample code transforms the array into the JSON block below.

Each “input” array item corresponds to an individual lead in Marketo.  The array items are JSON objects that contain one or more Marketo lead field names and their respective values.

The field names that you decide to specify (in this case firstName, lastName, email, and title) must match the REST API name defined for the Marketo subscription.  You can find the REST API Names in the field management section within Marketo admin panel by exporting the field names.

field_management_export_field_names

The field names will be exported into an excel file as seen below.

field_names_in_excel

Alternatively, you can find field names programmatically by calling the Describe Lead API.  For example, here is a Describe response snippet that contains the REST API name for the First Name field.

Program Logic

Once the payload is in the proper format, we are ready to call Create/Update Leads.  Note that in this sample we do not specify any of the optional parameters.  The default behavior is to create or update lead records (upsert), use email for deduplication purposes, and use synchronous processing.

If the call to Create/Update leads is successful, then the response body contains a “result” array containing the Marketo Lead Id and the status of the Create/Update operation.  Depending on the “action” parameter you passed in the request, the status can be either “updated”, “created”, or “skipped”.

Continuing with our example, suppose the first lead did not exist (Henry Adams), and the second lead did exist (Suzie Smith).  A response similar to the following would indicate the first lead was created, and the second lead was updated.

That’s it for now.  Happy coding!

Program Code