K6 Metabase post request is getting {"errors":{"database":"value must be an integer."}} although the value is integer

I am having trouble sending a request to Metabase and getting this error in as a response {“errors”:{“database”:“value must be an integer.”}} although the database in the body is an integer.

I tried passing the payload in its regular format and in the JSON.stringify format but I am getting the same response.

This is because I am using the http from K6 library import http from "k6/http"

Has anybody faced this issue before and how did you solve it?

   let params = {
    headers: {
      "X-Metabase-Session": metabaseId,
    },
  };

   var payload = {
    type: "native",
    native: {
      query: `select * from jobs where project_id = ${projectId} and job_type = 3 order by id desc limit 10`,
      "template-tags": {},
    },
    database: 16,
    parameters: [],
  };
  let url = `${myOptions.metabaseURL}/dataset`;

  // let res = http.post(url, JSON.stringify(payload), params);
  let res = http.post(url, payload, params);
  console.log(payload)
  console.log("JSON.stringify(payload)",JSON.stringify(payload))

  console.log(JSON.parse(res.body))
  console.log((res.body))

Hi @AhmadGafar,
what is the expected encoding format from Metabase? If it accepts only JSON then the right version you should use is with JSON.stringify. You should also explicit the Content-Type header in parameters.

let params = {
  headers: {
    'X-Metabase-Session': metabaseId,
    'Content-Type': 'application/json'
  }
};
let res = http.post(url, JSON.stringify(payload), params);

Have you tried to execute the same request from an HTTP client like curl? Are you getting a different response?

Note: checking the latest documentation of the Dataset endpoint I see the expected path defined as /api/dataset. Are you including /api in metabaseURL or are you using a different version?