How to call a lead in a specific partition through Marketo API? | Community
Skip to main content
Level 2
May 31, 2023
Solved

How to call a lead in a specific partition through Marketo API?

  • May 31, 2023
  • 1 reply
  • 4155 views

Hi everyone, 

 

My marketo account has multiple partitions (partition A, partition B, partition C, etc). I am trying to create a python program that will get me certain data about leads in partition B. 

 

I have the below code that's setup and working but the leads in the results don't belong to partition B and I'm not able to find any data with leads IDs that belong to partition B. 

import marketorestpython.client import requests import json from marketorestpython.client import MarketoClient munchkin_id = "munchkinID" client_id = "clientID" client_secret= "clientsecret" args = {'grant_type': 'client_credentials', 'client_id': client_id, 'client_secret': client_secret} host = f'https://{munchkin_id}.mktorest.com' # Enter your Marketo API credentials here marketo_client_id = client_id marketo_client_secret = client_secret # Get the lead id from the user lead_id = [21286327] # Create a Marketo client object mc = MarketoClient(munchkin_id, client_id, client_secret) # Get the activity log for the lead activities = mc.execute(method='get_lead_activities', activityTypeIds=["2", "1"], sinceDatetime='2023-04-23T02:41:00Z') # Filter the activities to only include activities for the lead with the ID 20017335 filtered_activities = list(filter(lambda activity: activity['leadId'] == lead_id[0], activities)) # Print the filtered activities for activity in filtered_activities: print(activity)

 

Do you guys know if I'm missing out on some detail here as to why leads from partition B are not showing up? OR better yet, is there a way to filter data with the partitionName or partitionID? 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Darshil_Shah1

First up, you need to get the correct lead id that you're using to filter the activities endpoint's output. It appears that you're using this Marketo REST Python package in your code. This package has a method to Get Multiple Leads by Filter Type, in this method, you can specify the Partition Id of Partition B so people in Partition B are returned. I've posted a sample Get Multiple Leads by Filter Type method with the filterType set to leadPartitionId and the partition Id set to "2" (you'd need to update this to Partition B's Id in your case). Once you have correct Lead Ids, you can then use them to filter your activities data. 🙂

lead = mc.execute(method='get_multiple_leads_by_filter_type', filterType='leadPartitionId', filterValues=['2'], fields=['firstName', 'middleName', 'lastName'], batchSize=None)

Also, use the following function to get the Id of all the partitions present in your instance:

lead = mc.execute(method='get_lead_partitions')

Here's the reference of it in the GitHub repo as well.

 

I hope this helps. Let us know if you have any questions.

 

1 reply

Darshil_Shah1
Community Advisor and Adobe Champion
Darshil_Shah1Community Advisor and Adobe ChampionAccepted solution
Community Advisor and Adobe Champion
May 31, 2023

First up, you need to get the correct lead id that you're using to filter the activities endpoint's output. It appears that you're using this Marketo REST Python package in your code. This package has a method to Get Multiple Leads by Filter Type, in this method, you can specify the Partition Id of Partition B so people in Partition B are returned. I've posted a sample Get Multiple Leads by Filter Type method with the filterType set to leadPartitionId and the partition Id set to "2" (you'd need to update this to Partition B's Id in your case). Once you have correct Lead Ids, you can then use them to filter your activities data. 🙂

lead = mc.execute(method='get_multiple_leads_by_filter_type', filterType='leadPartitionId', filterValues=['2'], fields=['firstName', 'middleName', 'lastName'], batchSize=None)

Also, use the following function to get the Id of all the partitions present in your instance:

lead = mc.execute(method='get_lead_partitions')

Here's the reference of it in the GitHub repo as well.

 

I hope this helps. Let us know if you have any questions.

 

Alia99Author
Level 2
May 31, 2023

I tried retrieving the partition ID and it gave me 3 rows of data 

Even though the marketo account has more:

 

I think this is probably the reason why I'm not able to get the activity details for the lead in my partition. But I have no idea why the the get_lead_partitions aren't showing the rest. 

 

 

 

Darshil_Shah1
Community Advisor and Adobe Champion
Community Advisor and Adobe Champion
May 31, 2023

This appears to be the snapshot of Workspaces in your instance. To check the available Person Partitions in your instance, you should click on the next tab, i.e., the Person Partition tab (see the snapshot below):