Dataverse long-running work and webhook callbacks in Azure Logic Apps
By Mirko Peters ·
How to combine Dataverse webhooks, the Dataverse asynchronous service and Logic Apps polling or webhook patterns for long-running work, with the documented 60-second webhook timeout, retry rules and Logic Apps limits.
A Dataverse webhook gives you only 60 seconds and reads only the status code, so it cannot carry a long operation itself. The workable design is to let the webhook start a Logic App, return a 2xx quickly, and let the Logic App do the long work with a polling or callback pattern. This article covers the documented limits on each side and where the documentation stops.
Key points
- A Dataverse webhook posts the execution context as JSON, waits 60 seconds, and reads only the HTTP status code. Any 2xx counts as success, so answer fast and do the long work afterwards.
- Dataverse retries a webhook once, and only for 502, 503 and 504. It sends at most 256 KB, then strips ParentContext, InputParameters and the entity images.
- Register webhooks in the Plug-in Registration tool with HttpHeader, WebhookKey or HttpQueryString authentication. Asynchronous steps log failures in System Jobs.
- For work that outlasts the request timeout, Logic Apps documents two patterns: polling with a 202 and Location header, or a webhook action that pauses until a callback.
- Request timeouts are 120 seconds in multitenant Logic Apps and 225 seconds by default in single-tenant. Stateful run duration defaults to 90 days.
The Dataverse side
Asynchronous service
Learn describes the Dataverse asynchronous service as a managed first-in, first-out queue for asynchronous plug-ins, workflows and operations such as bulk import. Each queued item is a System Job (asyncoperation). You see them under Settings > System > System Jobs, or query them:
``http GET <organization URL>/api/data/v9.2/asyncoperations?$top=1000 ``
Learn lists states such as Ready, Suspended, Locked and Completed, with status reasons like Waiting, In Progress, Succeeded and Failed. It says creating system jobs with code is not supported, and that cancel, pause and resume do not work on jobs generated by the platform. The page does not document limits or timeouts for the service.
The Web API page lists Prefer: respond-async, described as specifying that the request should be processed asynchronously, and links to a Background operations (preview) article. The Web API page does not say which operations support it or how you poll for the result, so check the Background operations article before relying on it.
Webhooks
Register a webhook in the Plug-in Registration tool with Register New WebHook and give it a name, an endpoint URL and one authentication option:
| Option | How it is sent | |---|---| | HttpHeader | Key/value pairs in the request header | | WebhookKey | Query string code with your value, which suits Azure Functions | | HttpQueryString | Key/value pairs in the query string |
Registered webhooks support only port 80 for HTTP and port 443 for HTTPS. You then register a step on a message, with a stage and an execution mode.
Learn lists these behaviors:
- Payload: a POST with a JSON body representing a
RemoteExecutionContext, plus headers such asx-ms-dynamics-organization,x-ms-dynamics-entity-nameandx-ms-dynamics-request-name. - Size: over 256 KB, the header
x-ms-dynamics-msg-size-exceededis sent and four properties are removed. - Response: only the status code counts. 2xx is success.
- Timeout: 60 seconds.
- Retry: one extra attempt, only for 502, 503 or 504.
- Asynchronous steps: a System Job records success or failure, and failures show with Status Reason Failed.
- Synchronous steps: a failure shows the user an Endpoint unavailable dialog. If an error occurs after the request was sent, the data operation rolls back but the request already sent cannot be recalled.
Use asynchronous steps for long work. Learn says synchronous mode suits cases where the entire transaction must fail unless the payload is received.
Learn also notes webhooks scale only as far as your hosted service can handle the messages, and that Azure Service Bus offers a full queue for high volumes.
The Logic Apps side
Learn describes two patterns for work that outlasts the request timeout.
Polling. Your API returns 202 Accepted with a Location header and optionally Retry-After. By default the engine polls the location URL after one second. A 200 OK with the payload ends the wait, and another 202 with the same headers keeps it going. Learn says the workflow definition needs nothing extra when the API follows this pattern.
Webhook. The workflow calls a subscribe endpoint, creates a callback URL, and waits. If the run is canceled, the engine calls unsubscribe. The designer cannot discover these endpoints through Swagger, so add a Webhook action and specify the URL, headers and body yourself. Learn says the workflow function @listCallbackUrl() can be used to pass in the callback URL. If you own both the logic app and the subscribed service, you do not have to call unsubscribe after the callback.
Limits, per Learn's limits page:
| Limit | Multitenant | Single-tenant | |---|---|---| | Inbound and outbound request | 120 sec | 225 sec (default) | | Run duration | 90 days | Stateful 90 days, stateless 5 min (defaults) | | Until loop timeout | PT1H | Stateful PT1H, stateless PT5M | | Retry attempts | Default 4 (Consumption) | Default 4 |
Inbound limits apply to the Request trigger, HTTP Webhook trigger and HTTP Webhook action. If the Response action has Asynchronous response turned on, or no Response action exists, the call pattern is asynchronous and the workflow can take whatever time it needs. Stateless workflows in single-tenant run only synchronously, so use stateful workflows for long work.
Putting it together
- Register an asynchronous webhook step that posts to a Logic App with a Request trigger. Use the key in the authentication option.
- Have the Logic App return a 2xx at once, inside the 60 seconds. Learn documents the Response action's Asynchronous response setting, and that a workflow without a Response action runs asynchronously. Placing the long steps after a Response action is a common design, but the pages read do not document it, so test it.
- In the workflow, call the long-running service. If it follows the 202 and
Locationpattern, the HTTP action waits for it. If it supports callbacks, use the Webhook action. - Write the result back to Dataverse with a row update.
- Monitor failures in System Jobs on the Dataverse side and in run history on the Logic Apps side.
Learn does not describe this exact combination, so treat it as an assembly of documented parts and test it. In particular, check what a retry does: because Dataverse can resend after 502, 503 or 504, make the Logic App idempotent, for example by keying work on PrimaryEntityId and the correlation header x-ms-correlation-request-id, which Learn says is used for infinite loop prevention.
Typical mistakes
- Doing the long work before replying and hitting the 60-second timeout.
- Using a synchronous step and rolling back users' saves when the endpoint is slow.
- Expecting the webhook response body to carry data back into Dataverse.
- Relying on the payload for related rows after it exceeded 256 KB.
Related
Sources
- Use webhooks to create external handlers for server events
- Register a WebHook
- Dataverse asynchronous service
- Compose HTTP Requests and Handle Errors (Web API)
- Patterns for calling custom web APIs and REST APIs from workflows in Azure Logic Apps
- Limits and configuration for Azure Logic Apps
FAQ
How long does a Dataverse webhook wait for my endpoint?
Microsoft Learn says the timeout is 60 seconds. The system cannot parse data returned in the response body and only looks at the status code. A 2xx status means success, anything else fails the operation.
Does Dataverse retry a failed webhook call?
Learn says the webhook service makes one more attempt only for status codes 502, 503 and 504, which indicate a networking issue. The page does not say whether the 60-second timeout triggers that retry.
What is the payload size limit?
Learn says that when the whole HTTP payload exceeds 256 KB, the header x-ms-dynamics-msg-size-exceeded is added and the properties ParentContext, InputParameters, PreEntityImages and PostEntityImages are removed. Read the row again with the Web API if you need them.
How does Logic Apps wait for a job that takes longer than the request timeout?
Learn describes the polling pattern, where the API returns 202 Accepted with a Location header and the engine polls it, and the webhook pattern, where the workflow calls a subscribe endpoint, creates a callback URL and waits for the callback. Polling by default starts after one second.
What are the Logic Apps timeout limits?
Learn lists 120 seconds for inbound and outbound requests in multitenant Logic Apps and 225 seconds by default in single-tenant. If the Response action's Asynchronous response setting is on, or there is no Response action, the pattern is asynchronous and the workflow can take as long as needed.