# Automatically email admin report CSVs on a recurring cadence

**URL:** https://meta.discourse.org/t/automatically-email-admin-report-csvs-on-a-recurring-cadence/267283
**Category:** Feature
**Tags:** email
**Created:** [June 5, 2023, 5:40pm UTC](https://meta.discourse.org/t/automatically-email-admin-report-csvs-on-a-recurring-cadence/267283 "2023-06-05T17:40:32Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![paigen11](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/paigen11/32/229055_2.png) [@paigen11](https://meta.discourse.org/u/paigen11)
#### Post date: [June 5, 2023, 5:40pm UTC](https://meta.discourse.org/t/automatically-email-admin-report-csvs-on-a-recurring-cadence/267283/1 "2023-06-05T17:40:32Z")

</div>

Hello,

I was hoping there might be a way to automate emailing the downloadable reports available on the Discourse admin panel to a defined email list on a recurring basis (like weekly or monthly CSV reports of Trending Topics, for instance).

In the meantime, I built my own Python script to get the data from the Discourse API and create a CSV, but if there’s already a pre-built solution I could use instead, I’d prefer it.

Thanks very much,  
Paige

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [June 5, 2023, 6:13pm UTC](https://meta.discourse.org/t/automatically-email-admin-report-csvs-on-a-recurring-cadence/267283/2 "2023-06-05T18:13:20Z")

</div>

> [@paigen11](#):
>
> I built my own Python script to get the data from the Discourse API and create a CSV,

Unless you want to write a plugin, that’s what to do.

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [June 6, 2023, 12:38am UTC](https://meta.discourse.org/t/automatically-email-admin-report-csvs-on-a-recurring-cadence/267283/3 "2023-06-06T00:38:31Z")

</div>

Discourse automation has this option you may find handy, can you try it out and let us know what you think?

 ![schedule PM with data explorer using discourse automation in admin section](https://global.discourse-cdn.com/meta/original/4X/e/3/8/e389ba2fcba1ef06a0dcdaed43cd3b1fca8a96a2.png)

---

<div class="post-metadata">

### Author: ![paigen11](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/paigen11/32/229055_2.png) [@paigen11](https://meta.discourse.org/u/paigen11)
#### Post date: [June 6, 2023, 2:08pm UTC](https://meta.discourse.org/t/automatically-email-admin-report-csvs-on-a-recurring-cadence/267283/4 "2023-06-06T14:08:10Z")

</div>

Thanks for pointing this out, Sam - I had no idea it existed even after the amount of time I spent perusing various Discourse threads in my search for it.

Follow up question though: after looking through the existing SQL [Data Explorer](https://meta.discourse.org/t/32566?silent=true) queries in the GitHub repo and making a few attempts at writing my own, is there somewhere where I can pull the query that generates the “Trending Search Terms” report available in the Discourse admin dashboard for the past month (term, search count, CTR)?

I’ve used the `admin/reports/trending_search.json` API to get the info manually, but I’d like to use a Discord cron job here if possible.

---

<div class="post-metadata">

### Author: ![paigen11](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/paigen11/32/229055_2.png) [@paigen11](https://meta.discourse.org/u/paigen11)
#### Post date: [June 6, 2023, 3:19pm UTC](https://meta.discourse.org/t/automatically-email-admin-report-csvs-on-a-recurring-cadence/267283/5 "2023-06-06T15:19:08Z")

</div>

I figured out the query to run in [Data Explorer](https://meta.discourse.org/t/32566?silent=true), it is:

```plaintext
SELECT term, count(*) searches, 
 sum(case when search_result_id is not null then 1 else 0 end) clicks,
 round(sum(case when search_result_id is not null then 1 else 0 end) * 100.0 / count(*), 1) as ctr
from search_logs
where created_at > current_timestamp - interval '30' day
group by term
order by count(*) desc

```

So my final, final question is: is there a way in the Automation, to have this query run and turn the results into a CSV attached to the email for the recipients instead of the results posted in the body of the email?

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [June 6, 2023, 8:15pm UTC](https://meta.discourse.org/t/automatically-email-admin-report-csvs-on-a-recurring-cadence/267283/6 "2023-06-06T20:15:54Z")

</div>

> [@paigen11](#):
>
> So my final, final question is: is there a way in the Automation, to have this query run and turn the results into a CSV attached to the email for the recipients instead of the results posted in the body of the email?

Not at the moment but it is a very good feature request, and should not be too hard to change

Can you post a dedicated topic for this ?

---

<div class="post-metadata">

### Author: ![paigen11](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/paigen11/32/229055_2.png) [@paigen11](https://meta.discourse.org/u/paigen11)
#### Post date: [June 7, 2023, 1:15pm UTC](https://meta.discourse.org/t/automatically-email-admin-report-csvs-on-a-recurring-cadence/267283/7 "2023-06-07T13:15:54Z")

</div>

Happy to. New [feature request here](https://meta.discourse.org/t/turn-data-explorer-query-results-into-csv-to-attach-to-discourse-automated-emails/267529) - thanks very much!

---

<div class="post-metadata">

### Author: ![Thas](https://avatars.discourse-cdn.com/v4/letter/t/b19c9b/32.png) [@Thas](https://meta.discourse.org/u/Thas)
#### Post date: [June 7, 2023, 2:59pm UTC](https://meta.discourse.org/t/automatically-email-admin-report-csvs-on-a-recurring-cadence/267283/8 "2023-06-07T14:59:14Z")

</div>

> [@sam](#):
>
> ![schedule PM with data explorer using discourse automation in admin section](https://global.discourse-cdn.com/meta/original/4X/e/3/8/e389ba2fcba1ef06a0dcdaed43cd3b1fca8a96a2.png)

What does PM stand for?

---

<div class="post-metadata">

### Author: ![Moin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/moin/32/554653_2.png) [@Moin](https://meta.discourse.org/u/Moin)
#### Post date: [June 7, 2023, 3:15pm UTC](https://meta.discourse.org/t/automatically-email-admin-report-csvs-on-a-recurring-cadence/267283/9 "2023-06-07T15:15:30Z")

</div>

PM is user for personal message  
The second line also says “to your messages”

---

<div class="post-metadata">

### Author: ![Thas](https://avatars.discourse-cdn.com/v4/letter/t/b19c9b/32.png) [@Thas](https://meta.discourse.org/u/Thas)
#### Post date: [June 7, 2023, 4:02pm UTC](https://meta.discourse.org/t/automatically-email-admin-report-csvs-on-a-recurring-cadence/267283/10 "2023-06-07T16:02:07Z")

</div>

Yes but it hasn’t come to my messages therefore, I thought I may be missing something here.

Could I get this sent to my outlook instead?

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [June 8, 2023, 12:18am UTC](https://meta.discourse.org/t/automatically-email-admin-report-csvs-on-a-recurring-cadence/267283/11 "2023-06-08T00:18:45Z")

</div>

> [@Thas](#):
>
> Could I get this sent to my outlook instead?

As long as your outlook uses the same email address as your Discourse account, it should land there.
