# Validation error even when parameter passed while running data explorer API with Curl

**URL:** https://meta.discourse.org/t/validation-error-even-when-parameter-passed-while-running-data-explorer-api-with-curl/191341
**Category:** Support
**Created:** [May 23, 2021, 6:34am UTC](https://meta.discourse.org/t/validation-error-even-when-parameter-passed-while-running-data-explorer-api-with-curl/191341 "2021-05-23T06:34:47Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Himanshu\_Singh](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/himanshu_singh/32/216438_2.png) [@Himanshu\_Singh](https://meta.discourse.org/u/Himanshu_Singh)
#### Post date: [May 23, 2021, 6:34am UTC](https://meta.discourse.org/t/validation-error-even-when-parameter-passed-while-running-data-explorer-api-with-curl/191341/1 "2021-05-23T06:34:47Z")

</div>

I have looked at forum answers but I still can’t make it to work. The function does not want to take a `user_param` parameter I have defined in the query.

**Error:** Array ( [success] =\> [errors] =\> Array ( [0] =\> DataExplorer::ValidationError: Missing parameter user\_param of type int ) )

**The query:**

```plaintext
-- [params]
-- int :user_param

SELECT Count(likes_received) total_likes_received 
from user_stats us
where us.user_id = :user_param

```

**The code:**

```plaintext
<?php global $post;

$current_user_id = get_current_user_id();

$user_discourse_id = (int)get_user_meta($current_user_id,'discourse_sso_user_id')[0];
//api credentials,
$api_key = 'key';
$api_username = 'name';
$post_fields = array(
    'user_param' => $user_discourse_id,
);

$headers = array("Content-Type: multipart/form-data;","Api-Key: $api_key","Api-Username: $api_username",);
$url = 'https://domain/admin/plugins/explorer/queries/9/run';
$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, $url );
curl_setopt( $ch, CURLOPT_POST, true );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers );
curl_setopt( $ch, CURLOPT_POSTFIELDS, $post_fields );

$result = curl_exec( $ch );
if ( curl_errno( $ch ) !== 0 ) {
    // Handle error, call curl_close( $ch ) and return.
	echo 'error';
	curl_close ($ch);
	return;
}

curl_close( $ch );
$decoded_result = json_decode( $result, true );
print_r($decoded_result);

?>

```

I have generated value for $post\_fields with and without http\_build\_query but still parameter is not passed to [data explorer](https://meta.discourse.org/t/32566?silent=true).

This was working a month ago with http\_build\_query and now it is not. What am I missing here?

Update:  
I even tried to pass the array manually and still the same error. Has something recently changed in the plugin?

`curl_setopt( $ch, CURLOPT_POSTFIELDS, array('user_param'=>'25'));`  
`curl_setopt( $ch, CURLOPT_POSTFIELDS, array('user_param'=> 25));`

---

<div class="post-metadata">

### Author: ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### Post date: [May 24, 2021, 8:07pm UTC](https://meta.discourse.org/t/validation-error-even-when-parameter-passed-while-running-data-explorer-api-with-curl/191341/2 "2021-05-24T20:07:37Z")

</div>

Have a look at [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) for details about how the `params` parameter needs to be set. Based off the code you have provided, it looks like you are trying to pass the `user_param` param directly instead of including it in a `params` param. The first code example in the topic that I linked to should give you an idea about how to set that parameter.

---

<div class="post-metadata">

### Author: ![Himanshu\_Singh](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/himanshu_singh/32/216438_2.png) [@Himanshu\_Singh](https://meta.discourse.org/u/Himanshu_Singh)
#### Post date: [May 24, 2021, 8:50pm UTC](https://meta.discourse.org/t/validation-error-even-when-parameter-passed-while-running-data-explorer-api-with-curl/191341/3 "2021-05-24T20:50:03Z")

</div>

Simon,

I looked at your article on APIs but I am using `curl_setopt()` function to insert the parameters. The function requires me to use an array. so I have tried the following and it is displaying a forum level error.

```plaintext
$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, $url );
curl_setopt( $ch, CURLOPT_POST, true );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers );
curl_setopt( $ch, CURLOPT_POSTFIELDS, array('params' => (array('user_param' => 25))));

$result = curl_exec( $ch );
print_r($result);

```

Seems like the data is passing now but the output is not being rendered.

> **[Gyazo](https://gyazo.com/9e39ddb22ca848cc2e85adc2b51f0774)**
>
> Gyazo is the easiest way to record screenshots & videos you can share instantly. Save time with async visual communication that's effortless and engaging.

# Oops

The software powering this discussion forum encountered an unexpected problem. We apologize for the inconvenience.

Detailed information about the error was logged, and an automatic notification generated. We’ll take a look at it.

No further action is necessary. However, if the error condition persists, you can provide additional detail, including steps to reproduce the error, by posting a discussion topic in the site’s feedback category.

What am I missing?

---

<div class="post-metadata">

### Author: ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### Post date: [May 24, 2021, 9:11pm UTC](https://meta.discourse.org/t/validation-error-even-when-parameter-passed-while-running-data-explorer-api-with-curl/191341/4 "2021-05-24T21:11:28Z")

</div>

> [@Himanshu\_Singh](#):
>
> I am using `curl_setopt()` function to insert the parameters.

You might be able to simplify debugging the issue by first attempting to make the API call with a curl request from your computer’s terminal. If that can be made to work, you’ll know that the issue is related to how you are creating the request with `curl_setopt`.

> [@Himanshu\_Singh](#):
>
> Seems like the data is passing now but the output is not being rendered.

I wouldn’t expect making a [Data Explorer](https://meta.discourse.org/t/32566?silent=true) query via the API to cause a `500` error on your site’s server. If you are able to access the site, you should find details about what has gone wrong in your site’s error logs (found at Admin / Logs / Error Logs.)

---

<div class="post-metadata">

### Author: ![Himanshu\_Singh](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/himanshu_singh/32/216438_2.png) [@Himanshu\_Singh](https://meta.discourse.org/u/Himanshu_Singh)
#### Post date: [May 24, 2021, 10:23pm UTC](https://meta.discourse.org/t/validation-error-even-when-parameter-passed-while-running-data-explorer-api-with-curl/191341/5 "2021-05-24T22:23:15Z")

</div>

> [@simon](#):
>
> you should find details about what has gone wrong in your site’s error logs (found at Admin / Logs / Error Logs.

I was able to find the information but cannot make sense of it.

```plaintext
MultiJson::ParseError (unexpected character (after ) at line 1, column 1 [parse.c:769])
app/controllers/application_controller.rb:395:in `block in with_resolved_locale'
app/controllers/application_controller.rb:395:in `with_resolved_locale'
lib/middleware/omniauth_bypass_middleware.rb:71:in `call'
lib/content_security_policy/middleware.rb:12:in `call'
lib/middleware/anonymous_cache.rb:355:in `call'
config/initializers/008-rack-cors.rb:25:in `call'
config/initializers/100-quiet_logger.rb:23:in `call'
config/initializers/100-silence_logger.rb:31:in `call'
lib/middleware/enforce_hostname.rb:23:in `call'
lib/middleware/request_tracker.rb:177:in `call'

```

Regarding your first suggestion, I am working on figuring out how to run Curl on command prompt.

---

<div class="post-metadata">

### Author: ![Himanshu\_Singh](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/himanshu_singh/32/216438_2.png) [@Himanshu\_Singh](https://meta.discourse.org/u/Himanshu_Singh)
#### Post date: [May 25, 2021, 5:48pm UTC](https://meta.discourse.org/t/validation-error-even-when-parameter-passed-while-running-data-explorer-api-with-curl/191341/6 "2021-05-25T17:48:17Z")

</div>

So I tried the code on terminal and I am getting the following error:

curl: (3) URL using bad/illegal format or missing URL  
curl: (3) URL using bad/illegal format or missing URL  
curl: (3) URL using bad/illegal format or missing URL  
curl: (3) URL using bad/illegal format or missing URL

root@Discourse-for-Prowess:~# curl -X POST “[https://domain/admin/plugins/explorer/queries/9/run](https://domain/admin/plugins/explorer/queries/9/run)”-H “Content-Type:multipart/form-data;”-H “Api-key:12345”-H “Api-username:username”-F ‘params={“user\_param”:“25”}’

I am able to run the query in [data explorer](https://meta.discourse.org/t/32566?silent=true) - [screenshot](https://gyazo.com/55175c0ae7a8f4e3e5d39fbd92bd75cd).

In the error logs I see the following:

```plaintext
ActionDispatch::Http::MimeNegotiation::InvalidType ("%{#context['com.opensymphony.xwork2.dispatcher.httpservletresponse'].addheader('90b3sfq9'" is not a valid MIME type)
lib/middleware/omniauth_bypass_middleware.rb:71:in `call'
lib/content_security_policy/middleware.rb:12:in `call'
lib/middleware/anonymous_cache.rb:353:in `call'
config/initializers/008-rack-cors.rb:25:in `call'
config/initializers/100-quiet_logger.rb:23:in `call'
config/initializers/100-silence_logger.rb:31:in `call'
lib/middleware/enforce_hostname.rb:23:in `call'
lib/middleware/request_tracker.rb:177:in `call'

```

Any suggestion would be helpful.
