cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Sahil
Helper I
Helper I

How to consume Dataverse Custom API from Power Portals?

Hi All,

 

Is it possible to consume the Dataverse custom API (unbound) from within Power Portals using JS? If so, please share a sample code for the same.

 

Thanks in advance!

 

Regards,

Sahil

1 ACCEPTED SOLUTION

Accepted Solutions
eugenevanstaden
Resolver III
Resolver III

You wont be able to call Custom API directly. If you want to consume the Custom API/Custom Action then there are other options.

You can call a Flow, which executes the Custom API, or you can set up a Companion API. I prefer the Companion API approach as its secure - https://docs.microsoft.com/en-us/power-apps/maker/portals/oauth-implicit-grant-flow

You dont want to expose ClientId/Secret in Javascript.




View solution in original post

18 REPLIES 18
eugenevanstaden
Resolver III
Resolver III

You cant consume it from Portal, however you can implement the Portal API.
https://docs.microsoft.com/en-us/power-apps/maker/portals/web-api-overview



eugenevanstaden
Resolver III
Resolver III

You cant consume it from Portal, however you can implement the Portal API.
https://docs.microsoft.com/en-us/power-apps/maker/portals/web-api-overview



Hi, I have gone through this documentation already but could not find any details on how to call Dataverse Custom APIs from within Power Portal.

 

Some Background details:

I created a Custom API record in Dataverse and associated a plugin to the same API.  Now, I need to call this API from Portal with some Input Parameters in the request and get output parameters as the response. 

I saw this post that talks about how to call custom actions from Portal and we get a custom action for a Custom API as well so shouldn't we be able to consume the APIs in the same way from Portal?

 

https://debajmecrm.com/call-custom-action-using-webapi-in-powerapps-portals-dynamics-365-portals/ 

eugenevanstaden
Resolver III
Resolver III

You wont be able to call Custom API directly. If you want to consume the Custom API/Custom Action then there are other options.

You can call a Flow, which executes the Custom API, or you can set up a Companion API. I prefer the Companion API approach as its secure - https://docs.microsoft.com/en-us/power-apps/maker/portals/oauth-implicit-grant-flow

You dont want to expose ClientId/Secret in Javascript.




eugenevanstaden
Resolver III
Resolver III

Custom Actions via the Portal API was on the roadmap - not sure where it is at in terms of when its in public preview

Hi,

 

Based on my analysis/hits and tries so far, I am able to call any custom action and custom API that is bound to the CONTACT entity from Power Portals. But, I am still not able to get the response/output parameters from the API call if it is a success. The below syntax works:

 

webapi.safeAjax({

type: "POST",

url: "/_api/contacts("ENTER GUID")/Microsoft.Dynamics.CRM.new_contactapi",

contentType: "application/json",

data: JSON.stringify({ "name": "Test" }),

success: function (res, status, xhr){

}

});

I have done similar but yes as long as its bound action, if unbound then an issue. Did you check the response header for any output?

Sahil
Helper I
Helper I

Yea, I tried to check the Response Header in the developer console but nothing is there. However, if you try to create a new record using the Portal API then you get the ID (entityid) of the record in the response header.

 

I believe that maybe the Power Automate flow (with HTTP trigger) might be an option for me as I need the response parameters back to navigate the portal user accordingly (after custom logic) to the next screen.

Helpful resources

Announcements
Microsoft 365 Conference – December 6-8, 2022

Microsoft 365 Conference – December 6-8, 2022

Join us in Las Vegas to experience community, incredible learning opportunities, and connections that will help grow skills, know-how, and more.

Difinity Conference 2022

Difinity Conference 2022

Register today for two amazing days of learning, featuring intensive learning sessions across multiple tracks, led by engaging and dynamic experts.

European SharePoint Conference

European SharePoint Conference

The European SharePoint Conference returns live and in-person November 28-December 1 with 4 Microsoft Keynotes, 9 Tutorials, and 120 Sessions.

Users online (1,889)