Skip to content

Helper file for making WebAPI calls in Dynamics 365

The WebAPI has been around since Dynamics CRM 2016, and it has only become better with added features in Dynamics 365. Being aware of the fact that Microsoft has planned to slowly phase out the OData v2 or the REST endpoint to be replaced by the WebAPI completely in the future versions, it is only a smart decision to start using the much more robust and flexible WebAPI endpoint in the code that we write so that we make it more maintenance friendly.

What is WebAPI?

According to Microsoft’s official article : “The Web API, which is new for Microsoft Dynamics 365 (online & on-premises), provides a development experience that can be used across a wide variety of programming languages, platforms, and devices. The Web API implements the OData (Open Data Protocol), version 4.0, an OASIS standard for building and consuming RESTful APIs over rich data sources.”

You can find more here : Use the Microsoft Dynamics 365 Web API

What exactly am I offering you here?

For developers like us, we often end up writing our own piece of code to make those WebAPI calls for various projects. Unlike the “SDK.REST.js”, which is provided by Microsoft as a part of their Dynamics CRM SDKs, there isn’t any similar file that exists for WebAPI (or at least I couldn’t find any).

Wouldn’t it be really handy if we could create a helper file for WebAPI that helped us make those calls without having to write the whole thing again?

That’s where I decided to put together this helper file. It works exactly the same was as the “SDK.REST.js” used to work. You refer it in your custom code and simply call the various methods for Create, Update, etc. and the helper method will give you back the result like you used to get for the REST calls. I’ve been using this in my projects and so far this has saved a lot of time for me.

You can download it from here : Download SDK.WebAPI.js

How do I use it? Samples would be great!

Sure, if I made the effort of creating this helper file, why not go that extra mile of helping you use this. Once you have downloaded and extracted the archive, you’ll get a JavaScript file which you need to refer in your code (an example would be a HTML page where you are fetching some data from entities and displaying them in a fancy interface).

Without further ado, I will cut to the chase by giving you samples for the most commonly used methods: Create, Update, Delete, Retrieve and RetrieveMultiple.

CREATE:

UPDATE:

DELETE:

RETRIEVE SINGLE (By ID):

RETRIEVE MULTIPLE (By Query):

Now, if you need help forming the select query with $select, $filter, $expand and $order, I suggest using the CRM REST Builder solution by Jason Lattimer. It’s super helpful and lets you actually test the query before you including it in your code. You can download the CRM REST Builder from here : CRM REST Builder

This is how it looks like:

Once again, you can download the WebAPI helper file from here : Download SDK.WebAPI.js

Hope this helps you reduce some effort! Until next time.

Published inDynamics 365Tutorials Dynamics 365

Have something to add?

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

Loading Facebook Comments ...
Loading Disqus Comments ...

No Trackbacks.