How can I Validate Request Body Key and Value parameters that is in Form-data format

I would really appreciate, if you can go through Postman’s learning center and check about writing test script.

Now since our data is in variable map and mapValue, there is no point in passing data.form.body :sweat_smile:

The code will look something like this

var data = pm.request.body
var myReq = data.formdata

var map = myReq.reduce((r, i) => ((r[i.key] = r[i.key] || []).push(i), r), {});
var mapValue = myReq.reduce((r, i) => ((r[i.value] = r[i.value] || []).push(i), r), {});

pm.test("Request body to have form Data key", function () {
    pm.expect(mapValue.client_credentials[0].value).to.be.a("string").and.is.not.null.and.to.not.be.undefined.and.is.not.empty
});

pm.test("Request body to have form Data value", function () {
    pm.expect(mapValue.default[0].value).to.be.a("string").and.is.not.null
});

As I said, it will be great help if you can research a bit more (solutions are all around) :stuck_out_tongue: :smiley:

Cheers :magic_wand:

Thank you so much… I went through so may threads and tried but was really struggling.

No worries :grin: I hope this worked for you.