Getting Started with OData Queries in Microsoft Dynamics 365  - CloudFronts

Getting Started with OData Queries in Microsoft Dynamics 365 

Have you ever needed to pull data out of Dynamics 365 but didn’t know where to begin? Whether you’re building a report, wiring up a Power App, or feeding data into another system, OData is your friend. In just a few clicks, you’ll be able to write simple HTTP requests to retrieve exactly the records you want—no complex code required. 

What Is OData and Why It Matters

OData (Open Data Protocol) is a standardized way to query RESTful APIs. Microsoft Dynamics 365 exposes its entire data model via OData, so you can: 

  • Browse all your tables (entities) and fields 
  • Filter and sort records with familiar operators (e.g., equals, greater than) 
  • Pull related records in one go (e.g., contacts with parent accounts) 

This means faster development and fewer custom endpoints. 

1. Finding Your Web API Endpoint 

  1. Log into your Dynamics 365 or Power Apps environment. 
  1. Click Advanced SettingsCustomizationsDeveloper Resources
  1. Copy the Instance Web API URL, which looks like: 
https://yourorg.crm.dynamics.com/api/data/v9.2
That’s your base URL for every OData call.

2. Exploring Entities via Metadata 

Append $metadata to your base URL: 

GET https://yourorg.crm.dynamics.com/api/data/v9.2/$metadata 
You’ll get an XML file listing all entities (contacts, accounts, leads, etc.), their fields, data types, and navigation properties. Tip: press Ctrl + F to search for your entity by name. 

3. Core OData Query Options 

a. $select – Return Only What You Need 

GET https://yourorg.crm.dynamics.com/api/data/v9.2/contacts?$select=fullname,emailaddress1,jobtitle
This limits the payload to just those three fields, making responses smaller and faster. 

b. $filter – Narrow Down Your Results 

GET https://yourorg.crm.dynamics.com/api/data/v9.2//contacts?$filter=firstname eq ‘Ankit’
Operators: 
eq (equals) 
ne (not equals) 
gt / lt (greater than / less than) 
Combine with and / or : 
GET https://yourorg.crm.dynamics.com/api/data/v9.2//contacts?$filter=statecode eq 0 and jobtitle eq ‘Consultant’

c. $orderby – Sort Your Data

GET https://yourorg.crm.dynamics.com/api/data/v9.2/contacts?$orderby=createdon desc 
Newest records appear first. 

d. $top – Limit Record Count

GET https://yourorg.crm.dynamics.com/api/data/v9.2/contacts?$top=5 
Great for previews or testing. 

e. $expand – Fetch Related Records 

Example: Get each contact’s full name and its parent account name in one request: 

GET https://yourorg.crm.dynamics.com/api/data/v9.2/contacts? 
  $select=fullname,parentcustomerid 
  &$expand=parentcustomerid_account($select=name)

parentcustomerid is the lookup field 

parentcustomerid_account is the navigation property 

Nested $select limits expanded fields 

Another example: Expand opportunities with customer account info: 
GET https://yourorg.crm.dynamics.com/api/data/v9.2/opportunities?$expand=customerid_account($select=name,accountnumber)
Finding Expandable Names 
In your $metadata, look for lines like: 
<NavigationProperty Name=”parentcustomerid_account” Type=”Microsoft.Dynamics.CRM.account” /> 
Use that Name value in your $expand. 

Putting It All Together

Suppose you want all active contacts at “Contoso” and their account names: 

GET https://yourorg.crm.dynamics.com/api/data/v9.2/contacts?$filter=statecode eq 0 &$expand=parentcustomerid_account($filter=name eq ‘Contoso’; $select=name)&$select=fullname,emailaddress1 

Conclusion: 

OData might sound technical at first, but once you get the hang of it, it becomes one of the most powerful tools in your Dynamics 365 toolbox. Whether you’re building integrations, reports, or simple automations, OData gives you the flexibility to query exactly what you need—without relying on custom development. 

Start small. Open your environment, locate the Web API URL, and try your first $select or $filter query. Once you’re confident, move on to advanced options like $expand and $orderby. 

Call to Action: 

Need help designing smarter OData-based solutions or integrating with Power Platform tools? Reach out to our team today and we’ll help you build something great. 


Share Story :

SEARCH BLOGS :

FOLLOW CLOUDFRONTS BLOG :


Secured By miniOrange