marketo

How to fetch email marketing insights data from Marketo using API?


I am trying to fetch "Email Performance Report" from the platform using API to analyze the KPI's like CTR etc by type of the email (newsletter,email marketing etc).

I went through the documentation, however I didn't find endpoint from which I can fetch the same.

Is there a way to get this information?


Solution

  • There is no endpoint to query reports directly. However, the good news is, that the “things” that make up an “Email Performance Report”, namely: email delivery, bounce, open and click are available to query via the API.
    This means that you have to build the report yourself, but you can fetch the dataset to work on.

    These “things” are called activity types (activity measured on a Lead) and can be fetched by querying against the Get Lead Activities endpoint, which is also mentioned as the Query in the API docs.
    It sits at the GET /rest/v1/activities.json url and you have to pass a nextPageToken and the activityTypeIds as query parameters.

    The nextPageToken indicates a datetime. Activities after that date will be returned by the call. To obtain one, you have to make a call to GET /rest/v1/activities/pagingtoken.json, where you have to specify the earliest datetime to retrieve activities from. See more about Paging Tokens.

    To figure out the value of activityTypeIds, you first need to get the internal Ids of the activity types you are interested in. In order to do so, you have to query the GET /rest/v1/activities/types.json endpoint and look for the activity types with names like Send Email, Email Delivered, Email Bounced, Unsubscribe Email, Open Email and Click Email. (I don't know if these Ids are changing from instance to instance, but in ours these are from #6 to #11).

    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. Items can be filtered to specific email based on the primaryAttributeValue property and processed further accordingly.

    {
        "id":7370416,
        "marketoGUID":"7170506",
        "leadId":291305,
        "activityDate":"2017-12-17T00:00:00Z",
        "activityTypeId":11,// #11 = `Click Email`
        "campaignId":1790,
        "primaryAttributeValueId":1638,
        "primaryAttributeValue":"EMAIL_NAME",// Name of the Email as seen in Marketo
        "attributes":[
            // …
        ]
    }