# Data Driven : How to attach single json file to Postman collection runner having multiple APIs (requests) in it?

**URL:** <https://community.postman.com/t/data-driven-how-to-attach-single-json-file-to-postman-collection-runner-having-multiple-apis-requests-in-it/12219>\
**Category:** Help Hub\
**Tags:** tests, collections, jsondatafile\
**Created:** [April 27, 2020, 6:34am UTC](https://community.postman.com/t/data-driven-how-to-attach-single-json-file-to-postman-collection-runner-having-multiple-apis-requests-in-it/12219 "2020-04-27T06:34:45Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Prachii](https://avatars.discourse-cdn.com/v4/letter/p/74df32/32.png) [@Prachii](https://community.postman.com/u/Prachii)\
**Post date:** [April 27, 2020, 6:34am UTC](https://community.postman.com/t/data-driven-how-to-attach-single-json-file-to-postman-collection-runner-having-multiple-apis-requests-in-it/12219/1 "2020-04-27T06:34:45Z")

</div>

I am trying to automate the testing of different APIs. I have created collection in postman. There are multiple APIs present inside a collection and each API has different body structure (inputs) and different test cases. Each API should be tested for multiple testcases. e.g. API 1 has 2 Test cases and API 2 has 5.

API1

```
Testcase1
    input a
    input b
Testcase2
    input c
    input d

```

API2

```
Testcase1
    input 1
Testcase2
    input 2
Testcase3
    input 3
Testcase4
    input 4
Testcase5
    input 5

```

I want to send body of each API dynamically through JSON file.

I need a single JSON file which can contain data for all APIs.

is it possible? If yes, How can achieve it?

---

<div class="post-metadata">

**Author:** ![vjjohnson04](https://avatars.discourse-cdn.com/v4/letter/v/f19dbf/32.png) [@vjjohnson04](https://community.postman.com/u/vjjohnson04)\
**Post date:** [May 3, 2020, 4:34am UTC](https://community.postman.com/t/data-driven-how-to-attach-single-json-file-to-postman-collection-runner-having-multiple-apis-requests-in-it/12219/2 "2020-05-03T04:34:37Z")

</div>

Yes. You can structure your json data file as below and then use the input in the API you want.

> {  
> “input a”:“val”,  
> “input b”:“val”,  
> “input 1”:“val”,  
> “input 2”:“val”  
> }

---

<div class="post-metadata">

**Author:** ![Prachii](https://avatars.discourse-cdn.com/v4/letter/p/74df32/32.png) [@Prachii](https://community.postman.com/u/Prachii)\
**Post date:** [May 4, 2020, 4:10pm UTC](https://community.postman.com/t/data-driven-how-to-attach-single-json-file-to-postman-collection-runner-having-multiple-apis-requests-in-it/12219/3 "2020-05-04T16:10:00Z")

</div>

Hi @vjjohnson04,

I tried your solution but It will be messy for more number of APIs.  
Also for iteration 3, API 1 will not have any input so it will get failed.

---

<div class="post-metadata">

**Author:** ![Prachii](https://avatars.discourse-cdn.com/v4/letter/p/74df32/32.png) [@Prachii](https://community.postman.com/u/Prachii)\
**Post date:** [May 4, 2020, 4:57pm UTC](https://community.postman.com/t/data-driven-how-to-attach-single-json-file-to-postman-collection-runner-having-multiple-apis-requests-in-it/12219/4 "2020-05-04T16:57:34Z")

</div>

Let me reform my query with more specific example.

I have 2 APIs named “LogIn” API and “search” API.

Request body for “LogIn” API is as follows,

```
  {	
     "userName": "{{username}}",
     "passWord": "{{password}}"
  }

```

I have created JSON file for “LogIn” API, which looks like,

![image](https://us1.discourse-cdn.com/getpostman/original/3X/a/3/a3cb8d90dbd8f987f540e28217a4506e3eb46f21.png)

Request body for “Search” API is as follows,

```
 {
    "Input":"{{value}}"
 }

```

There is an another JSON file for “Search” API is as follows  
 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/7/6/7662c79f6f79fc571c1c0d9e6fe8689528ff8da6.png)

I want to run login API for two iterations(refer JSON for login) and search API for 5 iterations(refer JSON for search).

I want to automate testing of these two APIs using single JSON file (combination of these two files). Please suggest how should I achieve it?  
Both the APIs are currently in same collection runner.

---

<div class="post-metadata">

**Author:** ![vjjohnson04](https://avatars.discourse-cdn.com/v4/letter/v/f19dbf/32.png) [@vjjohnson04](https://community.postman.com/u/vjjohnson04)\
**Post date:** [May 5, 2020, 6:08am UTC](https://community.postman.com/t/data-driven-how-to-attach-single-json-file-to-postman-collection-runner-having-multiple-apis-requests-in-it/12219/5 "2020-05-05T06:08:40Z")

</div>

The way I would do this is by adding a **Test Control** file which would contain the below code.

> var userName = pm.iterationData.get(“userName”);  
> var passWord = pm.iterationData.get(“passWord”);
> 
> if(userName !==“” && passWord !==“”){  
> pm.setNextRequest(“Login”);  
> } else {
> 
> ```
> pm.setNextRequest("Search");
>     
> }
> 
> ```

Hope this helps.
