MSBA-273 · Lesson 1 of 12 · 25 min
Dataverse Web API
▶ Video coming soon A video version of this lesson is on the way.
Signe Tavernier-Mbeki's developer design reviews had covered the inside of Dataverse: the event pipeline, plug-ins, custom APIs and the solutions that carry them. The questions arriving in central IT during the second half of fall term were about the outside. Kwabena Asante-Lowe's reporting team wanted a reliable way to pull completed work orders into their tools. The Facilities team wanted building management alarms to reach the work-order system without anyone retyping them. Ysaline Dabrowski, the accounts payable supervisor, wanted to know whether supplier and invoice information could move between the Facilities Work Orders solution and LedgerPoint, the college's finance system, without the weekly spreadsheet exchange. Rupert Ellingsworth asked Signe and Wiremu Quaresma to run a second series of sessions on integration, and to treat every answer as a design that could be reviewed, not a promise that anything would be built.
Wiremu, who had come to Lumenvale from a web agency, was comfortable with REST services and JSON. He asked to start with the one interface every other integration eventually touches: the Dataverse Web API. This course assumes the extension work covered in Extending the User Experience and Extending the Platform: Plug-ins, Custom APIs and Connectors, and looks outward from Dataverse to other systems. The Microsoft AB-400 exam, which replaced PL-400 in October 2026, gives integrations about 10 to 15 percent of its weight, and the skills in this course sit mostly in that domain.
What the Web API is
The Dataverse Web API is an HTTP interface that follows the OData version 4 standard. Any program that can send HTTPS requests and read JSON can use it: a JavaScript single-page app, a Node service, a C# Azure Function, a Java batch job on a Linux server or a tool such as Postman or Insomnia. Requests act on resources identified by URLs, use the standard HTTP methods, and return JSON bodies and standard status codes. Because the API is described by a metadata document, many tools can read the description and help build requests.
The current version of the endpoint is 9.2. The service root URL combines the environment URL with the API path and version, for example https://lumenvale.crm3.dynamics.com/api/data/v9.2/. The environment URL is shown on the Developer resources page in Power Apps and in the environment's details in the Power Platform admin centre, so nobody needs to guess it. Every resource the API exposes sits under that root.
The Web API and the SDK for .NET
Dataverse offers two programming interfaces over the same operations. The Web API is the language-neutral HTTP interface. The SDK for .NET wraps the same platform messages in .NET classes. In a .NET client application the current choice is the ServiceClient class in the Microsoft.PowerPlatform.Dataverse.Client package, which handles sign-in, token refresh and some retry behaviour for you. The older organization service proxy classes are deprecated, and new code should not use them. Inside plug-ins the situation is different: a plug-in receives an IOrganizationService from the execution context and must use it rather than calling the Web API over HTTP, because an HTTP call from inside the sandbox would go back through the front door, outside the transaction, and count again against the limits.
| Question | Web API | SDK for .NET |
|---|---|---|
| Languages | Any language that sends HTTPS and reads JSON | .NET languages such as C# |
| Typical callers | Single-page apps, Azure Functions in any language, scripts, other platforms | .NET services, console tools, plug-ins, Azure Functions in C# |
| Authentication | You acquire an OAuth token and send it in the Authorization header | ServiceClient acquires and refreshes the token from a connection string or token provider |
| Inside a plug-in | Not used | Use the IOrganizationService from the execution context |
| Operations available | All platform messages, as OData resources, functions and actions | All platform messages, as request and response classes |
Signe's rule of thumb for Lumenvale was simple. Code written in C# uses ServiceClient. Code written in anything else, and anything that has to be explained to a partner whose platform Lumenvale does not control, uses the Web API. Both reach the same tables, the same security model and the same event pipeline, so a plug-in registered on a table fires whichever interface the caller uses.
Resources, names and metadata
Tables appear in the Web API as entity sets. The entity set name is usually the plural of the table's logical name, so the account table is accounts and Lumenvale's work order table, with the logical name lcc_workorder, is lcc_workorders. Columns appear as properties named by their logical names, all in lower case. A lookup column appears twice: as a navigation property used to bind and expand the related row, and as a read-only property whose name starts with an underscore and ends with _value, holding the related row's identifier.
The service document at the root lists every entity set. The metadata document, reached by adding the metadata segment to the service root as shown in the next listings, describes every entity type, property, relationship, function and action in the environment in the Common Schema Definition Language. It is large, because it includes every table, but it is the authoritative description. Wiremu used it to check names instead of guessing them from display names in the maker portal, which is the most common source of 404 and 400 errors for people new to the API.
GET https://lumenvale.crm3.dynamics.com/api/data/v9.2/lcc_workorders?$select=lcc_name,lcc_status,createdon&$filter=lcc_status eq 3 and createdon ge 2026-11-01&$orderby=createdon desc&$top=10
Authorization: Bearer <access token>
Accept: application/json
OData-MaxVersion: 4.0
OData-Version: 4.0
Prefer: odata.include-annotations="OData.Community.Display.V1.FormattedValue"Querying data
Read requests use GET and OData query options. The select option names the columns to return; always use it, because a request without it returns every column, which wastes bandwidth and makes the response depend on columns added later. The filter option takes conditions with operators such as eq, ne, gt, ge, lt and le, joined with and, or and not, and functions such as contains and startswith. The orderby option sorts, and the top option limits the number of rows. The expand option brings related rows into the same response: a single-valued navigation property such as the work order's building, or a collection such as a building's rooms, each with its own nested select.
Dataverse adds query functions that OData does not define, such as functions for relative dates and for checking whether a row is above or under another in a hierarchy. When a query is easier to write in FetchXML, the query language used by views and advanced find, the Web API accepts it as the fetchXml parameter on the entity set, URL-encoded. Wiremu found that some aggregate queries were easier in FetchXML; Signe preferred OData for anything a partner would read.
Choice columns return their integer value. To get the label the user sees, the caller asks for formatted values with the Prefer header shown in Listing 1.1, and each choice, lookup, date and money column then carries an annotation with its display text in the user's language. Kwabena's team had been mapping status numbers to labels in their reports by hand; the annotation removed a lookup table that had drifted out of date when the Facilities team added a status.
HTTP/1.1 200 OK
Content-Type: application/json; odata.metadata=minimal
Preference-Applied: odata.include-annotations="OData.Community.Display.V1.FormattedValue"
{
"@odata.context": "https://lumenvale.crm3.dynamics.com/api/data/v9.2/$metadata#lcc_workorders(lcc_name,lcc_status,createdon)",
"value": [
{
"@odata.etag": "W/\"48213077\"",
"lcc_name": "WO-24107",
"lcc_status": 3,
"lcc_status@OData.Community.Display.V1.FormattedValue": "Completed",
"createdon": "2026-11-18T15:42:10Z",
"lcc_workorderid": "6f1c2b0e-0000-0000-0000-000000000000"
}
]
}Paging through large results
A query never returns an unlimited number of rows. The default and maximum page size for standard tables is 5,000 rows. The caller can ask for a smaller page with the Prefer header odata.maxpagesize. When more rows exist, the response includes an @odata.nextLink property holding the URL of the next page. The client requests that URL exactly as given, without changing it, and repeats until a response arrives without a next link. The top option is different: it caps the total, and a query with top does not page.
Paging matters for integrations because nightly jobs are where large result sets appear. Kwabena's first prototype had read the first 5,000 rows and stopped, silently missing everything after them once the work-order table grew. The fix was a loop on the next link, and a test with more than one page of data in the developer environment.
Worked problem
Counting pages for a nightly export
The research export reads 12,400 completed work orders, with the page size set to 2,000 rows through the Prefer header. How many requests does the job make, and how many rows are in the last page?
Show solution
- Divide the rows by the page size: 12,400 divided by 2,000 is 6.2.
- Six full pages hold 12,000 rows, so a seventh request is needed for the remainder.
- The remainder is 12,400 minus 12,000, which is 400 rows, and that response has no next link.
Answer: Seven requests; the last page holds 400 rows. A loop that stops after the first page would export only 2,000 rows.
Creating, updating and deleting rows
To create a row, the client sends POST to the entity set with a JSON body of property values. By default the service answers 204 No Content and returns the new row's URL in the OData-EntityId header. With the header Prefer: return=representation, it answers 201 Created with the new row in the body, which saves a second request when the caller needs generated values such as the autonumber. Lookups are set with the @odata.bind annotation, naming the navigation property and giving the related row's URL.
POST https://lumenvale.crm3.dynamics.com/api/data/v9.2/lcc_workorders
Content-Type: application/json
Prefer: return=representation
{
"lcc_title": "Lakeshore boiler room: low pressure alarm",
"lcc_priority": 2,
"lcc_Building@odata.bind": "/lcc_buildings(lcc_buildingcode='LSB')",
"lcc_source": 4
}To update a row, the client sends PATCH to the row's URL with only the properties that change. A full replacement with PUT exists for single properties but is rarely needed. To delete, the client sends DELETE to the row's URL. A single property can be cleared with DELETE on the property's URL, and a lookup can be removed by deleting its reference.
PATCH has a property that surprises newcomers: by default it is an upsert. If no row exists at the URL, PATCH creates one with that identifier or key. That behaviour is useful for synchronization, described in Lesson 6, but dangerous when the caller expected the row to exist. The header If-Match: * makes PATCH update only, failing with 404 if the row is missing. The header If-None-Match: * makes it create only, failing with 412 if the row already exists.
Alternate keys
Every row has a GUID primary key, but other systems rarely know it. An alternate key is a column or combination of columns that Dataverse enforces as unique, such as Lumenvale's building code or LedgerPoint's supplier number. Once the key is defined and its index has been built, the Web API accepts the key in place of the GUID in a URL, as in lcc_buildings(lcc_buildingcode='LSB'). Listing 1.3 uses the same syntax inside @odata.bind. Alternate keys are the foundation of most synchronization designs, because they let the external system address rows by its own identifiers and make upsert safe to repeat.
Defining a key starts an index build in the background. Until it finishes the key is pending and cannot be used, and if existing data contains duplicates the build fails and the key shows as failed. Wiremu's first attempt to add a key on supplier number failed for that reason: two test suppliers had been entered twice by hand. The duplicates had to be resolved before the key could be activated.
Concurrency and conditional requests
Each row carries a version number, returned as the @odata.etag annotation. A client that reads a row, lets a user edit it and then writes it back can send the etag in an If-Match header. If someone else changed the row in the meantime, the version no longer matches and the service answers 412 Precondition Failed instead of overwriting the other change. The same mechanism lets a reader send If-None-Match with the etag to receive 304 Not Modified when nothing has changed. For integrations that update shared rows, optimistic concurrency is the difference between a lost update that nobody notices and an error that someone can handle.
Functions, actions and custom APIs
Not every operation is a create, read, update or delete. The Web API exposes other platform messages as functions and actions. A function has no side effects and is called with GET; WhoAmI, which returns the caller's user and organization identifiers, is the usual first test of a new connection. An action may change data and is called with POST and a JSON body of parameters. Functions and actions are either bound to a table or row, written after the row's URL with the namespace Microsoft.Dynamics.CRM, or unbound, written directly after the service root.
Custom APIs created in Dataverse appear in the Web API in exactly the same way, as functions or actions named by their unique names. The transcript fee calculation that Signe designed in the earlier series could be called by an external system with a POST to lcc_CalculateTranscriptFee, subject to the execute privilege defined on the API. That is a deliberate design: the logic lives once in Dataverse, and every caller, internal or external, uses the same message.
GET https://lumenvale.crm3.dynamics.com/api/data/v9.2/WhoAmI
HTTP/1.1 200 OK
{
"@odata.context": "https://lumenvale.crm3.dynamics.com/api/data/v9.2/$metadata#Microsoft.Dynamics.CRM.WhoAmIResponse",
"BusinessUnitId": "…",
"UserId": "…",
"OrganizationId": "…"
}Errors and status codes
A failed request returns an HTTP status code and a JSON error object with a code and a message. The message is written for developers and often names the column or privilege at fault. Integration code should log the status, the error code, the message and the request identifier from the response headers, but never the access token or personal data in the body.
| Status | Typical meaning | What the client should do |
|---|---|---|
| 400 Bad Request | Malformed query, wrong property name, invalid value | Fix the request; retrying will not help |
| 401 Unauthorized | Missing, expired or invalid token | Acquire a new token, then retry once |
| 403 Forbidden | The caller lacks a privilege | Fix the security role; do not retry |
| 404 Not Found | Wrong entity set or no row with that key | Check names and keys |
| 412 Precondition Failed | Etag or If-None-Match condition failed | Re-read the row and decide |
| 429 Too Many Requests | Service protection limit reached | Wait for the Retry-After interval, then retry |
| 500, 502, 503, 504 | Unexpected or transient server error | Retry with backoff, then alert |
The 429 response deserves special attention, and Lesson 7 returns to it in detail. Dataverse protects itself with service protection limits evaluated per user over a sliding five-minute window: 6,000 requests, 20 minutes of combined execution time and 52 concurrent requests. A client that exceeds a limit receives 429 with a Retry-After header saying how long to wait. Well-behaved clients wait that long and then retry. ServiceClient does this automatically for many operations; code that calls the Web API directly must do it itself.
Batching requests
The Web API accepts a batch request: a single POST to the batch endpoint containing up to 1,000 individual requests in a multipart body. Changes can be grouped into change sets, and the operations in a change set succeed or fail together as one transaction. Requests outside change sets run independently, and the caller can ask the service to continue after an error. Batching reduces the number of HTTP round trips and lets a client make related changes atomically, but it does not reduce the load on Dataverse: each request inside the batch still counts against the service protection limits. Lesson 7 compares batching with the bulk operation messages, which are the better tool for large volumes.
Trying the API safely
Signe asked Wiremu to explore the API in his own developer environment before writing any code. He signed in with his own account through a REST client, ran WhoAmI, listed buildings with a select option, created and deleted a test work order, and then broke things on purpose: a misspelt column name, an expired token, a PATCH with If-Match to a row that did not exist. Each error showed him the status code and message that the integration code would later have to handle. He wrote down the exact entity set and property names from the metadata document in the repository's docs folder, so that every later integration used the same names.
She was clear about what not to do. Nobody would point a test client at production. Nobody would paste a token into a chat or commit it to the repository. And nobody would use a personal account for a service that ran unattended; that was the subject of the next session, on app registrations.
Common mistakes
MistakeLeaving out the select option so that every column comes back.
InsteadAlways select only the columns needed; the response is smaller and does not change when columns are added.
MistakeReading the first page and assuming it holds all the rows.
InsteadFollow @odata.nextLink until no next link remains, and test with more than one page of data.
MistakeUsing PATCH to update a row without realizing it creates the row if it is missing.
InsteadSend If-Match: * when the row must already exist, and If-None-Match: * when it must not.
MistakeGuessing entity set and property names from display names.
InsteadRead the names from the metadata document or the table definition and keep them in the repository.
MistakeCalling the Web API over HTTP from inside a plug-in.
InsteadUse the IOrganizationService the plug-in receives from its context.
MistakeRetrying a 400 or 403 response in a loop.
InsteadRetry only transient errors such as 429 and 503; fix the request or the privilege for the others.
Summary and key terms
- The Dataverse Web API is an OData version 4 HTTP interface at the environment URL followed by api/data/v9.2; the SDK for .NET exposes the same operations through ServiceClient.
- Tables are entity sets, columns are lower-case logical names, and the metadata document is the authoritative list of names.
- Queries use select, filter, orderby, top and expand, return at most 5,000 rows a page and continue through @odata.nextLink.
- POST creates, PATCH updates or upserts, DELETE removes; If-Match and If-None-Match control upsert behaviour and concurrency.
- Alternate keys let other systems address rows by their own identifiers.
- Functions and actions, including custom APIs, expose other platform messages; batches group up to 1,000 requests but each still counts against limits.
- OData
- An open standard for REST interfaces that defines URL conventions, query options and JSON formats; Dataverse uses version 4.
- Entity set
- The name of a table in the Web API, usually the plural of its logical name.
- Alternate key
- A column or combination of columns that Dataverse enforces as unique and that can address a row in place of its GUID.
- Upsert
- An operation that updates a row if it exists and creates it if it does not.
- Etag
- A version marker returned with each row, used for optimistic concurrency with If-Match and If-None-Match.
- ServiceClient
- The current .NET client class for Dataverse, in the Microsoft.PowerPlatform.Dataverse.Client package.
- Change set
- A group of operations inside a batch request that succeed or fail together.
Practice problems
Work each problem on paper first, then reveal the answer to check.
What is the entity set name for a table with the logical name lcc_building, and where would you confirm it?
Show answer
Normally lcc_buildings; confirm it in the metadata document or the table definition.
A PATCH to a work-order URL created a new row by mistake. What header would have prevented it?
Show answer
If-Match: *, which makes the PATCH update only and return 404 when the row is missing.
Why does a batch of 500 requests not avoid service protection limits?
Show answer
Each request inside the batch still counts as a request against the limits.
How does a client get the label of a choice column rather than its number?
Show answer
By asking for formatted value annotations with the Prefer header.
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.