MSBA-342 · Lesson 2 of 12 · 22 min
OData services
▶ Video coming soon A video version of this lesson is on the way.
The second clinic began with a browser. Desmond opened a new tab, typed the address of Prudence's unified developer environment, added a forward slash and the word data, and pressed Enter. The screen filled with a long list of names in JSON: every public data entity in the application, each with the URL where it could be reached. Prudence scrolled until she found CRPumpWarranties. Desmond added that name to the address, and the twelve test warranties appeared as JSON objects. Nobody had written a line of web service code. The entity she had built in the first clinic was already a web service, because it was public.
That is the promise of OData in finance and operations apps. This clinic was about using that promise well: how requests are shaped, how programs authenticate, how security and legal entities affect what a caller sees, how to add an action to an entity, and when OData is the wrong tool. The distributor warranty feed from Prairieline Pump Supply would be the running example, because it was the first integration on the register that would use OData in production.
The OData endpoint
OData, the Open Data Protocol, is a standard for creating and consuming REST APIs over HTTP with JSON payloads. Finance and operations apps implement OData version 4. The service root is the environment URL followed by a forward slash and the word data. Under it, every entity marked Public appears as an entity set named by its public collection name. A full description of the service, with every entity, field, key, enumeration and action, is available at the metadata document under the same root. Client tools read that document to generate typed classes, which is how many .NET and Power Platform clients work.
OData maps HTTP methods to data operations. A GET request reads, a POST creates, a PATCH updates the fields sent, and a DELETE removes. To address a single record, the URL names the entity set followed by the key values in parentheses. Because most entities are company-specific, the key includes the data area, and a request that addresses one record names both the legal entity and the natural key.
Query options
Reading a whole entity set is rarely what a caller wants. OData query options, added to the URL after a question mark, narrow and shape the result. Finance and operations apps support the filter, select, expand, orderby, top, skip and count options. Each option name begins with a dollar sign in the URL, so the listings below show them in full. The filter option supports the comparison operators eq, ne, gt, ge, lt and le, the logical operators and, or and not, and arithmetic operators, but not the has or in operators. A filter with an asterisk inside a string value works as a wildcard match. Expand is supported only one level deep, which means a request can bring a related entity but not a relation of that relation.
# All active warranties for one distributor, newest first, a few fields only
GET https://cobaltridge-uat.operations.dynamics.com/data/CRPumpWarranties
?$filter=CustomerAccount eq 'C-10044' and Status eq Microsoft.Dynamics.DataEntities.CRWarrantyStatus'Active'
&$select=SerialNumber,ItemId,InstallDate,EndDate
&$orderby=InstallDate desc
&$top=50
# Count only
GET .../data/CRPumpWarranties/$count?$filter=EndDate lt 2027-01-31
# Serial numbers starting with MC-150
GET .../data/CRPumpWarranties?$filter=SerialNumber eq 'MC-150*'Enumeration values in a filter are written with their full name, the Microsoft.Dynamics.DataEntities namespace followed by the enum name and the symbol in single quotes, and only the eq and ne operators work with them. Dates are written without quotes. Strings are in single quotes. Prudence found these rules easiest to learn by trying them in the browser against her own environment, where a mistake costs nothing.
Results come back in pages. The server returns at most 10,000 records in one response; if more exist, the response includes a next link, the full URL for the next page. A well-behaved client follows next links until there are none, rather than assuming everything arrived in the first response. Desmond showed Prudence how the Prairieline portal team would do this for a nightly reconciliation of all warranties, and why a filter on a recent change date would make that reconciliation far cheaper.
Legal entities and cross-company reads
By default an OData request reads data from the caller's default company only. At Cobalt Ridge that matters, because the same integration user might call for CRCA on one request and CRUS on the next. To read across companies, the caller adds the cross-company option set to true, and then usually filters on the data area field to choose one or more companies. To write, the caller includes the data area in the body or the key. Desmond made it a rule for the register that every integration states its legal entities explicitly, rather than relying on a default company that someone might change in the user options.
# Warranties in the US company only, from an integration user whose default company is CRCA
GET .../data/CRPumpWarranties?cross-company=true&$filter=dataAreaId eq 'crus'
# Address one record by its full key
GET .../data/CRPumpWarranties(dataAreaId='crca',SerialNumber='MC-150-26-00412')Creating and updating through OData
To register a warranty, the Prairieline portal sends a POST request to the entity set with a JSON body containing the fields. The entity runs its initValue, validateWrite and mapping logic, writes the warranty table, and returns the created record, including the end date that Cobalt Ridge calculated. If validation fails, for example because the serial number was never shipped to Prairieline, the response is an error with the messages from the Infolog, which the portal can show to the installer.
POST https://cobaltridge-uat.operations.dynamics.com/data/CRPumpWarranties
Authorization: Bearer eyJ0eXAiOi...
Content-Type: application/json
{
"dataAreaId": "crca",
"SerialNumber": "MC-150-26-00412",
"ItemId": "MC-150",
"CustomerAccount": "C-10044",
"InstallDate": "2026-11-12",
"WarrantyMonths": 24
}
HTTP/1.1 201 Created
{ ..., "Status": "Active", "EndDate": "2028-11-12" }When creating records with the .NET OData client, Microsoft's documentation recommends the option that posts only the properties that were set, so the client does not send default values for every other field and accidentally overwrite defaults that the entity would have applied. PATCH requests likewise should carry only the fields that change.
OData also supports batch requests, which bundle several operations in one HTTP call. Inside a batch, operations grouped into a changeset are atomic: either all of them succeed or none of them is applied. Prairieline's portal registered pumps one at a time, so it did not need batches, but the robot integration in lesson 12 would, and Desmond flagged the feature in the register.
Authentication and the integration user
Every OData request must carry an OAuth 2.0 access token issued by Microsoft Entra ID. For a server-to-server integration, the usual pattern is the client credentials flow: the outside system has an app registration in Entra ID with a client secret or, better, a certificate; it requests a token for the environment's resource; and it sends that token in the Authorization header of each request. On its own, a token proves only that the caller is that app. To give the app rights inside finance and operations apps, an administrator registers the app's client ID on the Microsoft Entra applications page under System administration and links it to a user account in the application. Every request from the app runs as that user, with that user's roles.
This is where integration security is won or lost. Desmond created a dedicated user, CR-INT-PRAIRIELINE, with a single custom role, CR Distributor warranty integration, which held the maintain privilege for the warranty entity and nothing else. The user's default company was CRCA, and the role was scoped by organization so that it could only touch the companies Prairieline traded with. If the portal's secret ever leaked, the damage would be limited to warranty registrations. Kiri Langford added a line to the go-live checklist: rotate the integration certificate and confirm the role before cutover.
| Setting | Where | Value for the warranty feed |
|---|---|---|
| App registration | Microsoft Entra ID | Prairieline warranty portal, certificate credential |
| Client ID mapping | System administration > Setup > Microsoft Entra applications | Client ID linked to user CR-INT-PRAIRIELINE |
| Security role | Security configuration | CR Distributor warranty integration (one maintain privilege) |
| Companies | User and role assignment | Scoped to the legal entities Prairieline trades with |
| Throttling priority | Throttling priority mapping (lesson 11) | Medium |
OData actions
Sometimes an outside system needs to do more than create or update a row. The warranty portal, for example, needed a way to void a registration that an installer had entered against the wrong customer. Voiding is not a simple field change: the warranty service class checks that no claim has been paid and writes an audit entry. The OData way to expose that operation is an action, a method on the entity decorated with the SysODataActionAttribute. The first argument of the attribute is the public name of the action, and the second says whether the action is always available. Actions appear in the metadata document and are called with a POST request to the record's URL followed by the action's full name.
[SysODataActionAttribute('VoidRegistration', true)]
public void voidRegistration(str _reason)
{
CRPumpWarrantyTable warranty =
CRPumpWarrantyTable::findBySerial(this.SerialNumber, true);
CRPumpWarrantyService::voidWarranty(warranty, _reason);
}Microsoft's documentation also notes that actions added through extensions of standard entities are not currently supported. For custom entities like the warranty entity, that limit does not matter. For a standard entity, an operation like this would belong in a custom service, the subject of the next clinic.
When OData is the wrong tool
OData is synchronous and row-oriented. Each request waits for the server to finish, and each record runs through the full entity logic. That is exactly right for a portal that registers one pump at a time and wants an immediate answer. It is the wrong tool for moving fifty thousand rows every night, for which the data management framework and recurring integrations are designed, and for telling another system that something happened, for which business events are designed. Desmond added a column to the register called pattern, and for each row wrote synchronous, bulk, or event. Only two rows said synchronous.
There are practical limits too. The first OData call after the application server restarts can be slow while metadata is built, which Microsoft addresses with an option to warm the metadata cache at startup. Array fields are not supported in entities. Enum and entity names that collide can break client code generation. And because OData requests share web server resources with people using the browser, heavy OData traffic is subject to the service protection limits and throttling covered in lesson 11.
Testing requests before anyone writes a client
Desmond's next habit was to test every OData request by hand before the outside team wrote a line of code. The browser is enough for GET requests against an environment where the tester is signed in, because the browser session supplies the token. For POST, PATCH and DELETE, and for testing as the integration user rather than as a developer, a REST client such as Postman or the REST Client extension in Visual Studio Code is the usual tool. Prudence set one up with an environment file holding the tenant, the environment URL, the client ID and a certificate reference, and a collection of requests for the warranty entity: list, filter, read one, create, update and void. The collection went into the Azure Repos repository beside the entity, so that anyone could reproduce the tests later.
Testing as the integration user found two problems that testing as a developer would have hidden. The first request returned an empty list, not because the entity was broken but because the integration user's default company was still DAT, the demo default, rather than CRCA. The second returned a privilege error when the role was first assigned, because the role had the view privilege but not maintain. Both took minutes to fix in the sandbox and would have taken days to diagnose in production with an outside team on the phone.
Designing entities for OData callers
An entity that will be called through OData deserves a few design choices beyond those in the first clinic. Keep the field list focused: every field in the entity is read from the database on every request unless the caller uses the select option, so a lean entity is a faster entity. Prefer outer joins only where the related data may be missing; inner joins silently hide rows whose related record does not exist. Avoid virtual fields that run expensive X++ in postLoad, because OData reads call postLoad once per row. And think about the caller's filters: if a portal will always filter by customer account and install date, there should be an index on the warranty table that starts with those fields.
Naming matters too. The public entity name and collection name become part of another company's code, so they should be stable, descriptive and free of prefixes that mean nothing outside Cobalt Ridge. Desmond allowed the CR prefix in public names because the register showed that every custom entity would carry it, and a consistent prefix made Cobalt Ridge entities easy to find in a metadata document of several thousand entries. Field names, likewise, should be the business names the outside team will recognize, such as InstallDate rather than CRInstDt.
Finally, he reminded Prudence that an entity used by OData is also used by every other consumer in the first clinic's figure. A field added for one portal shows up in Excel, in data management templates and, if the entity is later enabled in Dataverse, in virtual tables. That is a reason to keep entities general and well named, and a reason to version carefully: adding a field is safe, but renaming or removing one breaks every caller at once.
Worked problem
Reading the right page of data
The Prairieline team writes a nightly job that reads all warranties for its customers to reconcile its own records. In testing, the job receives exactly 10,000 records and stops, although the CONFIG sandbox has more. What is wrong, and how should the job be changed?
Show solution
- A response of exactly 10,000 records is a sign of server-driven paging: the server returned one full page.
- The response contains a next link with the URL of the following page.
- The job must loop, following each next link until a response arrives without one.
- Better still, the job should filter on records changed since its last run, so that it reads a few hundred rows instead of every warranty every night.
Answer: The job ignored paging. Follow next links until none remains, and filter on recent changes to reduce the load.
Common mistakes
MistakeRelying on the integration user's default company.
InsteadName the legal entity in every write and use cross-company reads with a data area filter.
MistakeGiving the integration user the System administrator role to make errors go away.
InsteadCreate a narrow role with only the entity privileges the integration needs.
MistakeUsing OData to export tens of thousands of rows every night.
InsteadUse the data management framework or a recurring integration for bulk data.
MistakeTreating the first page of results as the complete answer.
InsteadFollow next links until no more are returned.
Summary and key terms
- Every public data entity is available through the OData version 4 endpoint under the data service root.
- Query options filter, select, expand one level, sort and page the results; pages hold at most 10,000 records.
- Reads return the default company unless cross-company is set; writes should always name the legal entity.
- Programs authenticate with Microsoft Entra ID tokens; the client ID maps to a user whose roles decide what the program can do.
- OData actions expose operations on custom entities; OData suits synchronous, row-by-row work, not bulk loads.
- OData
- The Open Data Protocol, a REST standard that finance and operations apps implement in version 4 for data entities.
- Entity set
- The collection of records of one public entity, addressed by its public collection name.
- Query option
- A URL parameter such as filter, select or top that shapes an OData result.
- Cross-company
- An OData option that returns data from every company the caller can access.
- OData action
- An entity method exposed to OData with the SysODataActionAttribute.
- Changeset
- A group of operations in an OData batch that succeed or fail together.
- Integration user
- An application user mapped to an app registration, whose roles decide what the integration can do.
Practice problems
Work each problem on paper first, then reveal the answer to check.
What two things must exist before a program with a valid Entra ID token can read warranties?
Show answer
The client ID must be registered on the Microsoft Entra applications page and mapped to a user, and that user must hold a role with the view or maintain privilege for the entity.
Which filter operators cannot be used with an enumeration value?
Show answer
Everything except eq and ne.
Why does Desmond expose voiding as an action instead of letting the portal PATCH the status to Void?
Show answer
Voiding runs service logic (claim check, audit entry) that a field update would bypass or make harder to control.
Lesson quiz · 5 questions
Score 60% or more to complete this lesson.
Create a free account to save your progress, take quizzes and earn a certificate.