M.Abulsoud
M.Abulsoud

Reputation: 999

Request URL Too Long for fetchXml query types

I'm using CRM 2016 web api with fetchxml query parameter, but my query is too long it's simulate the IN operator were the number of parameters passed in the IN list are 300 elements and some times will be more than that.

So my problem is the query are too big for a GET HTTP Request. I have tried to send the query in the http message body but that didn't work so what is the solution for this problem?

Here's a code snippet of the fetchxml query that I used:

<fetch mapping="logical" distinct="true">
   <entity name="entity">
      <attribute name="new_classopportunityid" />
      <attribute name="new_trainingproduct" />
      <attribute name="new_gtgstatus" />
      <attribute name="new_scheduledstartdate" />
      <attribute name="new_scheduledenddate" />
      <attribute name="new_remainingnumberofseats" />
      <attribute name="new_liveclassroom" />
      <attribute name="new_maxlive" />
      <attribute name="new_xavieruniversity" />
      <attribute name="new_partnerlive" />
      <attribute name="new_blended" />
      <filter>
         <condition attribute="new_classopportunityid" operator="in">
            <value>001943ea-e263-e611-8158-00155d002810</value>
            <value>0071e4ea-bd9b-e611-8163-00155d002810</value>
            <value>00c32774-1c8f-e611-8161-00155d002810</value>
            <value>00d513fa-f0bb-e611-8169-00155d002810</value>
            <value>....</value>
            <value>....</value>
            <value>....</value>
         </condition>
      </filter>
   </entity>
</fetch>

The CRM web api endpoint that I request is :

 GET http://<org>/api/data/v8.0/<entity>?fetchXml=<fetch mapping="logical" distinct="true">
       <entity name="entity">
          <attribute name="new_classopportunityid" />
          <attribute name="new_trainingproduct" />
          <attribute name="new_gtgstatus" />
          <attribute name="new_scheduledstartdate" />
          <attribute name="new_scheduledenddate" />
          <attribute name="new_remainingnumberofseats" />
          <attribute name="new_liveclassroom" />
          <attribute name="new_maxlive" />
          <attribute name="new_xavieruniversity" />
          <attribute name="new_partnerlive" />
          <attribute name="new_blended" />
          <filter>
             <condition attribute="new_classopportunityid" operator="in">
                <value>001943ea-e263-e611-8158-00155d002810</value>
                <value>0071e4ea-bd9b-e611-8163-00155d002810</value>
                <value>00c32774-1c8f-e611-8161-00155d002810</value>
                <value>00d513fa-f0bb-e611-8169-00155d002810</value>
                <value>....</value>
                <value>....</value>
                <value>....</value>
             </condition>
          </filter>
       </entity>
    </fetch>

This is the response I got from the api.

Error code: 414: HTTP/1.1 414 Request-URI Too Long  Response :  "<!DOCTYPE HTML PUBLIC \"-\/\/W3C\/\/DTD HTML 4.01\/\/EN\"\"http:\/\/www.w3.org\/TR\/html4\/strict.dtd\">\r\n<HTML><HEAD><TITLE>Request URL Too Long<\/TITLE>\r\n<META HTTP-EQUIV=\"Content-Type\" Content=\"text\/html; charset=us-ascii\"><\/HEAD>\r\n<BODY><h2>Request URL Too Long<\/h2>\r\n<hr><p>HTTP Error 414. The request URL is too long.<\/p>\r\n<\/BODY><\/HTML>\r\n" [] []

Upvotes: 3

Views: 2520

Answers (2)

Daryl
Daryl

Reputation: 18895

You'll need to use a Post, not a Get:

https://dreamingincrm.com/2017/01/15/executing-large-fetchxml-with-webapi/

Upvotes: 3

Josh Painter
Josh Painter

Reputation: 4111

Using the "in" operator with a big list of ids is probably not the best way to query, as you've seen. It would be better if you could filter on an attribute of the new_classopportunity entity by using a link-entity, like this:

<fetch mapping="logical" distinct="true" >
  <entity name="entity" >
    <!-- ... all your attributes ... -->
    <link-entity name="new_classopportunity" from="new_classopportunityid" to="new_classopportunityid" >
      <attribute name="new_name" />
      <filter>
        <condition attribute="statecode" operator="eq" value="0" />
      </filter>
    </link-entity>
  </entity>
</fetch>

Notice you can pull in attributes from the link-entity as well. In this case I'm pulling in name and using a filter to only get new_classopportunity records that are active.

If you don't have a field on new_classopportunity that you can filter on to get the same list, add one! :)

Upvotes: 1

Related Questions