Reading values from the "Body" and setting environment variables


I am trying to ready values from the BODY and a json request (no the response) and then set it in a variable. I can successfully do it the response body but not the request body.

Its a post request


  "PolicyDN": "\\VED\\Policy\\Demo\\APIs\\Certificates",
  "ObjectName": "",
  "Subject": "",
  "SubjectAltNames": [
      "TypeName": "DNS",
      "Name": ""
      "TypeName": "DNS",
      "Name": ""

Tests Tab

tests[""] = !(responseBody.has(“Error”));
var data = JSON.parse(responseBody);
postman.setEnvironmentVariable(“Cert_DN”, data.CertificateDN.replace(/\/g,"\$&"));
postman.setEnvironmentVariable(“GUID”, data.Guid);

Tyring to add something for the "Request Value in the request body. Something like this (This does not work)

var mydata = JSON.parse(requestBody);
postman.setEnvironmentVariable(“Subject”, mydata.Subject);

I am sure the solution/syntax is easy. Just not sure how to do it.

Any help would be greatly appreciated.

Hey @Jmeldrum

Are you trying to set a variable from the request body? I’m unsure of the reason for doing this.

Would you be able to explain your use case a little bit more to help provide context and allow us to get to a solution quicker?