Postman to k6 convertion

Hi All,

I am new to K6 and its really useful tool. I am facing a issue while running the scripts. Hope I get some help here.

  1. I have written postman script and its working fine, its setting the environment variables.(verified by printing in console).
  2. After converting from postman to k6 and running I am getting an error.
// Auto-generated by the postman-to-k6 converter

import "./libs/shim/core.js";
import "./libs/shim/urijs.js";

export let options = { maxRedirects: 4 };

const Request = Symbol.for("request");
  environment: {
    tenantId: "",
    tenantName: "demo2"

export default function() {
    name: "Onboard tenant",
    id: "69e8633c-caa9-4d6b-bae3-2de1643564cd",
    method: "POST",
    address: "{{baseUrl}}/tenants",
      '{\r\n    "name": "{{tenantName}}",\r\n    "handler": "test",\r\n    "description": "tenant"\r\n}',
    post(response) {

      //validate status
      pm.test("[POST]==/Onboard tenant -- Status code is 201", () => {;

      // Set Environment variable
      let responseBodyData = pm.response.json();
      pm.environment.set("tenantId", responseBodyData.result._id);
**Error: running k6**
ERRO[0007] TypeError: Cannot read property '_id' of undefined
running at post (file:///C:/workspace/k6-notification-flow2-script.js:41:34(21))
default at executePostrequest (file:///C:/workspace/libs/shim/core.js:1253:11(22))
        at executeRequest (file:///C:/workspace/libs/shim/core.js:1034:25(108))
        at file:///C:/workspace/libs/shim/core.js:314:30(27)
        at file:///C:/workspace/k6-notification-flow2-script.js:20:19(17)  executor=per-vu-iterations scenario=default source=stacktrace

     ✗ [POST]==/Onboard tenant -- Status code is 201
      ↳  0% — ✓ 0 / ✗ 1

Hi @subramanyam, Welcome to the community forum! :tada:

The only thing the error is telling us is that responseBodyData.result is undefined.

If this happens only when doing it with many requests this likely is due to the system under test (SUT) returning a bad response under load.

Either way I would recommend dumping the whole response and looking at it for better diagnosis.

You can add the following lines above pm.environment.set

if (responseBodyData.result == undefined) {
  console.log(JSON.stringify(pm.response, null, "  "));

Which will “pretty print” the whole response in case the result property of the body data is undefined.

Hope this helps you!

p.s. I am not certain the current mantainer of postman-to-k6 is looking at this forum at all. So you might want to write in their issues/discussions on the repo

Hi @mstoykov ,

Thanks for replying on the issue. I dont see any issue with
“responseBodyData.result” data printing in console. I used the suggested code and see different issue. Let raise the issue postman-to-k6 Git repo.

Thanks once again.

1 Like