Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

postman: save response on a global variable

Tags:

postman

With PostMan, how can save the follow response:

[
    {
        "id": "6254c754-5a97-43fd-9b48-c428b9bd69e5",
        "name": "fdsfds",
        "description": "fdzf",
        "type": 0,
        "createDate": "2018-08-01T17:49:29.071+01:00",
        "lastUpdateDate": "2018-08-01T17:49:29.071+01:00",
        "lastUpdateUser": null,
        "variables": null,
        "instructions": null
    }
]

on a variable? For example the id?

var jsonData = pm.response.json();

console.log(jsonData.id);

pm.globals.set("variable_key", jsonData.id);
like image 856
Carlos Rodrigues Avatar asked Aug 28 '26 18:08

Carlos Rodrigues


1 Answers

to set the environment variable "authkey" from response

var obj = pm.response.json()["token"];
pm.environment.set("authkey", obj);
like image 126
Subhash Avatar answered Sep 03 '26 22:09

Subhash