Call Power Automate actions from the Web API
Dataverse contains a feature that allows power users to create their own custom sets of business logic called actions. From a developer perspective, Microsoft Docs defines an action as a "reusable operation, which may have observable side effects." These side effects include creating or updating records.
Another feature of actions is their ability to be invoked through the Web API. As a result, you can encapsulate your low-code automations in such a way that you can use them in nearly any scenario by interacting with them through their associated Web API request and response.
While this lesson doesn't cover how to create actions in detail, it's assumed that you already have a basic understanding of how to build them. If you need more information on how to create an action, you can review the documentation on them. See the Create Custom APIs section for detailed information on how to build Dataverse actions.
Run actions with the Web API
When a new action is created in your Dataverse solution, the framework also creates a corresponding Web API request message. You can run these requests by using a POST operation similar to the following example:
POST [Organization URI]/api/data/v9.2/WinOpportunity HTTP/1.1
Accept: application/json
Content-Type: application/json; charset=utf-8
OData-MaxVersion: 4.0
OData-Version: 4.0
{
"Status": 3,
"OpportunityClose": {
"subject": "Won Opportunity",
"opportunityid@odata.bind": "[Organization URI]/api/data/v9.2/opportunities(b3828ac8-917a-e511-80d2-00155d2a68d2)"
}
}
The above example is an HTTP request call to the WinOpportunity action for an opportunity with an opportunityid value of b3828ac8-917a-e511-80d2-00155d2a68d2.
Call pre-built Dataverse actions
Dataverse comes with a set of existing actions that you can use to perform common operations. Some of these actions might only apply to model-driven or Dynamics 365 apps. For example, the CalculatePrice action calculates the price in an opportunity/quote/order/invoice, so it would only apply to a Dynamics 365 Sales app where that functionality exists.
For more information about which pre-built actions are available for use through the Web API, see the Web API Action Reference.
Unbound vs. bound actions
An action can be built as either unbound (meaning, it doesn't have a
Dataverse entity correlated to it) or bound (meaning, the
logic is tied to a specific entity record). SQL developers could
consider these actions as similar to stored procedures (unbound
actions) versus triggers (bound actions). However, unlike SQL triggers,
you can also run bound actions on demand by providing a
corresponding entity record ID as its parameter.
Unbound actions are beneficial for generic logic that might need to run outside the context of a specific entity record, such as the WinOpportunity action that was referenced earlier. To run a bound action against a specific record, you must provide the ID of that record in the URI of your request:
POST [Organization URI]/api/data/v9.2/contacts(94d8c461-a27a-e511-80d2-00155d2a68d2)/Microsoft.Dynamics.CRM.new_AddNoteToContact HTTP/1.1
Accept: application/json
Content-Type: application/json; charset=utf-8
OData-MaxVersion: 4.0
OData-Version: 4.0
{
"NoteTitle": "New Note Title",
"NoteText": "This is the text of the note"
}
The preceding example calls a custom action that was previously built in the solution called new_AddNoteToContact for a contact with the ID of 94d8c461-a27a-e511-80d2-00155d2a68d2 and then passes the parameters NoteTitle and NoteText to the action. The expected behavior for this procedure would be that a new note would be added to the corresponding contact with the title and text provided.
More details
For more information on how to call actions in code, see the Use Web API actions article in Microsoft Docs.
Trenger du hjelp? Se feilsøkingsveiledningen vår, eller send oss spesifikke tilbakemeldinger ved melde fra om et problem.