Get Web Api Version Dynamically in Dynamics 365/ DataVerse

Follow Debajit’s Power Apps & Dynamics 365 Blog on WordPress.com

Loads of my blog readers wanted to know how to get the Web API version dynamically in scripts. In this blog, I will walk you through the steps to accomplish the same.

DataVerse or Dynamics 365 Apps WebAPI endpoint is of the following format.

https://<environment-url>/api/data/v9.2

With each version released by Microsoft, the version number at the end of the URL may be changed. How to make sure to always work with the latest WebAPI endpoint?

The following code give us the version number of the app.

var versionNumber = Xrm.Utility.getGlobalContext().getVersion()

When I execute this code, I get ‘9.2.23031.00178’ as the result. It’s basically in the standard format of <Major>.<minor>.<build>.<revision>

Below is the final code to get the WebAPI version out of the above result.

const [major,minor] = Xrm.Utility.getGlobalContext().getVersion().split('.');
var webApiVersion = major + "." + minor;

Don’t be confused if the javascript code look bit unfamiliar to you. Here we have used the modern Javascript concept of destructuring which is supported in all modern browsers.

Hope you liked this post. If this post has helped, you can buy me a coffee. Links on right pane.

For similar topics on Microsoft.NET and Power Platform, subscribe to my blog using the Subscribe option on right pane.

You will also like the below posts.

Debajit Dutta
Business Solutions MVP