Calling a Power Platform AI Builder Model via oData

   Words by Paul McQuillan

   on 28/04/2021 21:00:00

We’ve got our Model setup in the Power Platform AI Builder and we’ve experimented with a Flow in Power Automate to query the Model and Predict an outcome.

As a next step we might want to start querying our model outside of Power Automate to start running experiments or test scenarios past our model – particularly if we want to start visualising the model graphically or showing ‘what-if’ style predictions.

We could run different Predict Actions in Power Automate in bulk to generate data from our model – but this would be quite wasteful.

Instead we might want to invoke our Model in real-time to generate a Prediction Outcome.

We can do this by invoking our Model via the Dynamics oData API.

This can be done by calling the Predict Action against our Model, and supplying our input values to generate the prediction.

The documentation from Microsoft for this call is fairly non-existent as yet so this took some trial and error to get right – but it can be done.

Specifically by calling the following command as a REST Endpoint using a POST Message:

https://[mycrm].crm[region].dynamics.com/api/data/v9.1/msdyn_aimodels([GUID Id of my Model])/Microsoft.Dynamics.CRM.Predict

Supplying the details of our Prediction Input as the Body of the Message:

{
  "version": "2.0",
  "requestv2": {
    "@odata.type": "Microsoft.Dynamics.CRM.opportunity",
    "new_winnability": 100
  }
}

This tests the model to return the Predicted Outcome when a single Input is supplied – in my case, just [Winnability] as 100.

The Model will then return its prediction for that scenario:

{

"responsev2":{

  "@odata.type": "#Microsoft.Dynamics.CRM.expando",

  "operationStatus": "Success",

  "predictionOutput":{

    "@odata.type": "#Microsoft.Dynamics.CRM.expando",

    "Explanation": "[{\"entityName\": \"new_projects\", \"attributeName\": \"new_projecttype\", \"weight\": 0.13992829903618048}, {\"entityName\": \"opportunity\", \"attributeName\": \"new_customercontractstatus\", \"weight\": 0.11845726947582477}, {\"entityName\": \"new_projects\", \"attributeName\": \"new_name\", \"weight\": 0.05761718620521564}]",

    "Likelihood": 0.6319,

    "Prediction": 2

    }

  }

}

This then provides a way of querying our model using Custom Development or JSON Calls outside of Power Automate.

By building a series of JSON Calls, we could use this approach to build real-time scenarios comparing different probabilities for scenarios in the Model.

This can most obviously be seen using a JSON Client such as Talend to pass requests to our Model and evaluate the responses.

image

At the time of writing, I found the Microsoft Documentation on this action to be ‘evolving’ as took pulling a few resources on oData to get the syntax of this call right – so hopefully this article helps point in the right direction!

Further Reading

Predict Action

https://docs.microsoft.com/en-us/dynamics365/customer-engagement/web-api/predict?view=dynamics-ce-odata-9

Predict Response

https://docs.microsoft.com/en-us/dynamics365/customer-engagement/web-api/predictresponse?view=dynamics-ce-odata-9

Getting Started with the Power Platform AI Builder

https://www.crmcs.co.uk/content/getting-started-with-the-power-platform-ai-builder.aspx

Share this Article

Search Articles

Filter Articles

CRM Tech DocMan

Recent Articles

HOW TO: Manage Your Dynamics 365 Database Size (Video Included) Dynamics 365 Marketing vs ClickDimensions It’s time to pause, reflect and acknowledge a new era of inclusivity and collaboration. Part 2 - How to get the most from a Technology Expert – Asset Management Hub Property & Asset Management Hub Part 1 – Balancing CRM and Asset Management Scopes - Asset Management Hub Creating a Multi-Lingual PowerApps Portal How to Set Up a Microsoft Teams Site Using DocDrive365 Microsoft Teams - Adding a Microsoft Teams URL to a Dynamics Appointment Dynamics 365 Marketing – Customer Voice Survey Not Appearing In Emails? Using SQL Management Studio to connect to the Dynamics DB Calling a Power Platform AI Builder Model via oData How to use DocDrive365 to integrate permissions between Business Units in Dynamics with Sites in SharePoint Getting started with the Power Platform AI Builder. Power Apps Portal Information Hub DocDrive365 Security: Day One - Getting Started with Dynamics to SharePoint Permissions Part 5 - Power Apps Portals: How To Connect Azure B2C With Linked-In Part 4 – Power Apps Portals: Styling Azure B2C for Power Apps Portals The 3 Phases for Using Multi-Select Option Sets in Flow with Microsoft Forms Part 3 – PowerApps Portals: Azure B2C and Power Apps Portals – User Flow for Signup and Signin Part 2 - Power Apps Portals: New Application Registration in Azure B2C for our Power Apps Portal Part 1 – Power Apps Portals: Creating a New Azure AD B2C Tenant The Automation Bot: Launching Contextual Flow from Teams Creating a New Bot for Teams Debugging your Teams Bot using Ngrok
Contact Us

Want expert advice or a demo?

Get in touch now and see how we can help your business grow.

  • Name
  • Email Address
  • Phone Number
 
Close

Understanding Your Challenges

Our strong understanding of CRM and emerging technologies within the Microsoft environment means we deliver the right solutions for you.

Proven Real-World Solutions

As a leader in the field of Dynamics solutions, our pedigree developing and delivering real-world solutions is unsurpassed.

Long Term Support

We provide support beyond our design, implementation and 'go-live' delivery using Sprints and continual updates to our AppSource apps.

CRMCS | Design by Thinktank Marketing | Citrus-Lime Limited

To improve your experience today and in the future, this site uses cookies. Read our full Privacy Policy & Cookie information here I Understand