I am trying to fetch a XML document in Wix Velo JS Backend, but I have the: “Error: Converting circular structure to JSON”. I use the following code to read the XML:
export const get_branches_func = webMethod(Permissions.Anyone, (token) =>
{
....
return fetch('https://webservices.vebra.com/export/'+datafeedid+'/v12/branch', {
'method': 'get',
'headers': {
'Authorization': AuthHeader
},
})
.then((httpResponse) => {
if (httpResponse.ok) {
//return httpResponse.json();
console.log("Response OK: ", httpResponse);
return (httpResponse.text());
}
})
.then(xmlText => {
const parser = new DOMParser();
const xmlDoc = parser.parseFromString(xmlText,
'text/xml');
// Now you can work with the parsed XML document
console.log("xmlDoc:", xmlDoc)
return (xmlDoc);
}
);}
)
Branch_response.txt is the successful response from the fetch (httpResponse): https://1drv.ms/t/s!AvYtCyRV-nEPg4sNE2lvb2OIw701Aw?e=T7EUCz
xmlDoc.txt is the xmlDoc parsed: https://1drv.ms/t/s!AvYtCyRV-nEPg4sOqUZ9Ml4XAhAO6g?e=fvD0pf
I expect to see a readable XML with branches information as per API.
var xmlDoc = parser.parseFromString(xmlText,"application/xml");
solved the problem for me. Thanks