3

I log in, then get the token. I stored that varibale and use it throughout my next collections.

let location = pm.response.json().location
let token = location.split("?token=")[1]
console.log('Token : ',token );

When I get the token, I can use that token to call my next API call.

Let's say I call : cpe profiles, I will get a list of profiles in my CPE

{
    "id": "32341696-80c4-4597-998b-5f6cbe7d5a48",
    "group": "a5dd9ed2-f9c6-4d23-9623-de0cae4d4aa8",
    "name": "Jane",
    "dob": null,
    "image": "assets/profile/e6398f955035eb1a6a297739fedcc770.png",
    "cpe": "E8DE2799DD87"
}

I want to create dynamic variables for all my profiles "{{profile.name}}_ID"

1 profile, I want to create 2 variables.

JANE_ID = "32341696-80c4-4597-998b-5f6cbe7d5a48"
JANE_GROUP = "a5dd9ed2-f9c6-4d23-9623-de0cae4d4aa8"

Then, I can access that avarable later on

How can I create a dynamic variables in Postman ?

code-8
  • 54,650
  • 106
  • 352
  • 604

2 Answers2

2

I think I just solved my owned problem. ‍

var jsonData = JSON.parse(responseBody);
jsonData.forEach(function(object) {
    pm.globals.set((object.name + "_ID").toUpperCase(), object.id);
    pm.globals.set((object.name + "_GROUP").toUpperCase(), object.group);
});

console.log(pm.globals);

enter image description here

code-8
  • 54,650
  • 106
  • 352
  • 604
0

Not exactly dynamic - you can create different environments to hold different values for your user_id.

enter image description here

Milan
  • 1,903
  • 17
  • 16