Aplogies in advance, pretty new to postman and not much cop at coing.
I am currently putting a number of bookings through to a system where let’s say the variables examples are; BookingRefOne and BookingRefTwo. These could increment with each JSON Object in the response.
[{
"ProviderId": 25,
" BookingRef ": "{{ BookingRefOne}}"
}, {
"ProviderId": 25,
" BookingRef ": "{{ BookingRefTwo}}" //Set at collection Level
}
]
I am populating the above by running the below pre request scripts and setting variables.
let bookingRefIncrement **=** pm.globals.**get** ("bookingRefIncrement")
pm.globals.**set** ("bookingRefIncrement", **+** bookingRefIncrement **+** 1)
const bookingRefIncrement **=** pm.globals.**get** ("bookingRefShortName") **+** pm.globals.**get** ("bookingRefIncrement")
pm.globals.**set** ("bookingRefIncrement", bookingRefIncrement)
pm.globals.**set** ("bookingRefOne", pm.globals.**get** ("bookingRefShortName") **+** bookingRefIncrement**++** )
pm.globals.**set** ("bookingRefIncrement", **+** bookingRefIncrement **+** 1)
pm.globals.**set** ("bookingRefTwo", pm.globals.**get** ("bookingRefShortName") **+** providerReferenceIncrement**++** )
pm.globals.**set** ("bookingRefIncrement", **+** bookingRefIncrement**+** 1)
Each time I want to add a new JSON object to the request body, I have to add these lines and manually change the references in the pre request scripts.
pm.globals.set (“bookingRefOne”, pm.globals.get (“bookingRefShortName”) + bookingRefIncrement**++** )
pm.globals.set (“bookingRefIncrement”, + bookingRefIncrement + 1)
I am not very good at this so I am surprised I got this far, is there an easy to understand way/better way to do this with a few lines of code, where the pre request script could look at the request body and inject these incrementing them for me.
For information, the booking ref is made up of static text e.g., “Booking “ + bookingRefIncrement’ so it might b Booking 1, Booking 2 and so for each object within the request body.
hope this makes sense as I don’t know how better to explain it.
If anybody could help me, or point me in the right direction that would be great.