API POST /api/card/:card-id/query/:export-format with parameters

Hi,
I’m trying to call /api/card/:card-id/query/xslx of a card with a required parameter of type text.

The submitted call is something like

curl -X POST \
  -H "Content-Type: application/json" \
  -H "X-Metabase-Session: xxxx-xxx-xxx" \
  -d '{"parameters": [{"cf": "foo"}]}' \
  "https://mymetabase/api/card/168/query/xlsx"

The answare is:
You'll need to pick a value for 'codice fiscale' before this query can run.

The log is:

metabase_1  | 11-22 11:03:59 WARN middleware.process-userland-query :: Query failure {:status :failed,
metabase_1  |  :class clojure.lang.ExceptionInfo,
metabase_1  |  :error "You'll need to pick a value for 'codice fiscale' before this query can run.",
metabase_1  |  :stacktrace
metabase_1  |  ("--> query_processor.middleware.parameters.native.values$missing_required_param_exception.invokeStatic(values.clj:72)"
metabase_1  |   "query_processor.middleware.parameters.native.values$missing_required_param_exception.invoke(values.clj:71)"
metabase_1  |   "query_processor.middleware.parameters.native.values$fn__40626$default_value_for_tag__40631$fn__40635.invoke(values.clj:130)"
metabase_1  |   "query_processor.middleware.parameters.native.values$fn__40626$default_value_for_tag__40631.invoke(values.clj:124)"
metabase_1  |   "query_processor.middleware.parameters.native.values$fn__40780$value_for_tag__40785$fn__40786.invoke(values.clj:215)"
metabase_1  |   "query_processor.middleware.parameters.native.values$fn__40780$value_for_tag__40785.invoke(values.clj:209)"
metabase_1  |   "query_processor.middleware.parameters.native.values$fn__40806$query__GT_params_map__40811$fn__40815$iter__40817__40821$fn__40822.invoke(values.clj:226)"
metabase_1  |   "query_processor.middleware.parameters.native.values$fn__40806$query__GT_params_map__40811$fn__40815.invoke(values.clj:225)"
metabase_1  |   "query_processor.middleware.parameters.native.values$fn__40806$query__GT_params_map__40811.invoke(values.clj:218)"
metabase_1  |   "query_processor.middleware.parameters.native$expand_inner.invokeStatic(native.clj:51)"
metabase_1  |   "query_processor.middleware.parameters.native$expand_inner.invoke(native.clj:34)"
metabase_1  |   "query_processor.middleware.parameters$expand_native_params.invokeStatic(parameters.clj:42)"
metabase_1  |   "query_processor.middleware.parameters$expand_native_params.invoke(parameters.clj:41)"
metabase_1  |   "query_processor.middleware.parameters$expand_one.invokeStatic(parameters.clj:51)"
metabase_1  |   "query_processor.middleware.parameters$expand_one.invoke(parameters.clj:44)"
metabase_1  |   "query_processor.middleware.parameters$expand_all$replace_40898__40899.invoke(parameters.clj:62)"
metabase_1  |   "mbql.util.match$replace_in_collection$iter__20300__20304$fn__20305.invoke(match.clj:132)"
metabase_1  |   "mbql.util.match$replace_in_collection.invokeStatic(match.clj:131)"
metabase_1  |   "mbql.util.match$replace_in_collection.invoke(match.clj:126)"
metabase_1  |   "query_processor.middleware.parameters$expand_all$replace_40898__40899.invoke(parameters.clj:62)"
metabase_1  |   "query_processor.middleware.parameters$expand_all.invokeStatic(parameters.clj:62)"
metabase_1  |   "query_processor.middleware.parameters$expand_all.invoke(parameters.clj:56)"
metabase_1  |   "query_processor.middleware.parameters$expand_all.invokeStatic(parameters.clj:59)"
metabase_1  |   "query_processor.middleware.parameters$expand_all.invoke(parameters.clj:56)"
metabase_1  |   "query_processor.middleware.parameters$expand_parameters.invokeStatic(parameters.clj:80)"
metabase_1  |   "query_processor.middleware.parameters$expand_parameters.invoke(parameters.clj:76)"
metabase_1  |   "query_processor.middleware.parameters$substitute_parameters_STAR_.invokeStatic(parameters.clj:85)"
metabase_1  |   "query_processor.middleware.parameters$substitute_parameters_STAR_.invoke(parameters.clj:82)"
metabase_1  |   "query_processor.middleware.driver_specific$process_query_in_context$fn__37521.invoke(driver_specific.clj:12)"
metabase_1  |   "query_processor.middleware.resolve_driver$resolve_driver$fn__41221.invoke(resolve_driver.clj:22)"
metabase_1  |   "query_processor.middleware.bind_effective_timezone$bind_effective_timezone$fn__36835$fn__36836.invoke(bind_effective_timezone.clj:9)"
metabase_1  |   "util.date$call_with_effective_timezone.invokeStatic(date.clj:88)"
metabase_1  |   "util.date$call_with_effective_timezone.invoke(date.clj:77)"
metabase_1  |   "query_processor.middleware.bind_effective_timezone$bind_effective_timezone$fn__36835.invoke(bind_effective_timezone.clj:8)"
metabase_1  |   "query_processor.middleware.store$initialize_store$fn__44341$fn__44342.invoke(store.clj:11)"
metabase_1  |   "query_processor.store$do_with_store.invokeStatic(store.clj:46)"
metabase_1  |   "query_processor.store$do_with_store.invoke(store.clj:40)"
metabase_1  |   "query_processor.middleware.store$initialize_store$fn__44341.invoke(store.clj:10)"
metabase_1  |   "query_processor.middleware.async$async__GT_sync$fn__20798.invoke(async.clj:23)"
metabase_1  |   "query_processor.middleware.async_wait$runnable$fn__36561.invoke(async_wait.clj:89)"),
metabase_1  |  :query
metabase_1  |  {:constraints nil,
metabase_1  |   :type :native,
metabase_1  |   :middleware {:skip-results-metadata? true, :userland-query? true},
metabase_1  |   :native
metabase_1  |   {:query
metabase_1  |    "the query text...",
metabase_1  |    :template-tags {"cf" {:id "3234dc0b-ed2f-dc8b-4409-30cb1e087470", :name "cf", :display-name "codice fiscale", :type :text, :required true}}},
metabase_1  |   :info
metabase_1  |   {:executed-by 1,
metabase_1  |    :context :xlsx-download,
metabase_1  |    :card-id 168,
metabase_1  |    :dashboard-id nil,
metabase_1  |    :query-hash [-39, 4, 33, 71, -33, -62, -126, -110, -42, -48, -108, 85, -88, -45, 36, -30, 16, -122, -96, -79, 61, -104, 46, -103, 46, 114, 9, -68, 6, -69, 84, 11]},
metabase_1  |   :parameters nil,
metabase_1  |   :async? true,
metabase_1  |   :cache-ttl 8},
metabase_1  |  :error_type :missing-required-parameter,
metabase_1  |  :ex-data {:type :missing-required-parameter}}
metabase_1  |
metabase_1  | 11-22 11:03:59 DEBUG middleware.log :: POST /api/card/168/query/xlsx 400 536.8 ms (10 DB calls)
metabase_1  | "You'll need to pick a value for 'codice fiscale' before this query can run."

