0

I feel kinda dumb asking this question bcs I might be missing something super easy but.. I have a collection of requests in Postman.

I have a collection variable test_model_id which is 888.

What I'm trying to achieve is simply putting the model_id variable into the string in resp_data line. I feel like I tried everything lol.

var model_id = parseInt(pm.collectionVariables.get("test_model_id"));

pm.test("Test_response_model_creation", function () {
    var jsonData = pm.response.text();
    var resp_data = JSON.stringify({"detail":"Model {{model_id}} created","HTTPStatusCode":200});
    pm.expect(jsonData).to.eql(resp_data);
});

Getting

... to deeply equal '{"detail":"Model {{model_id}} created","HTTPStatusCode":200}'
Leemosh
  • 883
  • 6
  • 19
  • `detail: "Model " + model_id + " created"` or `detail: \`Model ${model_id} created\`` –  Jun 07 '21 at 14:39
  • string manipulation should do it: `"detail": "Model ${model_id} created"` – somallg Jun 07 '21 at 14:39
  • This `"Model ${model_id} created"` is what I was trying and it didn't work. At `"Model " + model_id + " created"` I was a little scared it's gonna break the JSON format but it works. Thanks. – Leemosh Jun 07 '21 at 14:43
  • Nevermind, I'm dumb. Thanks! – Leemosh Jun 07 '21 at 14:45
  • Duplicate: [How can I do string interpolation in JavaScript?](https://stackoverflow.com/questions/1408289/how-can-i-do-string-interpolation-in-javascript) –  Jun 07 '21 at 15:16

1 Answers1

1

Have you tried using template laterals?

var resp_data = JSON.stringify({"detail":`Model ${model_id}` created","HTTPStatusCode":200});