jsonapirunscope

Inserting Dynamic Data and Request Chaining Runscope


When the first step return a json object like this

  {
"success":true,
"total":21,
"items":
[
{"id":"762"},
{"id":"763"},
{"id":"764"}
]
}

how can i assign variable id to the first "id" item in response

i have done it like this but it didn't work

enter image description here

i also tried items.id, items[0].id but that didn't work either


Solution

  • To assign a variable to an item in a list, you can use a post-response script.

    In this case, something like:

    var data = JSON.parse(response.body);
    var myId = data.items[0].id;
    variables.set("id", myId);