Fetch the total number of elements in dynamics web api using oData query

How do i just fetch the number of accounts created after a given date using the dynamics 365 web apis...
The normal way to do this would be https://directi123.crm8.dynamics.com/api/data/v9.0/accounts/?$filter=createdon gt 2017-04-01&$count=true
But the problem with this is it returns all the data. I only need the count.. And dont need any of the data...I can although restrict it to just one element by specifying $select...
Is there any way to use the filter element also and to just get the total count...

Rohit BajajAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Chinmay PatelChief Technical NinjaCommented:
Hi Rohit,

Personally, I am not a big fan of WebAPI end point just yet (I use them in most of my engagements nowadays that's a different story and maybe I am biased towards FetchXML as it was my go to solution for more than a decade) so I have a combined solution that uses both FetchXML and WebAPI.

Take this fetch xml definition and modify it as per your requirements
<fetch distinct='false' mapping='logical' aggregate='true'> 
    <entity name='account'> 
       <attribute name='name' alias='count' aggregate='count'/> 
<filter type="and">
      <condition attribute="createdon" operator="on-or-after" value="YOURDATEHERE" />

Open in new window

UrlEncode the above XML

And then execute it using

Open in new window

Let me know how it goes.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Chinmay PatelChief Technical NinjaCommented:
Author has not come back with the comment. The solution given works and gets desired results.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Dynamics

From novice to tech pro — start learning today.