Skip to content

Cannot use insomnia.environment.replaceIn() with a template that contains Faker tags #9655

@juan-vertiz

Description

@juan-vertiz

Expected Behavior

insomnia.environment.replaceIn() interpolates variables and Faker tags referenced by the template.

Actual Behavior

insomnia.environment.replaceIn() throws an exception when the template contains Faker tags:

* Error from Pre-request or after-response script:
* (unknown path) [Line 2, Column 12]
*   unknown block tag: faker
* Stack: Template render error: (unknown path) [Line 2, Column 12]
*   unknown block tag: faker
*     at Object._prettifyError (file:///C:/Users/JuanVertiz/AppData/Local/insomnia/app-12.3.1/resources/app.asar/entry.hidden-window.min.js:4285:15)
*     at Template2.render (file:///C:/Users/JuanVertiz/AppData/Local/insomnia/app-12.3.1/resources/app.asar/entry.hidden-window.min.js:14445:25)
*     at Environment3.renderString (file:///C:/Users/JuanVertiz/AppData/Local/insomnia/app-12.3.1/resources/app.asar/entry.hidden-window.min.js:14328:21)
*     at Interpolator.render (file:///C:/Users/JuanVertiz/AppData/Local/insomnia/app-12.3.1/resources/app.asar/entry.hidden-window.min.js:79141:24)
*     at Environment.replaceIn (file:///C:/Users/JuanVertiz/AppData/Local/insomnia/app-12.3.1/resources/app.asar/entry.hidden-window.min.js:82427:30)
*     at fn1 (eval at runScript (file:///C:/Users/JuanVertiz/AppData/Local/insomnia/app-12.3.1/resources/app.asar/entry.hidden-window.min.js:83421:25), <anonymous>:58:40)
*     at eval (eval at runScript (file:///C:/Users/JuanVertiz/AppData/Local/insomnia/app-12.3.1/resources/app.asar/entry.hidden-window.min.js:83421:25), <anonymous>:71:13)
*     at async runScript (file:///C:/Users/JuanVertiz/AppData/Local/insomnia/app-12.3.1/resources/app.asar/entry.hidden-window.min.js:83441:33)
*     at async file:///C:/Users/JuanVertiz/AppData/Local/insomnia/app-12.3.1/resources/app.asar/entry.hidden-window.min.js:83396:23

Reproduction Steps

  1. Create a POST request and use Faker to generate some random values for the body:

    {
      "id": "{% faker 'randomDomainWord' %}"
    }
  2. Create a pre-request script to parse the request body with rendered values:

    try {
      const raw = insomnia.request.body?.raw ?? "";
      console.log("Raw:", raw);
      const rendered = insomnia.environment.replaceIn(raw);
      console.log("Rendered:", rendered)
      const body = JSON.parse(rendered);
      console.log("Parsed:", body);
    } catch (err) {
      console.error("Could not parse request body:", err.name);
    }
  3. Send the request and verify the console output:

    * log: Raw: {
    * 	"id": "{% faker 'randomDomainWord' %}",
    * 	"name": "{% faker 'randomLoremSlug' %}",
    * 	"specifications": {},
    * 	"type": "ML"
    * }
    * error: Could not parse request body: Template render error

Is there an existing issue for this?

Which sync method do you use?

  • Git sync.
  • Insomnia Cloud sync.
  • Local only

Additional Information

I want to create the request body dynamically using Faker and store the rendered values as environment variables so I can use them across requests.

Insomnia Version

12.3.1

What operating system are you using?

Windows

Operating System Version

Windows 11 version 25H2 build 26200.7623

Installation method

Downlaoded from insomnia.rest

Last Known Working Insomnia version

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    B-bugBug: general classificationS-unverifiedStatus: Unverified by maintainer

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions