How can I create a dynamic requestbody using a pre-requisite script?

I want to create a dynamic requestbody through a pre-requisite script. I want that script to extract the headers from the csv datafile and add them to the requestbody. I want to do this so that my code can be as reusable a possible.

My csv:

organization,user,user,car7,“["“JVBERi0xLjQKlJUVPRgo="”]”,“{"“title"”:"“files"”}”,“{"“meta_owner_reference"”:"“11"”,"“meta_owner_name"”:"“username"”,"“meta_owner_email"”:"“"”,"“meta_owner_phone_number"”:"”+961 71 123456"“}”,INVALID ORGANIZATION INPUT

i want to write the body like this:

Instead of writing it manually like this:

Hey @sergeasmar :wave:

Welcome to the Postman community! :postman:

You could make use of the this technique described by @vdespa in his video:

That would allow you to create the body the in the pre-request script and use that as the payload. You can you the pm.iterationData.get('header_name') function in the dynamic request body to get those values from the data file.

There was also this from @odanylewycz that might be useful too:

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.