Tests: Cannot get XML-body (got stream instead) from SOAP-request

Trying to send SOAP-request from script (Tests tab).
Script itself:

// Example with a full-fledged request
const PHP = pm.variables.get("PHP")
const postRequest = {
  url: PHP+'/my/path',
  method: 'POST',
  header: {
    'Content-Type': 'text/xml;charset=UTF-8',
    'Authorization': 'Basic qwertyqwerty'
  body: {
    mode: 'raw',
    raw: `<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:api="http://my.org.com/api">

pm.sendRequest(postRequest, (error, resp) => {
//   console.log(error ? error : xml2Json(resp));

Snippet works! I can see in console dump of a successful request-response:

POST http://host:port/path
162 ms
POST /path HTTP/1.1
Content-Type: text/xml;charset=UTF-8
Authorization: Basic qwertyqwerty
User-Agent: PostmanRuntime/7.26.8
Accept: */*
Postman-Token: b2031eb0-885a-4e28-b136-e02ecfa0ba49
Host: host:port
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
Content-Length: 486
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xmlns>

HTTP/1.1 200 OK
X-Powered-By: Servlet/2.5
Server: Sun GlassFish Enterprise Server v2.1.1
Content-Type: text/xml;charset="utf-8"
Transfer-Encoding: chunked
Date: Tue, 08 Dec 2020 10:47:27 GMT
<?xml version='1.0' encoding='UTF-8'?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"><S:Body>...</S:Body></S:Envelope>

But this part of a snippet:

    pm.sendRequest(postRequest, (error, resp) => {
    //   console.log(error ? error : xml2Json(resp));

Returns this:

What am I doing wrong?

Hi @53r93yCD,

Welcome to the community! :clap:

Looks like you did a great job at writing your xml request in a script.

However, in regards to your question, it doesnt seem like you did anything wrong at all. In this instance, the server responded to you in a Buffer byte array (stream). That doesn’t indicate something is wrong.

Rather, to make sense of the data, you can capture the response body, and convert it into raw text like so:

var responseBodyString = Buffer.from(response.json().stream.data).toString('utf-8'); // assuming encoding is utf-8

This should get you closer to something more readable.

Let us know if this works!