简体   繁体   中英

How to check the content of a POST method in Postman?

I am testing an API that after a trigger will make a POST method in the server and I want to guarantee that the request body has all the mandatory fields.

I can't find the correct solution yet that how to point to the request body.

It would be good if there is a way to check that the request is a valid Json, and then check each field of the Json(Name, Sex, etc).

Request Body:

{
  "requestId": "ok01",
  "parentRequestId": "some text",
  "formType": "some text",
  "sourceURL": "some text",
  "documentType": "some text",
  "documentNumber": "some text",
  "phoneType": "some text",
  "phoneArea": "some text",
  "phoneNumber": "some text",
  "name": "some text",
  "customerId": "some text",
  "email": "some text",
  "locationName": "some text",
  "currentAddress": "some text",
  "newAddress": "some text",
  "descriptions": "some text",
  "creationDate": "some text",
  "geoLocation": "some text",
  "ipsourceFibertel": "some text",
  "userId": "some text",
  "retries": "some text",
  "productList": [
    {
      "products": "some text"
    },
    {
      "products": "some text"
    }
  ]
}

Response body:

{
"OK"
}
// I tried like this, but it didnt work
pm.test("Check field 'requestId'", function () {
   pm.requestBody.have.jsonBody("requestId");
}); 

Not sure what your overall goal is here but if you wanted to check that the requestId property was used in the Request Body , you could do this:

pm.test("Check the request data", function () {
    pm.expect(JSON.parse(pm.request.body.raw)).to.have.property('requestId');
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM