Passing params to Data Explorer using API requires enclosing a value

Reference: Run Data Explorer queries with the Discourse API

When passing params to a SQL query using the API, Discourse currently requires that all values be encapsulated using double quotes, including integers, which are not encapsulated by default on some systems (namely PHP’s json_encode). Looking at the JSON RFC, there is no requirement to use double quotes for integers. This requirement also goes against the philosophy of “be tolerant in what you accept…”

How to reproduce?

-F 'params={"user_id":2}'

Server returns 500 Internal Server Error.

In error logs this shows up:

NoMethodError (undefined method `downcase' for 2:Integer)
app/controllers/application_controller.rb:424:in `block in with_resolved_locale'
app/controllers/application_controller.rb:424:in `with_resolved_locale'
lib/middleware/omniauth_bypass_middleware.rb:64:in `call'
lib/content_security_policy/middleware.rb:12:in `call'
lib/middleware/csp_script_nonce_injector.rb:12:in `call'
config/initializers/008-rack-cors.rb:14:in `call'
lib/freedom_patches/rails_rack_logger_from_rails_7_2.rb:35:in `call_app'
lib/freedom_patches/rails_rack_logger_from_rails_7_2.rb:22:in `call'
config/initializers/100-quiet_logger.rb:20:in `call'
config/initializers/100-silence_logger.rb:29:in `call'
lib/middleware/missing_avatars.rb:22:in `call'
lib/middleware/turbo_dev.rb:31:in `call'
lib/middleware/processing_request.rb:12:in `call'

Backtrace

plugins/discourse-data-explorer/lib/discourse_data_explorer/parameter.rb:121:in `cast_to_ruby'
...

This format works correctly:

-F 'params={"user_id":"2"}'

I’m sharing this not because I’m nitpicky, but to save time for anyone who may encounter a similar issue as I did. It took me a while to figure out what was causing the problem.