Developers can add desktop flows functionality to their applications, including programmatically triggering and canceling desktop flows. These capabilities are offered as part of the Microsoft Dataverse platform.
By using Dataverse, you can add the functionality of triggering a desktop flow through your application. To implement this functionality, you need to use the RunDesktopFlow action.
To call the action, you'll need the following information.
The ID of the desktop flow that you want to run. You can get this ID via the API as the List available desktop flows section outlines earlier in this article.
Tip
Alternatively, you can retrieve the ID manually from the desktop flow details URL in Power Automate. The URL format is: https://make.powerautomate.com/manage/environments/[Environment ID]/uiflows/[Desktop Flow ID]/details.
The name of the desktop flow connection (targeting a machine/machine group) to use to run your flow. The name can be retrieved from the URL of the same connection page in Power Automate. The URL format is: https://make.powerautomate.com/manage/environments/[Environment ID]/connections?apiName=shared_uiflow&connectionName=[Connection Name].
Alternatively, you can use a connection reference's logical name as the input of the connection instead of the connection name (usage example described below). The connection references are stored in the Dataverse table connectionreference and can be listed programmatically in the same way as desktop flows detailed in the List available desktop flows section.
The inputs of the script are viewable in the run details page on the Power Automate portal (in Preview).
Warning
When using the API, there are some limitations to be aware of:
Triggering a desktop flow run with an account having "User" privileges will work. However, canceling the run and querying the status needs "Owner" privileges.
Dataverse impersonation isn't supported.
The input field content size is limited to 2 MB.
Receive notification on script completion
An optional parameter "callbackUrl" is available in the body of the RunDesktopFlow action.
You can use it if you want to be notified of your script completion.
A POST request will be sent to the provided URL when the script is complete.
If no callback URL parameter is provided, the flow session status should be polled from Dataverse (refers to Get the status of a desktop flow run).
Note
You can still use the status polling as a fallback mechanism even if you provide a callback URL parameter.
Your callback endpoint operation should be idempotent.
The POST request will be retried three times with one second interval if your endpoint responds with a Server Error response (code 500 and above) or a "Request Timeout" response (code 408).
As the callback call isn't authenticated, some precautions should be taken
Check the flow session Id validity when the callback notification is received. Dataverse is the source of truth.
Implement a rate limit strategy on your server side.
Try to limit the callback URL sharing between several organizations.
Cancel a desktop flow run
Similar to the Trigger functionality, you can also cancel a queued/running desktop flow. To cancel a desktop flow, use the CancelDesktopFlowRun action.
Request to cancel a desktop flow run
Authorization: Bearer eyJ0eXAiOi...
Accept: application/json
POST https://[Organization URI]/api/data/v9.2/flowsessions(d9687093-d0c0-ec11-983e-0022480b428a)/Microsoft.Dynamics.CRM.CancelDesktopFlowRun HTTP/1.1
Response from a request to cancel a desktop flow
HTTP/1.1 204 No Content
Errors
When an error occurs, the response has a different format that matches Dataverse error messages. The http error code and the message should provide enough information to understand the issue.
HTTP/1.1 403 Forbidden
{
"error": {
"code": "0x80040220",
"message": " Principal user (Id=526..., type=8) is missing prvReadworkflow privilege (Id=88...*)”
}
}
Known limitations
We currently support up to 70 desktop flows runs per minute for every connection.