Problem Statement 

If you execute long fetchXml request using GET method of WebAPI, then you will receive 404 – File or directory not found the error message.

404-error

Steps To Reproduce

  1. Go to Advanced find.
  2. Select Account entity.
  3. Click on edit columns.
  4. Click on add columns and select all columns from the list.
  5. Click on OK and download the fetchXml or use below fetchXml as an example.
  6. Open the new window and enter data in the following format.organization-url/api/data/v9.0/accounts?fetchXml=[enter fetchxml without brackets]
  7. You will get server error 404. You will received same error in JS code executing fetchXml GET request using WebAPI.
<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">
<entity name="account">
<attribute name="name" />
<attribute name="primarycontactid" />
<attribute name="telephone1" />
<attribute name="accountid" />
<attribute name="yominame" />
<attribute name="websiteurl" />
<attribute name="timespentbymeonemailandmeetings" />
<attribute name="tickersymbol" />
<attribute name="territorycode" />
<attribute name="territoryid" />
<attribute name="telephone3" />
<attribute name="stockexchange" />
<attribute name="statuscode" />
<attribute name="statecode" />
<attribute name="slaid" />
<attribute name="sic" />
<attribute name="shippingmethodcode" />
<attribute name="sharesoutstanding" />
<attribute name="donotsendmm" />
<attribute name="customertypecode" />
<attribute name="overriddencreatedon" />
<attribute name="stageid" />
<attribute name="processid" />
<attribute name="primarytwitterid" />
<attribute name="primarysatoriid" />
<attribute name="defaultpricelevelid" />
<attribute name="preferredsystemuserid" />
<attribute name="preferredappointmenttimecode" />
<attribute name="preferredserviceid" />
<attribute name="preferredcontactmethodcode" />
<attribute name="preferredequipmentid" />
<attribute name="preferredappointmentdaycode" />
<attribute name="paymenttermscode" />
<attribute name="parentaccountid" />
<attribute name="ownershipcode" />
<attribute name="ownerid" />
<attribute name="telephone2" />
<attribute name="originatingleadid" />
<attribute name="openrevenue_base" />
<attribute name="openrevenue" />
<attribute name="opendeals" />
<attribute name="onholdtime" />
<attribute name="numberofemployees" />
<attribute name="modifiedon" />
<attribute name="modifiedbyexternalparty" />
<attribute name="modifiedonbehalfby" />
<attribute name="modifiedby" />
<attribute name="marketingonly" />
<attribute name="marketcap_base" />
<attribute name="marketcap" />
<attribute name="lastonholdtime" />
<attribute name="lastusedincampaign" />
<attribute name="industrycode" />
<attribute name="ftpsiteurl" />
<attribute name="followemail" />
<attribute name="fax" />
<attribute name="exchangerate" />
<attribute name="emailaddress3" />
<attribute name="emailaddress2" />
<attribute name="emailaddress1" />
<attribute name="donotphone" />
<attribute name="donotpostalmail" />
<attribute name="donotfax" />
<attribute name="donotemail" />
<attribute name="donotbulkpostalmail" />
<attribute name="donotbulkemail" />
<attribute name="description" />
<attribute name="customersizecode" />
<attribute name="transactioncurrencyid" />
<attribute name="creditlimit_base" />
<attribute name="creditlimit" />
<attribute name="creditonhold" />
<attribute name="createdon" />
<attribute name="createdbyexternalparty" />
<attribute name="createdonbehalfby" />
<attribute name="createdby" />
<attribute name="accountclassificationcode" />
<attribute name="accountcategorycode" />
<attribute name="businesstypecode" />
<attribute name="revenue_base" />
<attribute name="revenue" />
<attribute name="aging90_base" />
<attribute name="aging90" />
<attribute name="aging60_base" />
<attribute name="aging60" />
<attribute name="aging30_base" />
<attribute name="aging30" />
<attribute name="address1_telephone1" />
<attribute name="address2_postalcode" />
<attribute name="address2_utcoffset" />
<attribute name="address2_upszone" />
<attribute name="address2_telephone3" />
<attribute name="address2_telephone2" />
<attribute name="address2_telephone1" />
<attribute name="address2_line3" />
<attribute name="address2_line2" />
<attribute name="address2_line1" />
<attribute name="address2_stateorprovince" />
<attribute name="address2_shippingmethodcode" />
<attribute name="address2_primarycontactname" />
<attribute name="address2_postofficebox" />
<attribute name="address2_name" />
<attribute name="address2_longitude" />
<attribute name="address2_latitude" />
<attribute name="address2_freighttermscode" />
<attribute name="address2_fax" />
<attribute name="address2_county" />
<attribute name="address2_country" />
<attribute name="address2_city" />
<attribute name="address2_addresstypecode" />
<attribute name="address2_composite" />
<attribute name="address1_postalcode" />
<attribute name="address1_utcoffset" />
<attribute name="address1_upszone" />
<attribute name="address1_telephone3" />
<attribute name="address1_telephone2" />
<attribute name="address1_line3" />
<attribute name="address1_line2" />
<attribute name="address1_line1" />
<attribute name="address1_stateorprovince" />
<attribute name="address1_shippingmethodcode" />
<attribute name="address1_primarycontactname" />
<attribute name="address1_postofficebox" />
<attribute name="address1_name" />
<attribute name="address1_longitude" />
<attribute name="address1_latitude" />
<attribute name="address1_freighttermscode" />
<attribute name="address1_fax" />
<attribute name="address1_county" />
<attribute name="address1_country" />
<attribute name="address1_city" />
<attribute name="address1_addresstypecode" />
<attribute name="address1_composite" />
<attribute name="accountratingcode" />
<attribute name="accountnumber" />
<order attribute="name" descending="false" />
</entity>
</fetch>

Resolution

GET request will support only 2048 characters. To handle large fetchXml request kindly use Batch request of the WebAPI.

Learn how to create batch request

https://community.dynamics.com/crm/b/scaleablesolutionsblog/archive/2017/04/11/web-api-bulk-operations

https://msdn.microsoft.com/en-in/library/mt607719.aspx

To parse the batch response.


function parseBatch (responseCollection) {
 var boundary = '--batchresponse_';
 var items = [];
 var responseLines = responseCollection.split(boundary);
 $.each(responseLines, function (index, value) {

var startJson = value.indexOf('{');
 var endJson = value.lastIndexOf('}');
 if (startJson &amp;amp;amp;amp;amp;lt; 0 || endJson &amp;amp;amp;amp;amp;lt; 0) {
 return;
 }
 var responseJson = value.substr(startJson, (endJson - startJson) + 1);
 responseJson = JSON.parse(responseJson);
 items.push(responseJson);

});
 return items;
 },