title: Unable to access XML response in Postman pre-request script
body: <p>I'm having trouble extracting the xml respose from within the Postman pre-request script. My pre-request looks like the following:</p>
  
  <pre><code>pm.sendRequest({
     url: "https://login.salesforce.com/services/Soap/u/40.0",
     method: 'POST',
     header: {
         'soapaction': "Required", 
         'Content-Type': 'text/xml',
     },
     body: {
         mode: 'raw',
         raw: "&lt;se:Envelope xmlns:se=\"http://schemas.xmlsoap.org/soap/envelope/\"&gt; \
                  &lt;se:Header/&gt; \
                  &lt;se:Body&gt; \
                      &lt;login xmlns=\"urn:partner.soap.sforce.com\"&gt; \
                          &lt;username&gt;user&lt;/username&gt; \
                          &lt;password&gt;password&lt;/password&gt; \
                      &lt;/login&gt; \
                  &lt;/se:Body&gt; \
              &lt;/se:Envelope&gt;"
     }
  }, function (err, responseBody) {
      console.log(pm.request.body);
      var xmlTree = xml2Json(responseBody);
      console.log(xmlTree);
      console.log("sessionid: " + xmlTree['soapenv:Envelope']['soapenv:Body'].loginResponse.result.sessionId);
      //pm.environment.set("sys_id", response.json().result.sys_id);
      postman.setEnvironmentVariable("sessionid", xmlTree['soapenv:Envelope']['soapenv:Body'].loginResponse.result.sessionId);
  });
  </code></pre>
  
  <p>When i look at the response in the Postman console i see the correct response however when i try to access it via "pm.request.body" or simply the "responseBody" i get an empty/null value. </p>
  
  <p>Below is the response i see and also note when i output to log it's empty:</p>
  
  <p><a href="https://i.stack.imgur.com/M1P87.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/M1P87.jpg" alt="enter image description here"></a></p>
  
  <p>Any thoughts? </p>
  
  <p>Additionally, I'm able to do the exact same thing with a url that responds with JSON payload and using the same method i'm able to extract the response and work with the values. Does anyone know if there's something different about XML responses? Or if they should be handled differently? </p>