# Store IDs from json and re-use them in a second API call

**URL:** <https://community.postman.com/t/store-ids-from-json-and-re-use-them-in-a-second-api-call/5485>\
**Category:** Help Hub\
**Tags:** array\
**Created:** [May 17, 2019, 11:57am UTC](https://community.postman.com/t/store-ids-from-json-and-re-use-them-in-a-second-api-call/5485 "2019-05-17T11:57:39Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![bhargavkaranam96](https://avatars.discourse-cdn.com/v4/letter/b/e99b99/32.png) [@bhargavkaranam96](https://community.postman.com/u/bhargavkaranam96)\
**Post date:** [May 17, 2019, 1:10pm UTC](https://community.postman.com/t/store-ids-from-json-and-re-use-them-in-a-second-api-call/5485/2 "2019-05-17T13:10:02Z")

</div>

Hi @francoisc,  
Welcome to the community 👋

You can make use of Postman’s variables and collections for this. Create a collection with your two requests ([https://learning.getpostman.com/docs/postman/collections/intro\_to\_collections/](https://learning.getpostman.com/docs/postman/collections/intro_to_collections/))

In your first request’s test script, you can have the following snippet.

```javascript
let response = pm.response.json(),
    ids = _.map(response.items, ({ id }) => ( id )); // This will store your ids in an array. For reference (https://lodash.com/docs/4.17.11#map)

pm.variables.set('ids', JSON.stringify(ids));

```

And in the body of the second request, you can access the ids like this. Choose Raw and content type as `application/json`

```auto
{
 "ids": {{ids}},
 "type": "test"
}

```

Now you can run your collection with the help of Postman’s collection runner ([https://learning.getpostman.com/docs/postman/collection\_runs/starting\_a\_collection\_run/](https://learning.getpostman.com/docs/postman/collection_runs/starting_a_collection_run/))

The second request body will have your `ids`. You can check the requests sent in Postman’s console (View \> Postman Console)

[https://learning.getpostman.com/docs/postman/collection\_runs/debugging\_a\_collection\_run/](https://learning.getpostman.com/docs/postman/collection_runs/debugging_a_collection_run/)

---

_[View the full topic](https://community.postman.com/t/store-ids-from-json-and-re-use-them-in-a-second-api-call/5485)._
