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:
-- [params]
-- int :user_param
SELECT Count(likes_received) total_likes_received
from user_stats us
where us.user_id = :user_param
The code:
<?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.
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));