Assignment in conditional expression


I have an error “assignment in conditional expression” that I tried Googling for hours last night and hope I can get some help.

I am trying to get the nonce out of an XML response. Below is the original responseBody.

Response Body:

<?xml version='1.0' encoding='UTF-8'?><soapenv:Envelope xmlns:soapenv="link"><soapenv:Body><processOCIMessageResponse xmlns="urn:com:broadsoft:webservice" xmlns:ns="urn:com:broadsoft:webservice"><processOCIMessageReturn>&lt;?xml version="1.0" encoding="ISO-8859-1"?>&lt;BroadsoftDocument protocol="OCI" xmlns="C" xmlns:xsi="link">&lt;sessionId xmlns="">33&lt;/sessionId>&lt;command echo="" xsi:type="AuthenticationResponse" xmlns="">&lt;userId>bryankowalczyk&lt;/userId>&lt;nonce>1557585660073&lt;/nonce>&lt;passwordAlgorithm>MD5&lt;/passwordAlgorithm>&lt;/command>&lt;/BroadsoftDocument></processOCIMessageReturn></processOCIMessageResponse></soapenv:Body></soapenv:Envelope>

Even after performing xm2json in the Postman, I don’t get a properly formatted JSON converting the XML to key:value pairs. It still remains a string

<?xml version="1.0" encoding="ISO-8859-1"?> <BroadsoftDocument protocol="OCI" xmlns="C" xmlns:xsi="link"><sessionId xmlns="">33</sessionId><command echo="" xsi:type="AuthenticationResponse" xmlns=""><userId>bryankowalczyk</userId><nonce>1557585660073</nonce><passwordAlgorithm>MD5</passwordAlgorithm></command></BroadsoftDocument>

I tried using a regex to extract the nonce which does work successfully using Node outside of Postman but I get an error “assignment in conditional expression” in Postman when trying to execute it.

The code I am using in the tests section in Postman is as follows:

var responseJson = xml2Json(responseBody);
var re = new RegExp("<nonce>(.*?)</nonce?>", "gmi");
while (res = re.exec(responseBody)){ console.log(res[1])}

It struggles with the ‘while’ command. Any thoughts on how I can extract this value cleanly?

I appreciate it!

P.S. I had to remove ‘http’ from the XML as I am limited to links I can post.

Hey @klysdale,

Welcome to the community :wave:

I have to be honest, I know very little about XML responses and using the xml2Json module in Postman but I was able to extract that value from your sample response.

I used the following code in the Tests tab to move down through the response body to get to the value. It’s not the cleanest or most efficient way of accessing the value but hopefully, it gives you a starting point.

let responseJson = xml2Json(pm.response.text());
let nonceId = responseJson['soapenv:Envelope']['soapenv:Body'].processOCIMessageResponse.processOCIMessageReturn.BroadsoftDocument.command.nonce;

pm.globals.set('nonceId', nonceId)

I did find that the response that you posted had several encoded &lt;characters, which would be the < character. Once I manually changed these, the response body was no longer a string. I’m not sure if that was just a formatting issue with copying and pasting or some actual issue from the response on the live service.