Steps to Run

To execute the script please follow the below mentioned steps:

  1. Click on the plus icon to create a new API request enter the URL of the API in the box and select the post request.
  2. Click on body then select raw and change the text to Json.
  3. Enter the data in the body as Json and also go to Pre-request script and write your script then just hit on send.
  4. Go to postman console and search for visualize tab open it you can see the output in it.

Output:

The two pictures below depict different outputs one when the user has missed the parameters entered, and the other when the user has entered all the parameters.

Missed required parameters

Entered all parameters

How to validate POST request body required params in Pre-request script?

APIs are a set of rules and protocols that allow different software applications to communicate and exchange data with each other, so it is important to test these APIs for their reliability by doing so-called API testing. API testing or application programming interface testing is a type of software testing that verifies the functionality, reliability, performance, and security of the API’s. There are different API requests like(POST, DELETE, GET, PUT, Etc..) in some requests like POST we have to pass the data as JSON and it is common that we will miss some required parameters especially if the parameters are huge. So in order to validate it we can make use of Pre-request scripts let’s explore in this article how we can validate the POST request body required params in a Pre-request script.

Similar Reads

What is a Pre-request Script?

The pre-request script is a piece of JavaScript code that will be executed even before the API request....

Approach

Follow the steps below to validate a post-request body required parameters in the Pre-request script:...

Steps to Run

...

Conclusion

To execute the script please follow the below mentioned steps:...