Search code examples
marketo

Marketo Leads - How to find the updated values of progressionStatus field


I need to get the Marketo Leads who have changes on "progressionStatus" field (inside membership) with the API. I can get all the leads related to a Program (with Get Leads by ProgramID API) without issues, but my need is to get those Leads with changes on "progressionStatus" column. I was thinking to use the CreatedAt / UpdatedAt fields of the Program, so then, get all the leads related to those programs. But I didn't get the accurate results that I want. Also, I tried to use the GET Lead changes API and use "fields" parameter to "progressionstatus" but that field don't exist.

It is possible to resolve this? Thanks in advance.


Solution

  • You can get the list of Leads with progression status change by querying against the Get Lead Activities endpoint.

    The Get Lead Changes endpoint could sound as a good candidate, but that endpoint only returns changes on the lead fields. Progression status change is not stored on the lead directly, so at the end that won't work. On the other hand the Get Leads by ProgramId endpoint returns –amongst others– the actual value of progressionStatus (program status of the lead in the parent program) but not the “change” itself, so you cannot process the resultset based on that.

    The good news is that the progression status change is an activity type and luckily we have the above mentioned Get Lead Activities endpoint (which is also mentioned as the Query in the API docs) available to query just that. This endpoint also allows for filtering by activityTypeIds to narrow down the resultset to a single activity type.

    Basically you have to call the GET /rest/v1/activities.json enpoint and pass the values of activityTypeIds and nextPageToken as query parameters (next to the access token obviously). So, first you need to get the internal Id of the activity type called “Change Status in Progression”. You can do that by querying the GET /rest/v1/activities/types.json endpoint and look for a record with that name. (I don't know if this Id changes from instance to instance, but in ours it is the #104). Also, to obtain a nextPageToken you have to make a call to GET /rest/v1/activities/pagingtoken.json as well, where you have to specify the earliest datetime to retrieve activities from. See more about Paging Tokens.

    Once you have all of these bits at hand, you can make your request like that:

    GET https://<INSTANCE_ID>.mktorest.com/rest/v1/activities.json?activityTypeIds=<TYPE_ID>&nextPageToken=<NEXTPAGE_TOKEN>&access_token=<ACCESS_TOKEN>
    

    The result it gives is an array with items like below, which is easy to process further.

    {
        "id":712630,
        "marketoGUID":"712630",
        "leadId":824864,
        "activityDate":"2017-12-01T08:51:13Z",
        "activityTypeId":104,
        "primaryAttributeValueId":1104,
        "primaryAttributeValue":"PROGRAM_NAME",
        "attributes":[
            {"name":"Acquired By","value":true},
            {"name":"New Status ID","value":33},
            {"name":"Old Status ID","value":32},
            {"name":"Reason","value":"Filled out form"},
            {"name":"Success","value":false},
            {"name":"New Status","value":"Filled-out Form"},
            {"name":"Old Status","value":"Not in Program"}
        ]
    }
    

    Knowing the leadIds in question, you can make yet another request to fetch the actual lead records.