0

For the post request I have this knid of body

{
    "callbackUrl": "http://test.io",
    "secret": "ygc28gc2VjcmV0"
}

I want to verify does the body has all requied fields such as callbackUrl and secret.

How do I check it in Pre-req script and assert it. And don't send the request?

Masi Boo
  • 635
  • 1
  • 10
  • 24

1 Answers1

0
const requestBody = JSON.parse(pm.request.body.raw);
const requiredFields = ['callbackUrl', 'secret'];

requiredFields.forEach(field => {
    if (!requestBody.hasOwnProperty(field)) {
        throw new Error(`Missing ${field} field in the request body`);
    }
});
Masi Boo
  • 635
  • 1
  • 10
  • 24