Loop request based on data from response in Postman

  Рет қаралды 58,363

Valentin Despa

Valentin Despa

Күн бұрын

In this Postman tutorial, I wanted to show you how to reuse a request and loop over a set of data from a previous request.
If this was helpful and you want to support me create more videos like this one, please consider subscribing.
👉 / @vdespa
The Postman collection used in this tutorial is available here:
gist.github.com/vdespa/b524b5...
--
⭐️ Video contents ⭐️
00:00 - Introduction
00:45 - Passing data between requests w/ variables
06:53 - Creating a custom workflow with setNextRequest
12:58 - Conclusion
--
⭐️ 🎓 The complete guide to Postman (online course) ⭐️
Want to learn more about Postman? Check my Postman online course.
Get it at a special price and help support this KZfaq channel:
vdespa.com/courses/
--
⭐️ 💬 I have a question. ⭐️
I do my best to answer all comments here on KZfaq but I cannot make any guarantees.
If you have a question, it is best to ask your question on Discord, on the Postman User Group on Facebook, or on the Postman Community (links below).
If you are asking a question, make sure to include as many details as possible, including screenshots.
If you have purchased the Postman online course, please use the Q&A section or send me a message directly.
Please do not email me or contact me on other channels as I might not be able to answer. Sorry!
--
⭐️ 💡 I have a video idea ⭐️
Do you want me to create a video on a specific topic? Just fill out the form below:
forms.gle/uWEzXFQ2viJtZtvZ7
--
⭐️ 📺 Learn Postman on KZfaq ⭐️
Collection of video tutorials:
▸ Learn Postman | bit.ly/2CFaf70
▸ Postman Crash Course | bit.ly/2YwEBBT
▸ Postman Tips & Tricks | bit.ly/2JLkXyU
___
⭐️ 📕 Free resources ⭐️
📌 DOWNLOAD the FREE Postman Quick Reference Guide
bit.ly/postman-quick-reference-yt
📌 Ask a question on Discord (unofficial)
/ discord
📌 Join the Postman User Group on Facebook (unofficial)
bit.ly/2OutAMZ
📌 Postman community forum (official)
community.getpostman.com/
--
⭐️ 📩 Contact & Imprint ⭐️
👉 Let's be friends
sendfox.com/lp/1dv56d
👉 Follow me on Twitter:
/ vdespa
👉 Follow me on Medium:
/ vdespa
👉 Follow me on Facebook:
/ valentin-despa-1130381...
👉 Let's connect on LinkedIn:
/ vdespa
vdespa.com/imprint

