SOLVED

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

Go to solution
Alia99
Level 1

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

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? 

1 ACCEPTED SOLUTION

Accepted Solutions
Darshil_Shah1
Level 10 - Community Advisor + Adobe Champion

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

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.

 

View solution in original post

9 REPLIES 9
Darshil_Shah1
Level 10 - Community Advisor + Adobe Champion

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

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.

 

Alia99
Level 1

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

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

Alia99_0-1685537698451.png

Even though the marketo account has more:

Alia99_2-1685537811605.png

 

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
Level 10 - Community Advisor + Adobe Champion

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

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):

Darshil_Shah1_0-1685545044218.png

 

 

Alia99
Level 1

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

Thanks so much for the promptly responses. It's the same on partitions tab too, tho 

Alia99_1-1685549811120.png

I can see all the partitions listed on the page, but not when I'm calling the details by code

Darshil_Shah1
Level 10 - Community Advisor + Adobe Champion

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

Interesting! Could you make a GET call to this endpoint and see if you get all the Person Partitions in the response or not?

 

 

Alia99
Level 1

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

I tried the following code to get the list of partitions 

# Make a GET request
response = requests.get('https://[marketo-instance].marketo.com/rest/v1/leads/partitions.json',
                         headers={'Authorization': 'Bearer ' + "[access-token]"})

print(response)

# # Parse the response
lead_partitions = response.json()

# # Print the lead partitions
for lead_partition in lead_partitions:
    print(lead_partition)

 

Print(response) gave result: 

<Response [200]>

 I'm assuming this to mean that the response is empty and marketo is not returning any data.  

Darshil_Shah1
Level 10 - Community Advisor + Adobe Champion

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

Please pass the access_token = <access-token> and authorization = bearer as the query parameters. Below's the CURL in case you want to refer:

 

curl --location --request GET 'https://123-BBB-CCC.mktorest.com/rest/v1/leads/partitions.json?access_token=<access-token>&authorization=bearer'

Python script:

import requests

url = "https://123-BBB-CCC.mktorest.com/rest/v1/leads/partitions.json?access_token=<access-token>&authorization=bearer"

payload={}
headers = {}

response = requests.request("GET", url, headers=headers, data=payload)

print(response.text)

 

 

Alia99
Level 1

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

hmmm there is still only the same 3 partitions that's showing up as response. 

Alia99_0-1685603124211.png

 

Darshil_Shah1
Level 10 - Community Advisor + Adobe Champion

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

Ideally, this endpoint should return all the available person partitions in an instance. I re-checked this on my end, and it worked fine. If you're okay, we can hop on a call to troubleshoot this. Send me a DM with your availability so we can connect.