# \`DataExplorer::ValidationError: Missing parameter\` when running Data Explorer queries with \[params\] via API

**URL:** https://meta.discourse.org/t/dataexplorer-missing-parameter-when-running-data-explorer-queries-with-params-via-api/223812
**Category:** Data & reporting
**Tags:** rest-api, sql-query
**Created:** [April 9, 2022, 7:40pm UTC](https://meta.discourse.org/t/dataexplorer-missing-parameter-when-running-data-explorer-queries-with-params-via-api/223812 "2022-04-09T19:40:15Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![md-misko](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/md-misko/32/126315_2.png) [@md-misko](https://meta.discourse.org/u/md-misko)
#### Post date: [April 9, 2022, 7:40pm UTC](https://meta.discourse.org/t/dataexplorer-missing-parameter-when-running-data-explorer-queries-with-params-via-api/223812/1 "2022-04-09T19:40:15Z")

</div>

There is a bug in Discourse API when running [Data Explorer](https://meta.discourse.org/t/32566?silent=true) queries containing parameters (both queries below work as expected when run from the browser).

Following the instructions from [Run Data Explorer queries with the Discourse API](https://meta.discourse.org/t/how-to-run-data-explorer-queries-with-the-discourse-api/120063/) and using

```plaintext
-F 'params={"group_id":"64"}'

```

to run this query (which has a parameter without its default value set)

```plaintext
-- [params]
-- int :group_id
select id, name from groups
where id = :group_id

```

results in an error: `{"success":false,"errors":["DataExplorer::ValidationError: Missing parameter group_id of type int"]}`

When a query has a parameter with its default value set, the API call is successful, but the result is _the same_ regardless of the value provided via `-F 'params=`

```plaintext
-- [params]
-- int :group_id = 2
select id, name from groups
where id = :group_id

```

```plaintext
-F 'params={"group_id":"64"}'

```

and it always returns the result for the _default value_ of the parameter: `{"success":true,"errors":[],"duration":0.2,"result_count":1,"params":{},"columns":["id","name"],"default_limit":1000,"relations":{},"colrender":{},"rows":[[2,"moderators"]]}`

---

<div class="post-metadata">

### Author: ![michaeld](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/michaeld/32/1594_2.png) [@michaeld](https://meta.discourse.org/u/michaeld)
#### Post date: [April 9, 2022, 9:04pm UTC](https://meta.discourse.org/t/dataexplorer-missing-parameter-when-running-data-explorer-queries-with-params-via-api/223812/2 "2022-04-09T21:04:08Z")

</div>

What is the complete command you’re using?  
Are you supplying `-X POST` and all the required headers?

---

<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: [April 9, 2022, 9:54pm UTC](https://meta.discourse.org/t/dataexplorer-missing-parameter-when-running-data-explorer-queries-with-params-via-api/223812/3 "2022-04-09T21:54:46Z")

</div>

> [@md-misko](#):
>
> both queries below work as expected when run from the browser

The browser uses the API. It’s improbable that you are describing a big if discourse.

---

<div class="post-metadata">

### Author: ![md-misko](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/md-misko/32/126315_2.png) [@md-misko](https://meta.discourse.org/u/md-misko)
#### Post date: [April 10, 2022, 5:17am UTC](https://meta.discourse.org/t/dataexplorer-missing-parameter-when-running-data-explorer-queries-with-params-via-api/223812/4 "2022-04-10T05:17:06Z")

</div>

> [@michaeld](#):
>
> What is the complete command you’re using?  
> Are you supplying `-X POST` and all the required headers?

The one from [How to run Data Explorer queries with the Discourse API](https://meta.discourse.org/t/how-to-run-data-explorer-queries-with-the-discourse-api/120063/1) complete with `-X POST` and all the required headers.

This is not a syntax issue, if you check the last line from the OP you’ll see that curl returns a success, it’s just that the result is incorrect.

> [@pfaffman](#):
>
> It’s improbable that you are describing a big if discourse.

Jay, I don’t understand the meaning of this sentence. Did you by any chance try and repro the issue using the minimal examples provided in the OP?

* * *

@michaeld, @pfaffman  
I’m hesitating to write this part, mainly because I admire and respect your dedication and expertise in providing free support to the community, I know I benefited from your insights on numerous occasions before. But this time I have a feeling that neither of you read past the first few lines of the report (I’m very careful to research and test thoroughly before I post in the support category, and I always try to include _detailed repro steps_).

The thing is, in my experience, when support request receives a response like this—assuming a user error without trying to actually repro the issue using the provided steps (especially from such experienced members as yourselves)—the real issue is less likely to be picked up by the Discourse team.

On the other hand, if your response would either validate or invalidate the _actual repro steps_, this would lend weight to the claim (or point to some other cause) which will more likely attract attention from the team and lead to the eventual fix.

I know that probably 99% of cases are just users failing to read the instructions (I should know, I’ve been there before). But knowing this, we probably shouldn’t make the same mistake trying to answer support issues quickly, rather than thoroughly?

---

<div class="post-metadata">

### Author: ![michaeld](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/michaeld/32/1594_2.png) [@michaeld](https://meta.discourse.org/u/michaeld)
#### Post date: [April 10, 2022, 6:56am UTC](https://meta.discourse.org/t/dataexplorer-missing-parameter-when-running-data-explorer-queries-with-params-via-api/223812/5 "2022-04-10T06:56:17Z")

</div>

> [@md-misko](#):
>
> trying to answer support issues quickly, rather than thoroughly?

I am a surprised and TBH a bit disappointed to read this. I did read your issue very thoroughly and I had the following observations:

1. You did in fact not provide complete and detailed repro steps since you did not include the entire command line.

2. The fact that you only get output when you set a default value for the parameter leads me to believe that Discourse is not _seeing_ your parameter name/value pair.

The conclusion that your command line must be correct because you get output is wrong - and overlooks the fact that you are not getting the output that is associated with the parameter you provided but with its default value.

1. I _did_ try to - and cannot - reproduce this issue.

```plaintext
curl -X POST "https://REDACTED/admin/plugins/explorer/queries/2/run" -H "Content-Type: multipart/form-data;" -H "Api-Key: REDACTED" -H "Api-Username: system" -F 'params={"group_id":"1"}'

{"success":true,"errors":[],"duration":0.3,"result_count":1,"params":{"group_id":"1"},"columns":["id","name"],"default_limit":1000,"relations":{},"colrender":{},"rows":[[1,"admins"]]}

```

These three observations led me to ask you for a detail in your command line, since I was considering which circumstances would lead to Discourse not seeing the parameter, and I am convinced that this _is_ a syntax issue.

Making a typo or a mistake is not reserved for inexperienced users. I make trivial mistakes every day.

---

<div class="post-metadata">

### Author: ![md-misko](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/md-misko/32/126315_2.png) [@md-misko](https://meta.discourse.org/u/md-misko)
#### Post date: [April 10, 2022, 8:12am UTC](https://meta.discourse.org/t/dataexplorer-missing-parameter-when-running-data-explorer-queries-with-params-via-api/223812/6 "2022-04-10T08:12:02Z")

</div>

Michael (and Jay), please accept my apology, I assumed that you didn’t actually _do_ the repro steps, which I shouldn’t have done! I’ll be more careful not to asume such things in the future.

Hoping you’re still willing to bear with me: I used the exact same curl as you did (I actually copied yours this time, just to be 100% sure), with this result:

`{"success":true,"errors":[],"duration":0.2,"result_count":1,"params":{},"columns":["id","name"],"default_limit":1000,"relations":{},"colrender":{},"rows":[[2,"moderators"]]}`

and comparing it with yours

`{"success":true,"errors":[],"duration":0.3,"result_count":1,"params":{"group_id":"1"},"columns":["id","name"],"default_limit":1000,"relations":{},"colrender":{},"rows":[[1,"admins"]]}`

the issue immediately emerges: `params":{}` vs `"params":{"group_id":"1"}` in the output, which makes your analysis correct: my server is not seeing/ processing `-F 'params={"group_id":"1"}'` correctly.

> [@michaeld](#):
>
> These three observations led me to ask you for a detail in your command line, since I was considering which circumstances would lead to Discourse not seeing the parameter, and I am convinced that this _is_ a syntax issue.

Now that I see the detailed steps of your reasoning it makes perfect sense why you assumed the syntax error (I wish I could read your mind before I posted 😊). But since I used the exact syntax you did, it cannot be syntax error _now_, right?

The server is on latest build. What do you think could be the issue?

[Edit]: tried this on another standard standalone install server 2.9.0.beta3 (8040b95e8c) with the same issue. First server is on 2.9.0.beta3 (0f7b9878ff)

Unless this is some weird curl issue I’m at a loss.

```plaintext
curl 7.79.1 (Windows) libcurl/7.79.1 Schannel
Release-Date: 2021-09-22
Protocols: dict file ftp ftps http https imap imaps pop3 pop3s smtp smtps telnet tftp 
Features: AsynchDNS HSTS IPv6 Kerberos Largefile NTLM SPNEGO SSL SSPI UnixSockets

```

---

<div class="post-metadata">

### Author: ![michaeld](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/michaeld/32/1594_2.png) [@michaeld](https://meta.discourse.org/u/michaeld)
#### Post date: [April 10, 2022, 8:58am UTC](https://meta.discourse.org/t/dataexplorer-missing-parameter-when-running-data-explorer-queries-with-params-via-api/223812/7 "2022-04-10T08:58:23Z")

</div>

Windows does not understand those single quotes. So you’ll have to use regular double quotes and escape them with backslashes.

Use this:

```plaintext
-F params={\”group_id\”:\”1\”}

```

(Don’t copy paste this since iOS messed up the quotes)

---

<div class="post-metadata">

### Author: ![md-misko](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/md-misko/32/126315_2.png) [@md-misko](https://meta.discourse.org/u/md-misko)
#### Post date: [April 10, 2022, 9:16am UTC](https://meta.discourse.org/t/dataexplorer-missing-parameter-when-running-data-explorer-queries-with-params-via-api/223812/8 "2022-04-10T09:16:58Z")

</div>

> [@michaeld](#):
>
> Windows does not understand those single quotes.

Well don’t I feel lika a fool now 🤣

Thanks Michael, you truly own your title! I shall doubt you no more.

---

<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: [April 10, 2022, 12:54pm UTC](https://meta.discourse.org/t/dataexplorer-missing-parameter-when-running-data-explorer-queries-with-params-via-api/223812/9 "2022-04-10T12:54:37Z")

</div>

> [@md-misko](#):
>
> Did you by any chance try and repro the issue using the minimal examples provided in the OP?

I did not. If you’re saying that the OP is wrong then my comment is unhelpful. Sorry about that.

Oh, and not I see Michael’s response. Indeed getting quotes and escapes right is a zillion times more difficult than one would think.

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [May 10, 2022, 12:54pm UTC](https://meta.discourse.org/t/dataexplorer-missing-parameter-when-running-data-explorer-queries-with-params-via-api/223812/10 "2022-05-10T12:54:59Z")

</div>

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