Пікірлер: 134
@vdespa
@vdespa 2 жыл бұрын
Want to have ME be your Postman teacher? 🤔 Here's how: vdespa.com/courses/
@shakedown1979
@shakedown1979 2 жыл бұрын
Awesome Valentin, got me around a problem I'd been scratching my head about for a while here!
@vdespa
@vdespa 2 жыл бұрын
You are welcome. Thank you for leaving a comment.
@paulc8308
@paulc8308 2 жыл бұрын
Great video Valentin, I've done loops similar to this in the past but I didn't realise the clever trick you can do with Arrays and Objects. Top Tip :) Makes the code cleaner too 👍🏻
@vdespa
@vdespa 2 жыл бұрын
Thanks, Paul. I am glad you have learned something new.
@arashitook6784
@arashitook6784 Жыл бұрын
Great stuff! You are creating great content to help with learning API with Postman! Thank you!
@vdespa
@vdespa Жыл бұрын
Glad you enjoy it! You are welcome. Thank you for leaving a comment.
@emilvafin436
@emilvafin436 Жыл бұрын
What an enlightening lesson ! Thank you kind sir
@vdespa
@vdespa Жыл бұрын
Glad you enjoyed it! You are welcome. Thank you for leaving a comment.
@suzannevogt6528
@suzannevogt6528 Жыл бұрын
Perfect. Just what I needed to know.
@vdespa
@vdespa Жыл бұрын
You are welcome. Thank you for leaving a comment.
@shameeraweerasinghe6280
@shameeraweerasinghe6280 Жыл бұрын
Great explanation, you saved my day!
@vdespa
@vdespa Жыл бұрын
Glad to hear it! You are welcome. Thank you for leaving a comment.
@priyankabaheti4675
@priyankabaheti4675 2 жыл бұрын
This video was very helpful. Thank you
@vdespa
@vdespa 2 жыл бұрын
I am glad it helped!
@wesleyi.n6463
@wesleyi.n6463 2 жыл бұрын
I can't thank you enough for this great video
@vdespa
@vdespa 2 жыл бұрын
You're very welcome!
@RonenMiller
@RonenMiller 2 ай бұрын
Very clear and helpful!
@vdespa
@vdespa 2 ай бұрын
You are welcome. Thank you for leaving a comment.
@brendenlang9072
@brendenlang9072 Жыл бұрын
Great video and explanation!
@vdespa
@vdespa Жыл бұрын
Glad you liked it! You are welcome. Thank you for leaving a comment.
@hangeryouhen3311
@hangeryouhen3311 2 жыл бұрын
It's very useful, thank you!
@vdespa
@vdespa 2 жыл бұрын
Glad it was helpful!
@revvedupofficial
@revvedupofficial Жыл бұрын
thank you so much, it really helped me a lot
@vdespa
@vdespa Жыл бұрын
You are welcome. Thank you for leaving a comment.
@somechrisguy
@somechrisguy 2 жыл бұрын
I had 80 calls to make, I tried writing some axios js to do this, then gave up and tried postman ‘flows’, gave up on that and was about to start doing them all manually… then I found this video. You saved me a lot of time. Thanks so much.
@vdespa
@vdespa 2 жыл бұрын
You're welcome, I am glad it helped. What was the issue with Postman flows?
@somechrisguy
@somechrisguy 2 жыл бұрын
@@vdespa I just couldn’t work it out, I prefer to use JS code
@rohitw548
@rohitw548 2 жыл бұрын
Such a Fabulous Video
@vdespa
@vdespa 2 жыл бұрын
You are welcome. Thank you for leaving a comment.
@tmanrx7
@tmanrx7 2 жыл бұрын
Brilliant video 👍
@vdespa
@vdespa 2 жыл бұрын
Glad you enjoyed it
@AbdelhakKhedhiri-on8fx
@AbdelhakKhedhiri-on8fx Жыл бұрын
Thank you it is very hepful
@vdespa
@vdespa Жыл бұрын
You are welcome. Thank you for leaving a comment.
@hexazan8833
@hexazan8833 Жыл бұрын
thank you , this video was useful
@vdespa
@vdespa Жыл бұрын
Glad to hear that! You are welcome. Thank you for leaving a comment.
@jarrodmcguire2508
@jarrodmcguire2508 2 жыл бұрын
So handy, thanks.
@vdespa
@vdespa 2 жыл бұрын
I am glad that you liked it!
@hbk666
@hbk666 2 жыл бұрын
you saved my day! thanks a lot~!
@vdespa
@vdespa 2 жыл бұрын
Glad to hear that! Happy to help.
@user-uw5qg3yo5l
@user-uw5qg3yo5l 2 жыл бұрын
Nice tutorial
@vdespa
@vdespa 2 жыл бұрын
Thanks 👍
@user-wc8nx9vm7g
@user-wc8nx9vm7g 7 ай бұрын
Thanks A lot😍🤩
@vdespa
@vdespa 7 ай бұрын
You're welcome 😊 Thank you for leaving a comment.
@niamularifin6799
@niamularifin6799 4 ай бұрын
Great Video
@vdespa
@vdespa 4 ай бұрын
Glad you enjoyed it. Thank you!
@royandre-davidkoupoh9015
@royandre-davidkoupoh9015 Жыл бұрын
Good video
@vdespa
@vdespa Жыл бұрын
You are welcome. Thank you for leaving a comment.
@farhaan2812
@farhaan2812 6 ай бұрын
This is great. Do you have a video of this for XML responses?
@frsaund06
@frsaund06 Жыл бұрын
Hi, I’ve tried to apply this tutorial to some work I’m doing but my response is a nested object (I’m really new to postman and working with APIs in general but I think this is what it’s called). I need to create an array from one of the fields in this nested object but because the response I’m getting isn’t an array the map function isn’t working. Would it be possible to create a new example that would work off of nested object? If you have this already I’m sorry, I’ve tried to find it but have been unsuccessful thus far. Cheers!
@anvis360tech
@anvis360tech Жыл бұрын
Hi valentine, If I want to pass this id into next call path parameter then do I need to do any change or same script will work . I am getting undefined shift error
@FantasminhaGames
@FantasminhaGames Жыл бұрын
Great video! How to run collections async?
@soiletsstelios8533
@soiletsstelios8533 2 жыл бұрын
I want to make an add-on program that monitors the console (listens), separates some commands and sends them back to the server.
@dmoazzam
@dmoazzam Жыл бұрын
Thank you sm!! What even ChatGPT couldn't help me with, you could! So thank you Valentin. P.S could you share the video recording tool(s) you used? again, thank you!
@vdespa
@vdespa Жыл бұрын
Glad to hear that. OBS.
@peerjee
@peerjee 2 жыл бұрын
Loved it. How can I turn my looping and processing logic that I have written in Postman with your help to a stand alone API tat is running on a Linux box perhaps. Please point me to a course or a lecture you have published. I would love to take a paid course if one exists. Thanks for all you do
@vdespa
@vdespa 2 жыл бұрын
You may want to learn about Newman, which helps you run a Postman collection on any OS. You can't turn a Postman collection into an API. For courses, see the video description.
@paneerselvam3682
@paneerselvam3682 Жыл бұрын
Hi sir.. can we pass an entire response of a get call as a body to the next post api call?
@paneerselvam3682
@paneerselvam3682 2 жыл бұрын
Hi Sir, I am having a post request in my collection. When I run the entire collection I need that particular request to be repeated 10 times. So now as per your method i can call that request 10 times, once it is done will the next request in the collection will be continued? Or this statement postman.setNextRequest(null) will stop the collection run?
@vdespa
@vdespa 2 жыл бұрын
Yes, once you have iterated the desired number of times, the next request will be called (unless otherwise indicated).
@sebastus27
@sebastus27 2 жыл бұрын
Hello Valentin! I have a question. How can implement a wait function? I am asking because I noticed not all requests are received, at run collection it is the iteration field and there if I put 10 requests I get 4 or 7. How can fix this problem?
@vdespa
@vdespa 2 жыл бұрын
Hello Sebastian: I am not sure I get the problem. At which point do you need to wait?
@user-in5wp8yo2i
@user-in5wp8yo2i 24 күн бұрын
I this begginer level, or little bit advanced postmen level?
@nicoaraeugen
@nicoaraeugen Жыл бұрын
Super useful lessons! Well done! I also have a question. I have a POST for inserting some fields, and I want to test if the ID , which is unique, can be inserted twice? How can I run the same request twice? Thank you very much!
@vdespa
@vdespa Жыл бұрын
You are welcome. Thank you for leaving a comment.!
@honeybhatia9901
@honeybhatia9901 2 жыл бұрын
Hi If I save the values in CollectionVariable or environment variable then it always return first vlaue and shift function not working. Its only working with local varible.
@vdespa
@vdespa 2 жыл бұрын
I doubt this is the case. Double check your code, use console.log to debug.
@vamsikrish3185
@vamsikrish3185 2 жыл бұрын
Same logic is not working for array of strings. Have tried for Id and names. When tried with IDs it's working fine. Is there any other solution to deal with names. Please reply me
@krystofhornik6665
@krystofhornik6665 2 жыл бұрын
How would you extract ids being the response object, not an array?
@vdespa
@vdespa 2 жыл бұрын
It is hard to answer this with the given information. Consider posting your question in the Postman community (community.postman.com/) and share what you have tried so far and where did you get stuck. Include screenshots and as many details as possible. Feel free to tag me with @vdespa. Thanks!
@paneerselvam3682
@paneerselvam3682 2 жыл бұрын
Hi Sir, we are getting an array of values and passing one by one in the next request using shift function... Is there a possibility to pass the value in the reverse order? I mean if I have an array of values [12345] then i have to pass 5 in the first request and 4 in the second run. Can you please help me?
@vdespa
@vdespa 2 жыл бұрын
Instead of shift(), you can use pop()
@paneerselvam3682
@paneerselvam3682 2 жыл бұрын
@@vdespa Thank you very much 👍
@nikolaurevac7175
@nikolaurevac7175 2 жыл бұрын
Thanks for this video! If I run my collection, it still executes previous request each time as well. How to set to execute only second call in multiple times?
@vdespa
@vdespa 2 жыл бұрын
Hard to say. Double check your setNextRequst value.
@nikolaurevac7175
@nikolaurevac7175 2 жыл бұрын
@@vdespa Do you know how to write a script for creating a csv file on desired location and fill it by the variable values that I created in Tests of request?
@vdespa
@vdespa 2 жыл бұрын
@@nikolaurevac7175 You can't do that in Postman. Search my channel for a CSV tutorial.
@Findmanish09
@Findmanish09 Жыл бұрын
Hi.. I have tried this but keeps running with the 0th index value and doesn't exit.
@MladjanNjagojevic
@MladjanNjagojevic 2 жыл бұрын
Hey! Great stuff! Thanks. I have a question regrding this. How to filter or find specicic value from a nested array? Response looks like this: [ { "attributes": [ { "id": 54, "name": "Farbe", "options": [ "Grau" ] }, { "id": 57, "name": "Größe", "options": [ "60 x 20 x 1.5 cm" ] }, So, I want to save to a variable the value from "options", but only if the name in an object is "Farbe"? How that function would look like?
@MladjanNjagojevic
@MladjanNjagojevic 2 жыл бұрын
And I forgot to say, position of those nested objects may varay depending on a product. Some products do not have colors (first object in this case has color: this part "Farbe") for instance, so something like: const ean = response.map(data => data.meta_data[2].options[0]); will not work. Actually, it will work, but it will picup different data based on attribute existance.
@vdespa
@vdespa 2 жыл бұрын
You may want to get familiar with the filter function on arrays.
@MladjanNjagojevic
@MladjanNjagojevic 2 жыл бұрын
​@@vdespa Hey! Thanks for getting back. I will research that. If you already have something helpful on this topic in your portfolio, please share it. Or maybe you have just got a new topic for upcoming tutorials... :)
@rajusjohn1
@rajusjohn1 2 жыл бұрын
I have 1 GET request and 2 PUT requests in the collection.How do I pass the same variable in the second PUT request? variable is passing only in the first PUT request
@vdespa
@vdespa 2 жыл бұрын
Once you get a variable, it is available in all upcoming requests.
@midnightoilgames9796
@midnightoilgames9796 3 ай бұрын
awesome help! well explained. that intro is way too corny! lol
@vdespa
@vdespa 3 ай бұрын
Glad you liked it! Thank you!
@toufiqalam7445
@toufiqalam7445 2 жыл бұрын
Hi valentine, I have two queries, 1. Why did we use "variables" instead of "environment variables" 2. I have 605 id(s), but when ran the collection it ran for 1210 iteration . why is that?
@vdespa
@vdespa 2 жыл бұрын
I have used local variables, as they are no persisted. You can use any type of variables. Start with a smaller data set and use console.log to debug what is going on.
@md.atifkhan6658
@md.atifkhan6658 2 жыл бұрын
Hey Valentin Why we need to connect database with Postman? what will be the actual scenario when we need to the connect database..and if we will connect database can we do anything in database with postman? what about security and integrity issue.
@vdespa
@vdespa Жыл бұрын
I did other tutorials on connecting to a database. See my channel.
@hooyah
@hooyah Жыл бұрын
Hi valentin. I want to know how i push response into variable. Here example. Va is virtual account 1. Post create virtual account 2. Get the VA number then Push VA number to variable. 3. Repeat process 1 and 2 until all bank VA is created or 5 times. I stuck at this. I need va number foranother request in my api.
@vdespa
@vdespa Жыл бұрын
You may need to learn a few Postman basics before getting into scripting. See the video description for courses and other tutorials.
@helpothers6751
@helpothers6751 Жыл бұрын
i have list of items but shift() method always it's taking first value in the list please guide me
@vdespa
@vdespa Жыл бұрын
Which value is it taking?
@rohitw548
@rohitw548 2 жыл бұрын
Valentin - I need your help please. Problem - I am Running a Post request to create a Loan 1 by sending L1 in the request. Similarly I need to test Loan types from L1 to L13. These loan types will be created using the same Post request, just by replacing L1 with L2 or L3 or L3 and so on. I am passing the loan types in CSV file as shown in your video. And it works as expected. I see that for 13 types of loan types, I get 13 iterations in my html reporter. Which is again as expected. But how do I merge those 13 iterations into 1 iteration. How do I create a report which will just have 1 iteration, which will display the results for all 13 loan types. Let me know please
@vdespa
@vdespa 2 жыл бұрын
If the data is coming from a CSV file, you can't read the entire data set at once. This is why you have 13 iterations.
@rohitw548
@rohitw548 2 жыл бұрын
@@vdespa can I merge 13 iterations into 1 if I use a Json file as a input
@MrManandevil
@MrManandevil 2 жыл бұрын
Sir i don't understand , i followed the same steps as you did but it is saying that response.map is not a function and giving error
@russellstandard4955
@russellstandard4955 2 жыл бұрын
Same here, was there additional dependencies required?
@marklm1
@marklm1 2 жыл бұрын
I am having the exact same problem too. It says response.map is not a function. How do I fix that?
@vdespa
@vdespa 2 жыл бұрын
It is hard to answer this with the given information. Join the Discord community (see link in the description) and ask your question there. Consider adding more details, including screenshots. Thanks for understanding.
@connorrich8199
@connorrich8199 2 жыл бұрын
@@vdespa The discord link expired, may I have a new one?
@shubhamwalia5118
@shubhamwalia5118 2 жыл бұрын
Hey Valentin! First and foremost the video is really helpful and informative. I have landed into an error that I'm not able to fix on my own and thought you might be able to assist. I'm getting the error TypeError: Cannot read property 'shift' of undefined when I execute the Run Collection. In GET tests script section I have below code: const response = pm.response.json(); const tagnamess = response.map(tagname => tagname.name); console.log(tagnamess); pm.variables.set('tagnamess',tagnamess); And in POST pre-request script section I have below code: const namess = pm.variables.get('namess'); pm.variables.set('currentnamess', namess.shift()); And in the POST request body section i have below: { "tag": { "name": {{currentnamess}} } } What is that I'm missing? Please treat that as urgent, thanks!
@shubhamwalia5118
@shubhamwalia5118 2 жыл бұрын
@valentin despa, can you please check this?
@vdespa
@vdespa 2 жыл бұрын
It is hard to answer this with the given information. Join the Discord community (see link in the description) and ask your question there. Consider adding more details, including screenshots. Thanks for understanding.
@victorious_2230
@victorious_2230 10 ай бұрын
Hi.brother, I my collection there are four request First is auth Second is init Third is logic Fourth is end So i want to run third and fourth request multiple times(eg:10) ,how i can do this(third request contains session id which need to passed to fourth and then from fourth request session id need to be passed to third requestm)
@vdespa
@vdespa 10 ай бұрын
Look into setNextRequest
@ShruthiPamadi
@ShruthiPamadi Жыл бұрын
Hi , I am facing issue in handling workflow. "postman.setNextRequest()" is going infinite loop even though there is stop workflow code postman.setNextRequest(null);. Here is my piece of code. if(Array.isArray(req) && req.length>0) { postman.setNextRequest('Create Patient');//my post API name-Create Patient } else if(requestArray.length==0){ postman.setNextRequest(null); } req is my array which has multiple entries in it. Great if you could help in resolving . Thanks in advance.
@vdespa
@vdespa Жыл бұрын
ADD some console.log statements to your code to better understand what is going on.
@balajicmb1132
@balajicmb1132 2 жыл бұрын
How to updates multiple records multiple updates postman to postgresql sqlalchemy ?
@vdespa
@vdespa 2 жыл бұрын
It is hard to answer this with the given information. Join the Discord community (see link in the description) and ask your question there. Consider adding more details, including screenshots. Thanks for understanding.
@user-vm4id5gi4x
@user-vm4id5gi4x 2 жыл бұрын
Hello . But why postman show me the Response.map not a function?
@vdespa
@vdespa 2 жыл бұрын
Probably because it is not an array
@user-vm4id5gi4x
@user-vm4id5gi4x 2 жыл бұрын
@@vdespa how can I check array is true ?
@paneerselvam3682
@paneerselvam3682 Жыл бұрын
Hi sir.. can we pass an array of values as query param in postman... For each of the value in array i will have the decoded value in the response. Can i get those values as array. For eg i have array ["Arun","Kumar","Raj"].. for each of this value.. i will have a decoded value in response. I have to get those values in another array. Could you please help with this. 🙂
@vdespa
@vdespa Жыл бұрын
It is hard to answer this with the given information. Consider posting your question in the Postman community (community.postman.com/) and share what you have tried so far and where did you get stuck. Include screenshots and as many details as possible. Feel free to tag me with @vdespa. Thanks!
@nabinupreti3416
@nabinupreti3416 Жыл бұрын
TypeError: Cannot read properties of undefined (reading 'shift')
@vdespa
@vdespa Жыл бұрын
Check your code, use console.log to make sure the property you are using exists.
@MrManandevil
@MrManandevil 2 жыл бұрын
Please help me Valentin I am unable to run tests in Postman even after following the exact same steps, if you would just connect with me for a 5 min session then I would be grateful.
@vdespa
@vdespa 2 жыл бұрын
It is hard to answer this with the given information. Join the Discord community (see link in the description) and ask your question there. Consider adding more details, including screenshots. Thanks for understanding.
@jopadjr
@jopadjr 2 жыл бұрын
46th...Thanks
@vdespa
@vdespa 2 жыл бұрын
46th what?
@jopadjr
@jopadjr 2 жыл бұрын
@@vdespa It means Im the 46th who smashed the like button
@vdespa
@vdespa 2 жыл бұрын
@@jopadjr thanks 👍 keep it coming for other videos. You are the best
@jopadjr
@jopadjr 2 жыл бұрын
@@vdespa sure...I'm learning a lot from you mate.. Keep up the good work.. Cheers !!!
@paneerselvam3682
@paneerselvam3682 2 жыл бұрын
Hi Sir, I have two clarifications. 1. If I get a array [1,2,3] in a response how to pass the array in another request as [3,2,1]. 2.. If I get a array [1,2,3] in a response how to pass the array in another request as [ 1, 2, 3 ].
@vdespa
@vdespa 2 жыл бұрын
You can use JavaScript to transform the array to your needs.
@olelobyco7539
@olelobyco7539 4 ай бұрын
Nice, but it doesn't work :(
@mTz0KS43
@mTz0KS43 28 күн бұрын
Looking forward for a remake using postman flows🫡
Data-driven testing with different data sets for each request
16:48
Valentin Despa
Рет қаралды 15 М.
ВОДА В СОЛО
00:20
⚡️КАН АНДРЕЙ⚡️
Рет қаралды 35 МЛН
Jumping off balcony pulls her tooth! 🫣🦷
01:00
Justin Flom
Рет қаралды 28 МЛН
Learn JSON in 10 Minutes
12:00
Web Dev Simplified
Рет қаралды 3,1 МЛН
Postman Data Driven Testing with CSV Data File | Postman Testing Tutorial
17:20
SDET Unicorns by Dilpreet Johal
Рет қаралды 10 М.
Use Response Data in a Request | Postman Flows
3:29
Postman
Рет қаралды 18 М.
Run Postman Collections in Jenkins with Newman
35:35
Valentin Despa
Рет қаралды 20 М.
How to reuse Postman scripts and tests among different test cases
10:31
25 Nooby Pandas Coding Mistakes You Should NEVER make.
11:30
Rob Mulla
Рет қаралды 265 М.
Send HTTP requests from scripts Postman
14:14
Valentin Despa
Рет қаралды 20 М.