I have a requirement to use Web API to query values in Dynamics 365 CRM instead of the XRMService tool kit.
The test code is below but, I keep getting an undefined error
funtcion queryxml () {
var fetch = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>"+
" <entity name='plx_alert'>"+
" <attribute name='plx_alertid' />"+
" <attribute name='plx_name' />"+
" <attribute name='createdon' />"+
" <order attribute='plx_name' descending='false' />"+
" <filter type='and'>"+
" <condition attribute='plx_alertid' operator='eq' uiname='A-2334343' uitype='plx_alert' value='{7AE13339-7CEB-E711-A950-000D3AF3E215}' />"+
" </filter>"+
" </entity>"+
"</fetch>";
console.log(fetch);
var encodedFetchXML = encodeURIComponent(fetchxml);
console.log(encodedFetchXML);
var req = new XMLHttpRequest();
req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v8.2/plx_alerts?fetchXml="+ encodedFetchXml, true);
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");
req.onreadystatechange = function() {
if (this.readyState === 4) {
req.onreadystatechange = null;
if (this.status === 200) {
var result = JSON.parse(this.response);
var plx_name = result["plx_name"];
console.log(plx_name);
alert("test me "+ plx_name);
}
else {
Xrm.Utility.alertDialog(this.statusText);
}
}
};
req.send();
}
Having used console log, I see an error saying refused to set unsafe Header content- length

How can I resolve this issue.
*This post is locked for comments
I have the same question (0)