Where am I doing wrong?
thanks for any suggestions

Hi @ilkosta
Which version of Metabase?
When playing around with the API, I would highly recommend that you start by using the regular Metabase interface, while having your browser developer Network-tab open. It’s definitely the easiest way to learn the API.
The parameters is a little special and needs to be serialized - see the API docs:

-d 'parameters=%5B%7B%22type%22%3A%22category%22%2C%22target%22%3A%5B%22variable%22%2C%5B%22template-tag%22%2C%22cf%22%5D%5D%2C%22value%22%3A%22foo%22%7D%5D'

thanks @flamber. I’m using the v0.33.4 , but passing the urlencoded parameters, the message remain the same.

curl -X POST \
  -H "Content-Type: application/json" \
  -H "X-Metabase-Session: xxxx-xxx-xxx" \
  -d '{"parameters": **urlencoded_string**}' \
  "https://mymetabase/api/card/168/query/xlsx"

where the urlencoded_string parameters are copied from the browser console.
or

curl -X POST \
  -H "Content-Type: application/json" \
  -H "X-Metabase-Session: xxxx-xxx-xxx" \
  -d '"parameters": **urlencoded_string**' \
  "https://mymetabase/api/card/168/query/xlsx"

the answare is always: You'll need to pick a value for 'codice fiscale' before this query can run.

Other hints?

@ilkosta
What I posted actually comes directly from Metabase. I just “Copy as cURL”, which Firefox has as an option.
Notice that it’s not a JSON object. It’s a parameter called parameters with a value of a serialized JSON object.

I had never used that feature. a turning point. thank you very much!