Chaining API Requests to Populate Data from Prior Data

I’ve read through multiple forums and videos but cannot seem to resolve my issue. I’m sure this has already been covered somewhere on here and is probably very simple, but I need some additional handholding to walk me through the process for my use case.

*Using Postman desktop version 7.34.0 on Windows x64. Coding to Wrike (project management tool) REST API using bearer token.

Desired Outcome= (1) use Postman to POST 24 tasks into Wrike via API. (2) Then GET the unique task ID from Wrike for each of those tasks that were just created. (3) Then POST document (.xls) to each of those unique task ID’s from my PC.

I’ve been able at this stage to complete step (1) above to POST in the 24 tasks by building a POST request that looks for variables. I feed in those variables from a CSV file with the collection runner and it works great.

Where I’m getting hung up is on step (2) and (3) above. I need to pull back the task id’s that populate from step (1). Then after I pull those back I need to push an Excel file to those id’s. I believe I should be able to achieve this by using either Pre-request Scripts or Tests but I’m not sure exactly how to code that or in what order.

Here is the structure I have:

Postman Collection = “Wrike Store Task Assignment”
Folder= “Process”
Requests= “Post Tasks to Stores”
“Get Task ID from Prior Post”
“Post Attachment to Task”

Image of “Post Task to Stores”
Body calls the variables. Also set a Test to run after to set the id variable. This is working. Response below is just me testing on a single POST while I work to figure this out.



I think from here my next step needs to be that I run through and GET all of the unique “id” that are created in step (1). Then using that list, make another POST to post my .xls attachment to those newly created tasks. I’m stuck on this an not sure how to code it.

I’m completely new to API’s and Postman so I apologize if I haven’t provided things in the proper format here. I’m teaching myself as I go and reading/watching videos. Just let me know if more details are needed. I’ll likely need you to step me through in detail/images/video the exact code or process for this just because all of this is still so new to me.

Thanks!

You need to store the ids in an array and get them from there one by one.

Here is an idea of how to manipulate the array and send a request one by one:

Vdespa,

Thank you for your response. I apologize as I’m still so new with all of this that I’m not able to directly correlate the tutorial to my use case. Do you think I can achieve all of my steps with 1 POST like the video shows using the pre-request Script, the body, and then finishing up with the Test? Or should I be running my post in step (1) first and then using the video to call back the ID’s that provides?

There is no reason to apologize.

As a first step, I recommend trying what the tutorial shows you, irrespective of your own problem that you are trying to solve. It is important to get the concepts being demonstrated.