# Syntax for Data Explorer params in Automation

**URL:** https://meta.discourse.org/t/syntax-for-data-explorer-params-in-automation/355916
**Category:** Bug
**Created:** [March 5, 2025, 7:08pm UTC](https://meta.discourse.org/t/syntax-for-data-explorer-params-in-automation/355916 "2025-03-05T19:08:21Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![ganncamp](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ganncamp/32/106199_2.png) [@ganncamp](https://meta.discourse.org/u/ganncamp)
#### Post date: [March 5, 2025, 7:08pm UTC](https://meta.discourse.org/t/syntax-for-data-explorer-params-in-automation/355916/1 "2025-03-05T19:08:21Z")

</div>

I have a [Data Explorer](https://meta.discourse.org/t/32566?silent=true) query that accepts a ‘group\_name’ parameter

 ![Selection_2249](https://global.discourse-cdn.com/meta/original/4X/6/a/2/6a20730ce1c4fc69dfcf6ee1dd5ce0abafbf38da.png)

I would like to automate running it for each relevant group and sending the group the results once a week.

But for the life of me, I cannot figure out the syntax to use for the parameter. Here’s what I’m presented for that in a brand new automation:

 ![Selection_2250](https://global.discourse-cdn.com/meta/original/4X/2/1/a/21a55c03a1448dad4e7bc37860db41b799973849.png)

I find this… unhelpful.

I’ve tried several variations here. When I don’t get an error from my attempts (found in the error logs), I seem to get nothing at all.

If I use a query with no parameters, it runs like greased lightning. How do I make it work for queries that do need parameters?

---

<div class="post-metadata">

### Author: ![Arkshine](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/arkshine/32/298682_2.png) [@Arkshine](https://meta.discourse.org/u/Arkshine)
#### Post date: [March 5, 2025, 10:46pm UTC](https://meta.discourse.org/t/syntax-for-data-explorer-params-in-automation/355916/2 "2025-03-05T22:46:45Z")

</div>

I can reproduce the issue as well.

In your example, let’s say you want to check the moderators and admins groups, you are supposed to have:

key: `group_name`  
value: `moderators,admins`

* * *

Technical stuff to help, don’t mind me. 😄  
I tried to understand looking at the code, and I think there is an issue here:

> <https://github.com/discourse/discourse-data-explorer/blob/main/lib/discourse_data_explorer/report_generator.rb#L26>

> <https://github.com/discourse/discourse-data-explorer/blob/main/lib/discourse_data_explorer/report_generator.rb#L40-L58>

The params are transformed before `run_query` is called.  
Let’s say you have this original value:  
`[{"key":"group_names","value":"admins,moderators"}]`  
The transformed value will be:  
`{{"key"=>"group_names", "value"=>"admins,moderators"}=>nil}`

> <https://github.com/discourse/discourse-data-explorer/blob/main/lib/discourse_data_explorer/data_explorer.rb#L31>

> <https://github.com/discourse/discourse-data-explorer/blob/main/app/models/discourse_data_explorer/query.rb#L37-L43>

However, `cast_params` seems to expect `{"group_names"=>"admins,moderators"}`

I tried to test this naive change, and the params worked.

```ruby
def self.params_to_hash(query_params)
  params = JSON.parse(query_params)
  params_hash = {}

  params.each do |param|
    key = param["key"]
    value = param["value"]
    params_hash[key] = value
  end

  params_hash
end

```

---

<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: [March 6, 2025, 10:03pm UTC](https://meta.discourse.org/t/syntax-for-data-explorer-params-in-automation/355916/3 "2025-03-06T22:03:37Z")

</div>

wow thanks for the debugging here 🤗 we will have a look at this in the upcoming week.

---

<div class="post-metadata">

### Author: ![ted](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ted/32/283882_2.png) [@ted](https://meta.discourse.org/u/ted)
#### Post date: [March 13, 2025, 7:47am UTC](https://meta.discourse.org/t/syntax-for-data-explorer-params-in-automation/355916/8 "2025-03-13T07:47:30Z")

</div>

That’s some fantastic spelunking, @Arkshine! 🙂

I’m looking into this now. When I read the original code I get the impression that it expects the parameters to be an array of arrays, so I’m a bit weary of just throwing the existing stuff out. Will try to figure out when this might happen.

Will post here when I find something.

---

<div class="post-metadata">

### Author: ![ted](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ted/32/283882_2.png) [@ted](https://meta.discourse.org/u/ted)
#### Post date: [March 13, 2025, 10:01am UTC](https://meta.discourse.org/t/syntax-for-data-explorer-params-in-automation/355916/9 "2025-03-13T10:01:01Z")

</div>

There was indeed a bug here, and partly thanks to the investigation of @Arkshine, it was relatively easy to fix:

[https://github.com/discourse/discourse-data-explorer/pull/363](https://github.com/discourse/discourse-data-explorer/pull/363)

This has been merged already, so once your site has been deployed you should be unblocked @ganncamp.

If I understand correctly, you want an automation that is a one-to-one mapping between a group and its report? (I.e. `group_a` receives a report with `group_a` data, etc.)

 ![Screenshot 2025-03-13 at 5.53.57 PM](https://global.discourse-cdn.com/meta/original/4X/6/9/d/69d861d4c233d430c412233da2957a5e864a9ee2.png)

There is (currently) no connection between the recipient list and the report parameters, so to accomplish that you’d need to set up one automation per group. In this case you might want to change the parameter to `group_id`.

---

<div class="post-metadata">

### Author: ![ganncamp](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ganncamp/32/106199_2.png) [@ganncamp](https://meta.discourse.org/u/ganncamp)
#### Post date: [March 13, 2025, 11:51am UTC](https://meta.discourse.org/t/syntax-for-data-explorer-params-in-automation/355916/11 "2025-03-13T11:51:35Z")

</div>

Great news @ted!

> [@ted](#):
>
> to accomplish that you’d need to set up one automation per group

Yes, being able to `foreach` a set of groups was going to be my next request 😄

---

<div class="post-metadata">

### Author: ![ted](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ted/32/283882_2.png) [@ted](https://meta.discourse.org/u/ted)
#### Post date: [March 14, 2025, 2:19am UTC](https://meta.discourse.org/t/syntax-for-data-explorer-params-in-automation/355916/12 "2025-03-14T02:19:50Z")

</div>

> [@ganncamp](#):
>
> Yes, being able to `foreach` a set of groups was going to be my next request 😄

This does indeed seem like a convenient thing to have, especially for sites with lots and lots of groups. I’ll note down the request, but I can’t say when we’ll get to it. 🙏

---

<div class="post-metadata">

### Author: ![j.jaffeux](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/j.jaffeux/32/60297_2.png) [@j.jaffeux](https://meta.discourse.org/u/j.jaffeux)
#### Post date: [March 17, 2025, 10:09am UTC](https://meta.discourse.org/t/syntax-for-data-explorer-params-in-automation/355916/14 "2025-03-17T10:09:47Z")

</div>

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.
