Lead Partitioning
Marketo Lead Partitions provide a convenient way to isolate leads. Partitions can allow different marketing groups within your organization to share a single Marketo instance. For more information, see Understanding Workspaces and Lead Partitions.
Suppose that you are using lead partitions and creating leads programmatically using the Marketo REST API. How do you ensure the leads that you create will end up in the correct partition? This post will show you how!
For the sake of this example, we’ll use Workspaces and Partitions to isolate our leads based on geography. First we’ll define a workspace called “Country”. Next, we’ll create two partitions within that workspace called “Mexico” and “Canada”.
Create Lead in Partition
Suppose now that we want to create two leads in the “Mexico” partition. To create leads, we call the Create/Update Leads API. To specify the partition, we must include the “partitionName” attribute in the request body.
How do we know what to use for the partitionName value? We can retrieve a list of valid partition name values for our instance by calling the Get Lead Partitions API as follows:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
GET /rest/v1/leads/partitions.json { "requestId": "20ae#14f9a1a5a30", "result": [ { "id": 1, "name": "Default", "description": "Initial system lead partition" }, { "id": 2, "name": "Mexico", "description": "Leads that live in Mexico" }, { "id": 3, "name": "Canada", "description": "Leads that live in Canada" } ], "success": true } |
In this case, the correct value is “Mexico”, so we then pass that to Create/Update Leads as follows:
1 2 3 4 5 6 7 8 9 10 |
POST /rest/v1/leads.json { "input": [ {"email":"enrique.pena-nieto@gob.mx"}, {"email":"angelica.rivera@gob.mx"} ], "action":"createOrUpdate", "partitionName":"Mexico" } |
Here are our newly created leads in Marketo.
Update Lead in Partition
To update existing leads in a partition, we simply call Create/Update Leads and specify partitionName the same as we did before. For this update, we’ll assign first name, last name, and title to the leads that we created above.
1 2 3 4 5 6 7 8 9 10 |
POST /rest/v1/leads.json { "input": [ {"email":"enrique.pena-nieto@gob.mx", "firstName":"Enrique", "lastName":"Pena Neito", "title": "El Presidente"}, {"email":"angelica.rivera@gob.mx", "firstName":"Angelica", "lastName": "Rivera", "title": "Primera Dama"} ], "action":"createOrUpdate", "partitionName":"Mexico" } |
Here are our newly updated leads in Marketo.
Identify Partition for a Lead
How do we know which partition that a lead is in? For this we use the Get Lead by Id API and specify “leadPartitionId” in the “fields” query parameter. In this case we will retrieve the information for lead id 318816 that we created above.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
GET /rest/v1/lead/318816.json?fields=leadPartitionId,email,firstName,lastName,title { "requestId": "5c57#14f9a495b1f", "result": [ { "id": 318816, "lastName": "Pena Neito", "title": "El Presidente", "email": "enrique.pena-nieto@gob.mx", "firstName": "Enrique", "leadPartitionId": 2 } ], "success": true } |
Note that we get back leadPartitionId rather than the partitionName. To get the partitionName we need to revisit the output from Get Lead Partitions API from above.
1 2 3 4 5 |
{ "id": 2, "name": "Mexico", "description": "Leads that live in Mexico" }, |
In this case a leadPartitionId value of 2 maps to partitionName of “Mexico”.
That’s all for now. Happy partitioning!