Dataverse REST Builder and the Hidden Gems

I would like to start by saying that I use XRMToolbox a lot, I have in my favorites different plugins like FetchXML Builder, Solution Components Mover, User Settings Utility of course Plugin Registration tool and today I am going to talk about the one that has saved me a few times and that is Dataverse REST Builder.

Nowadays probably most consultants working with Dataverse and Power Platform also work with the XRMToolbox, no matter if you are a citizen developer or a pro-code developer, this is an amazing tool that helps us in many scenarios.

For example, when it comes to build a complex FetchXML that is not possible using the advance find in Dataverse, then FetchXML Builder is there to help you, I have lost count how many times I have used this plugin.

But as I mentioned this time I am going to talk about Dataverse REST Builder, and before I continue I would like to say thank you very much Guido Preite for this amazing plugin and thanks to the rest of heroes who have created all the other plugins for the XRMToolbox.

Without further introduction let’s start.

What is Dataverse REST Builder

As its creator claims, Dataverse REST Builder (DRB) is an application to create and execute requests against the Dataverse Web API endpoint.

And that is what this blogpost is about, how to create Dataverse Web API requests to call custom APIs or custom actions using the REST Builder plugin.

So why is this such an important topic for me, well, as a technical consultant I usually have to create Custom APIs and call them from somewhere else like a ribbon button, for example let’s say you have a requirement for a custom table “Contracts”, and the requirement says when the user clicks a button on the contract form to approve it, then some heavy logic needs to run behind it. For these types of scenarios I think Custom APIs are the way to go.

If you haven’t played with Custom APIs yet, I recommend you give it a try, imagine a Custom API as a classic plugin on steroids, with the advantage that you can set input and output parameters to the Custom APIs and you can call them from anywhere else in the platform.

So imagine you already have your Custom API, now the question arises, how can I call it from a ribbon button. And this is where Dataverse REST Builder comes into action.

Calling a Custom API using Dataverse REST Builder

First thing first, open XRMToolbox, connect to your environment and select the Dataverse REST Builder plugin:

After that click in File and then click in New Collection:

Next step is click in New request and select Execute Custom API:

Now you will have to select the table that your Custom API is related to or maybe you created an unbound Custom API as I do in some cases, let’s imagine it is an unbound one in this scenario, then you will have to select the Custom API itself:

As you can see I already have some unbound custom API in my developer environment, I am going to select the one called p365i_crudoperations, which receives an input parameter and that is the action you want to perform: create, read, update, delete:

The next step is to click in Xrm.WebAPI tab and you will get the code to execute the Custom API:

I’m sure you already know this, but the code above is JavaScript, so you can copy and paste this code into your JavaScript web resource to run the custom API from the ribbon button.

I’m not going to explain how to create the Custom API or the button or how to call a JavaScript code from the ribbon button because that’s not the purpose of this blogpost, if you want to know more about that, go and check out this blogpost I did a while ago.

Cool right?, with this you will be able to call any Custom API you create front-end with JavaScript. But this is just the beginning, because with Dataverse REST Builder you can see a lot of different out of the box actions that you can take benefit of.

Exploring out of the box Actions to call

Let’s start by changing the Request Type to Execute Action:

From the table list select Email and from the Action list select sendEmail:

This action as the name indicates sends an email.

The input parameter is the GUID of the email record and you can set the second parameter to true:

That GUID in the image above is this email in my Model Driven App:

And you can even run (as a test operation) this request, click on the Editor tab and then click on the Execute Code button:

And now as you can see the email is pending to be sent, I have not configured the email settings in my environment so that’s why it’s not being sent, but you get the idea.