Jesse
Jesse

Reputation: 1

Manipulating variables in insomnia

I was using Postman and I have this on it:

var jsonData = JSON.parse(responseBody);
postman.setEnvironmentVariable("nivel", jsonData.authenticationModel.nivel_ensino);

if(postman.getEnvironmentVariable("nivel") == "POSGRADUACAO"){
    postman.setEnvironmentVariable("nivel-modificado", "pos-graduacao");
} else {
     postman.setEnvironmentVariable("nivel-modificado", postman.getEnvironmentVariable("nivel"));
}

Is there anyway I could do the same in Insomnia? I know how to set env variables and all, its the if /else part that I want help with.

Tried creating a new variable to receive the one already there and them change it somehow. But don't know how it works in Insomnia.

What I want is that when nivel receives "POSGRADUACAO" it will be changed to "pos-graduacao" and a new variable will receive the new value.

Upvotes: 0

Views: 1211

Answers (1)

sidtagirisa
sidtagirisa

Reputation: 86

You can do in the following way:

Set this under the base / custom environment

{
    "dev_url": "http://somedevurl.com",
    "prod_url": "http://someprodurl.com",
    "env": "dev",
    "base_url": "{% if env == 'dev' %} {{ _.dev_url }} {% else %} {{ _.prod_url }} {% endif %}"
}

and use {{ _.base_url }} in your requests

Upvotes: 0

Related Questions