Error when trying to parse the response body

Hi I am Also facing Same issue however i am Getting 200 ok
Even then i have error
Definitions object is present in the response | JSONError: Unexpected token β€˜<’ at 1:1 <definitions targetNamespace="urn:microsoft-dynamics-schemas/codeunit/POSTransa ^
and my test script which is Auto Generated by Postman

pm.test("Response status code is 200", function () {
  pm.response.to.have.status(200);
});


pm.test("Content-Type header is text/xml", function () {
    pm.expect(pm.response.headers.get("Content-Type")).to.include("text/xml");
});


pm.test("Definitions object is present in the response", function () {
    const responseData = pm.response.json();
    
    pm.expect(responseData.definitions).to.exist;
});

Hey @shahrukhgaffar01 :wave:

Welcome to the Postman community :postman:

As it is an XML response you would need to parse that with pm.response.text() and then assertion reference you have would need to be changed to match the XML response.

pm.test("Definitions object is present in the response", function () {
    const responseData = pm.response.json();
    
    pm.expect(responseData.definitions).to.exist;
}); 

You’re trying to parse that response as JSON so it’s throwing a JSONerror.

Hey World, How r u ?

I have tried below code and error went away

var responseText = pm.response.text()

responseText = responseText.replace('<?xml version=\'1.0\'?>','')

var jsonData = xml2Json(responseText);

var uid = jsonData.methodResponse.params.param.value.int

pm.collectionVariables.set("uid", access_token);