Automation (Confluence): How to generate a list of pages and email the list?
Asked by P. Bryan Edge-Salois:

Hello! Hoping someone here can help me with this automation.

**Objective**: I am trying to create an automation that will generate a list of Confluence pages based on a CQL query and then email the list of pages (in a single email) to me.

**The Challenge** : The part I'm having trouble with is getting the automation to output the CQL query results into a single list/email. **Note**: The email method \*does work\* if I use a "For Each" branch -- but then I get 100 emails, each with a page title and link. :/

**The Deets**: My basic automation is as follows:

1. Trigger - Schedule
2. For Related Entities (CQL parameters/search)
3. Action - Send Email

This works fine outputting to the Audit Log -- but it's ugly and still requires a lot of work to make it more usable/actionable. I haven't figure out a way to get it all in a single email.

Does anyone have suggestions or know how to make this work?

Thanks in advance! :)


Answers:
author: Dylan Soechting
body: Hello [@P. Bryan Edge-Salois](/t5/user/viewprofilepage/user-id/5277664)

Branches do not support aggregating data for a single action like you are trying to accomplish here. However, [@Bill Sheboy](/t5/user/viewprofilepage/user-id/1685313) is correct that going with a manual web request to the Confluence API could enable you to accomplish your desired outcome.

I used the [Search content by CQL endpoint](https://developer.atlassian.com/cloud/confluence/rest/v1/api-group-content/#api-wiki-rest-api-content-search-get) to find pages by CQL query. Then I followed up in the Send email action with the[Multi-user picker smart values to use the fields from a list](https://support.atlassian.com/cloud-automation/docs/examples-of-using-smart-values-with-lists/) to put together an email body with the page title and page URL. I did need to hard code the base URL value in the email action. I will attach some screenshots that I hope will help.

![image.png](https://community.atlassian.com/t5/image/serverpage/image-id/273319iA61E7D933DB55446/image-size/large?v=v2&px=999 "image.png")![image.png](https://community.atlassian.com/t5/image/serverpage/image-id/273316iDAB8049218AD5A80/image-size/large?v=v2&px=999 "image.png")

comments: author: Darryl Lee
body: Hey [@Dylan Soechting](/t5/user/viewprofilepage/user-id/4419187) -

How about we make this into a feature request (NOTE to anyone discovering this page later **THIS IS NOT DOCUMENTATION, this is a FEATURE REQUEST**):
> **Lookup content**
>
> Search for up to 100 pieces of content using a CQL query. Include the results list in other actions by using the {{lookupContent}} smart value. Learn more about using smart values with issue lists.
>
> All properties can be accessed from the lookupContent list. For example, to print the titles and links for each page in bullet point form:
>
> {{#lookupContent}}{{title}}: {{url}}  
> {{/}}

(Yes, there's the question of whether content is a page or blogpost, although I think blogposts can have titles too.)

I mean, you have {{cqlResult}}, so the data is there. You just need to make it into an iterable list.

Thanks!!


author: Avinoam
body: Hi [@Darryl Lee](/t5/user/viewprofilepage/user-id/1365322) ! You're totally right :) This is something we have in our backlog to address within Confluence, and we'll be sure to post public updates once this is supported!


author: P. Bryan Edge-Salois
body: Yes -- this is a vastly over-complicated workaround for a very simple action: Isolate content by ancestor or parent, evaluate the created/modified dates, and output a list to a log or in an email.

This is very simple functionality that should be easy to build.


author: Jacquelyn Gallegos
body: Was there ever an update on this feature request? Do we have visibility on the feature request so we can look for any updates?

Thank you!!!


author: Dylan Soechting
body: [@P. Bryan Edge-Salois](/t5/user/viewprofilepage/user-id/5277664) Hello! I just wanted to circle back and make sure that you're aware that we have released a new action called "Lookup pages" which should make accomplishing your goal much easier. The action is very similar to the "Page branch", except instead of doing some action for every single page found, it will aggregate all of the results in a single smart value.

You can read a bit more about the action in [this post](https://community.atlassian.com/t5/Confluence-articles/New-Rule-Validations-New-Lookup-Pages-Action-New-Template-and/ba-p/2564083#M6928).


author: Bill Sheboy
body: Hi [@P. Bryan Edge-Salois](/t5/user/viewprofilepage/user-id/5277664) -- Welcome to the Atlassian Community!

First thing, I do not have Confluence automation rules in my site, so I am making a suggestion based on what I know of automation for Jira. With that out of the way...

Your use case is similar to using a scheduled rule on Jira issues and wanting one email communication (rather than one for each issue returned by JQL). For Jira Cloud, you could use "Lookup Issues"...there does not appear to be an equivalent for Confluence automation.

Instead I wonder: could you use a web request action to call the Confluence REST API, and then iterate over the response to list the pages in a single email?

Kind regards,  
Bill

comments: author: P. Bryan Edge-Salois
body: It's an interesting avenue to look into! Thank you!

One would think this sort of functionality would be easier to build with standard tools...