Retrieving customer and prospect information from Marketo using the API

March 5, 2014 | by

You can retrieve information about customers and prospects that are stored within Marketo using the getLead and getMultipleLeads SOAP API.  It is often desired to extract this information on a recurring basis to keep another system updated as customers and prospect information is updated or new records are created in Marketo.

We’ll show you the code sample that would be executed on a recurring basis to poll Marketo for updates.

The below diagram depicts the API calls that are made on a set periodic timer.  Depending on the use case, the periodic timer could be set to run the below code every 10 minutes.

getmultipleleads

The first call to getMultipleLeads will set the time range, batchSize and which fields are to be returned.  All leads within Marketo that were updated in the specified time range will be returned along with a streamPosition when more records are available than the batchSize specified.

SOAP Request for first call to getMultipleLeads:

SOAP Response from the first call to getMultipleLeads:

As long as the <remainingCount/> value is greater than 0, you will make subsequent calls to getMultipleLeads to paginate through the rest by passing the <newStreamPosition/> value  returned in the previous call into the <streamPosition/> parameter.

SOAP Request for subsequent call to getMultipleLeads:

This logic will continue as long as <remainingCount/> is greater than zero.

See below a sample Java program that executes the scenario described above.

Tips & Tricks:

When extracting large volumes of contacts out of Marketo it is recommended to tune the API request along the following parameters:

  • <includeAttributes/>: It is recommended that you only request those fields you are interested in keeping in sync with your system.  This reduces the payload of the response and increases query performance.
  • <batchSize/>: The API supports up to 1000 records to be returned in a single call.  Tuning this value down to 500 records also reduces the payload of the response.
  • <LastUpdatedAtSelector/>:  It is recommended to set both the <oldestUpdatedAt/> along with the <latestUpdatedAt/> pararameter to limit the date range.  For example, instead of making a single request for a year’s worth of data.  Break up the API calls to request smaller date ranges.

 

 

* This article contains code used to implement custom integrations. Due to its customized nature, The Marketo Technical Support team is unable to troubleshoot custom work. Please do not attempt to implement the following code sample without appropriate technical experience, or access to an experienced developer.