Retrieve parts of a GET response to feed into the next PATCH update body after some formatting

Hello,

I am newbie.

I’m using a GET to request a list of objects. These are just a few of them in the response:
{
“id”: 437725467,
“name”: “Div - 02”,
“orig_id”: null,
“proj_id”: “12345”,
“code”: “02”
},
{
“id”: 437725468,
“name”: “Div 02 - Dept 230”,
“orig_id”: “0201”,
“proj_id”: “12345”,
“code”: “02-230”
},
{
“id”: 440033671,
“name”: “Div 02 - Dept 260”,
“proj_id”: “12345”,
“orig_id”: “0202”,
“code”: “02-260”
},
{
“id”: 518363961,
“name”: “Div 01 - Dept 330”,
“proj_id”: “12345”,
“orig_id”: “0103”,
“code”: “01-330”
}

I want to save all of the ids, codes, and proj_id (same in this case) to an environment variable array and then concatenate “code” and “proj_id” to make a new value for “orig_id” in the next PATCH API call. Its body would look like this:

{
“updates”: [

{
    "id": 437725468,
    "orig_id": "12345-02"
},
{
    "id": 437725468,
     "orig_id": "12345-02-230"
 },
{
    "id": 440033671,
    "orig_id": "12345-02-260"
},
{
    "id": 518363961,
    "orig_id": "12345-01-330"
 }

]
}

Any idea is highly appreciated.

Thank you all!

Hey @balexalex ! Welcome to the Community, and welcome to learning Postman. I’m going to move your post over to the Just getting started category so that it has more visibility :slight_smile:

There are a couple of previous posts that might be relevant. Saving environment variables in an array, How to set environment variables from an array?, and Set array from environment variable for request body in postman can get you part of the way there, at least.

1 Like

Also, today I learned the word “concatenate” ! cool!

1 Like