How to fetch email marketing insights data from Marketo using API?
## How to Fetch Email Marketing Insights Data from Marketo Using API
### Introduction
While Marketo doesn't offer a direct endpoint for querying reports, the underlying data that constitutes an "Email Performance Report" (email delivery, bounce, open, and click) is accessible via the API. This means you can gather the necessary data to build your own report.
### API Endpoints
#### Querying Lead Activities
* **Endpoint:** GET /rest/v1/activities.json
* **Query Parameters:**
* `nextPageToken`: Indicates a datetime; activities after this date will be returned.
* `activityTypeIds`: Internal IDs of the activity types you're interested in.
#### Getting Activity Type IDs
* **Endpoint:** GET /rest/v1/activities/types.json
* **Output:** Array of activity types with names like `Send Email`, `Email Delivered`, etc.
#### Paging Tokens
* Activities are returned in paginated results. To retrieve subsequent pages, use the `nextPageToken` obtained from the `GET /rest/v1/activities/pagingtoken.json` endpoint.
### API Request
Once you have the necessary information, you can make the request to fetch the data:
```
GET https://<INSTANCE_ID>.mktorest.com/rest/v1/activities.json?activityTypeIds=<TYPE_ID>&nextPageToken=<NEXTPAGE_TOKEN>&access_token=<ACCESS_TOKEN>
```
### Response Format
The response is an array of items containing information such as:
* Activity ID
* Email name
* Activity type (e.g., `Click Email`)
* Lead ID
* Date of activity
### Data Processing
Filter the data based on the `primaryAttributeValue` property to identify specific emails and process the data accordingly.