Help needed regarding fetching the latest 30 activities using the marketo REST API
"I'm interested in retrieving the most recent 30 'Send Email' activities for leads using the Marketo REST API, sorted by 'activityDate' in descending order (from the most recent to the least recent). Could you please guide me on how to achieve this?
Currently, my approach involves the following steps:
Retrieve the creation date of a lead using their leadID.
/rest/v1/leads.json?filterType=id&filterValues=5799Create a 'nextPageToken' by setting the 'sinceDatetime' parameter to the lead's creation date.
/rest/v1/activities/pagingtoken.json?sinceDatetime=2023-11-04T09:29:50.839ZFetch all 'Send Email' activities until 'moreResults' is 'false' since the results are paginated.
/rest/v1/activities.json?leadIds=5799&activityTypeIds=6&nextPageToken=<value from step 2>Sort the results based on 'activityDate' in descending order.
Return the top 'min(results.length, 30)' results.
However, I'm not entirely satisfied with this solution because it requires multiple API calls to retrieve the most recent 30 activities, starting from the beginning. Is there an alternative approach while getting nextPageToken for 1st page such that it gets me the desired result or do I have to provide sinceDatetime?