Mark Goodwin
Mark Goodwin

Reputation: 63

Inconsistent results using Marketo API - can't find campaign ID

I am using the python library marketo-rest-api to pull data from Marketo. I am just pulling one day to attempt to connect the dots from activities to campaigns. I am making the following calls:

print('Getting Campaigns') 
with open(marketoCampaignsFile,'w') as fcamp:
  campaigns = mc.execute(method='get_multiple_campaigns', id=None, name=None, programName=None, workspaceName=None, batchSize=None)
    for campaign in campaigns:
      jsonString = json.dumps(campaign)
      fcamp.write(jsonString)
fcamp.close()

print('Getting Activities...')
activitiesFile = 'c:\\users\\mark\\marketocsv\\emailActivities.2016-07-26.json'  
with open(activitiesFile,'w',newline='') as fopen:
  for activities in mc.execute(method='get_lead_activities_yield', activityTypeIds=['6','7','8','9','10'], nextPageToken=None, sinceDatetime='2016-07-26', untilDatetime='2016-07-27', batchSize=None, listId=None, leadIds=None):
    for item in activities:
      jsonString = json.dumps(item)
      fopen.write(jsonString+'\n')
fopen.close()

What I have found is that the campaign IDs in the activities file do not match any of the campaign IDs in the campaign file. Does anyone know why this might be? I need campaign attributes in order to filter the specific activities that I need. Thanks.

Upvotes: 3

Views: 303

Answers (2)

Mark Goodwin
Mark Goodwin

Reputation: 63

So Jep was right. I did finally find the EmailID. It's called the primaryAttributeValueId. You can link this back to the EmailID provided by Marketo. I never did find the campaignID but I can get to the campaign through the email. Here's the full JSON from one of the requests:

{
    "primaryAttributeValue": "2016-07-Email-To-Customers",
    "activityDate": "2016-07-26T19:05:41Z",
    "attributes": [{
            "value": "0",
            "name": "Choice Number"
        },
        {
            "value": "43182",
            "name": "Step ID"
        }
    ],
    "primaryAttributeValueId": 17030,
    "leadId": 115345,
    "id": 393962103,
    "activityTypeId": 7,
    "campaignId": 15937
}

Upvotes: 1

Jep
Jep

Reputation: 384

The activity types that you are downloading don't include the Campaign ID, they provide the Email ID instead.

Upvotes: 1

Related Questions