I'm trying to get Report data about a Sent email through the API. I can see the report at:


And I can get data corresponding to the email from the API explorer as follows:

API explorer get civiMail

But I can't seem to access the civiMail report with the API. I have tried a few options but can't seem to find it. Any tips?

2 Answers 2


I think you're looking for the ReportTemplate.getrows API call. You can see examples of its use in the API explorer's built-in help (also available on Github). More examples exist in the tests folder, since the most common use of this API is to create tests for reports.

UPDATE: As @demerit points out, this answer isn't really correct - but it CAN be :) All(?) of the info on this mailing report is also available from the "Mailing Summary" report (for the stats) and the "Mailing Detail" report (if you need drilled-down data on click-throughs etc.). So I recommend Demerit's answer if you're writing an extension, but my answer if you need to collect this data over REST.

  • I don't know if this phrase has ever been said before but "Jon this answer might be wrong?". The mailing report here isn't a CiviReport it's a (CRM_XXX_)Page. Yes there are various mailing reports you can get from ReportTemplate.getrows but I don't think the one in question.
    – Demerit
    Commented Apr 17, 2019 at 3:17
  • @Demerit Good points. I updated my answer to improve it. Commented Apr 18, 2019 at 14:37

You might have to do something like this: https://github.com/civicrm/civicrm-core/blob/master/CRM/Mailing/Page/Report.php#L107-L110

For the $this variable, you can probably use a dummy, e.g. $page = new CRM_Mailing_Page_Report(); $page->_mailing_id = 388; // or whatever number $report = CRM_Mailing_BAO_Mailing::report($page->_mailing_id); CRM_Mailing_BAO_Mailing::getMailingContent($report, $page);

Lower down it assigns $report to the smarty template, and you can see how it's used at https://github.com/civicrm/civicrm-core/blob/master/templates/CRM/Mailing/Page/Report.tpl, so you should be able to do the same thing in php, accessing the member elements of $report.

  • I'm not entirely sure how that would work. Is it possible to achieve what you describe in the API explorer?
    – user77510
    Commented Apr 16, 2019 at 16:54
  • I'm not completely sure that you CAN'T do it from the api, but the functionality seems partly tied to the page. I've updated answer a bit.
    – Demerit
    Commented Apr 16, 2019 at 17:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.