web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id : ULNpe5HqJy38JL1E64jYMb
Power Pages - Customize & Extend
Answered

How to consume Dataverse Custom API from Power Portals?

Like (0) ShareShare
ReportReport
Posted on 17 Aug 2022 17:38:12 by 130

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

Categories:
  • rk2048 Profile Picture
    22 on 23 Sep 2023 at 19:26:48
    Re: How to consume Dataverse Custom API from Power Portals?

    @tappu02 

    The second option is quite compelling and I would like to pick your brain on the the GET call that you make to a virtual entity.

    As I see it is a fetch xml query to trigger the Retrieve multiple plugin configured with the virtual entity. 

    I tried this and it does not seem to work the same way as it would for a standard entity with a retrieve multiple plugin configured.

    I would like your thoughts on how you would implement the get call from the portal passing a couple of parameters to achieve a desired response of triggering the Virtual entity plugin.

  • Sahil Profile Picture
    130 on 30 Oct 2022 at 21:10:34
    Re: How to consume Dataverse Custom API from Power Portals?

    Thanks @tappu02 .

     

    This seems to be a good alternative. I will try to use this somewhere in my project.

  • tappu02 Profile Picture
    Microsoft Employee on 14 Oct 2022 at 22:48:44
    Re: How to consume Dataverse Custom API from Power Portals?

    @Sahil 

    There are couple of workarounds we can use to achieve this until the feature is supported in the product.

    1. Create a HTTP triggered power automate and call the D365 Custom API from within the flow. Next, call the flow from the PowerApps portal client code.

    2. This is an alternate way we tried using Virtual Entity. Configure a virtual entity to contain the same parameters as your Custom API input and output parameters. The Virtual entity Provider expects a plugin configured which in our case would be a Retrieve/RetrieveMultiple plugin configured on the virtual entity. The idea being when a GET call is made on the virtual entity (using REST API), the plugin would get called. The plugin will call your custom API internally and can return the output back. The good part is the RetrieveMultiple plugin gets registered as a Main event in the pipeline instead of as a POST event. Also, as compared to the first approach, you no longer have to maintain the flow URL which can also have security concerns having the signature in it.

  • steeredprince Profile Picture
    8 on 17 Sep 2022 at 15:53:08
    Re: How to consume Dataverse Custom API from Power Portals?

    @eugenevanstaden 

     

    Thank you for your response. I believe I had misunderstood the use of portal api. I now understand to call the custom dataverse API you do need the Implicit Grant flow feature from Portal and use a companion api. 

    Thank you for response and clarification

  • eugenevanstaden Profile Picture
    432 on 15 Sep 2022 at 20:19:14
    Re: How to consume Dataverse Custom API from Power Portals?

    @steeredprince 

    Portal Web Api details here https://docs.microsoft.com/en-us/power-apps/maker/portals/web-api-overview

    Have you configured the Site Settings and set up the Table and Column permissions?

    The above scenario is for consuming an external api securely using the Implicit Grant flow feature from Portal. Your code sample is for consuming the Portal Web Api.

    What errors are you getting?




  • steeredprince Profile Picture
    8 on 15 Sep 2022 at 09:07:53
    Re: How to consume Dataverse Custom API from Power Portals?

    May I request you to elaborate or point to an article  or link on how you can call a custom API using the Portal Web API. 

    I have used the portal web api like shown below but I feel I missing key steps in using that and calling a custom API.

     


    {% editable snippets 'GDS/APIButtonContinue' %}

    {% assign entity = 'new_hsdemos' %}
    {% assign fieldLogicalName = 'new_location' %}
    {% assign linkPage = 'welcome' %}

    {% include 'API -- WrapperAJAX' %}

    <script>

    // update
    function updateRecord(dynid) {
    const recordUrl = window.location.href;
    const recordId = recordUrl.split("=")[1];
    webapi.safeAjax({
    type: "PATCH",
    url: "/_api/{{ entity }}(" + recordId + ")",
    contentType: "application/json",
    data: JSON.stringify({
    "{{ fieldLogicalName }}": 100000000
    }),
    success: function (res, status, xhr) {
    dynid(xhr.getResponseHeader("entityid"));
    //myCallback(dynid);
    console.log(xhr.getResponseHeader("entityid"));
    }
    });
    };
    //Button Click
    $('#ButtonContinue').click(function () {
    updateRecord(myRoute)
    });
    </script>
  • eugenevanstaden Profile Picture
    432 on 21 Aug 2022 at 20:41:13
    Re: How to consume Dataverse Custom API from Power Portals?

    @Sahil 

    I have a companion app template here:
    GitHub - eugenevanstaden/d365-portal-companion-api: Sample API demonstrating how to configure OAuth to authenticate against D365 portal

    Once you have the API set up you can consume it from the portal securely by first getting the Auth token and then executing your call to the API endpoint. I use this for custom document upload, payment integration or any secured external service that needs to be consumed from the portal.


    eg. 
    the authUrl would be: portal/_services/auth/token?client_id=abc123
    The companionAppUrl would be your endpoint.

     $("#checkout-btn").click(function () {
     $.ajax({ method: "POST", cache:false, url: "{{authUrl}}", })
     .done(function (token) {
     $.ajax({
     method: "GET",
     headers: { 'Authorization': "Bearer " + token },
     url: '{{companionAppUrl}}/payment/request?orderid={{orderid}}'
     }).done(function (data) {
     window.location.href = data.paymentUrl; //redirect to payment page
     }).fail(function (error) {
     $("#payment-service-alert").show();
     });
     });
     });


    The MS examples are here:
    https://github.com/microsoft/PowerApps-Samples/tree/master/portals/ExternalWebApiConsumingPortalOAuthTokenSample



  • Sahil Profile Picture
    130 on 19 Aug 2022 at 14:59:20
    Re: How to consume Dataverse Custom API from Power Portals?

    Hi,

     

    Is there any other documentation available that you are aware of Companion API or Implicit Grant Flow configuration for Portals and can share? The existing MS docs seems little confusing to me.

  • Sahil Profile Picture
    130 on 18 Aug 2022 at 22:19:25
    Re: How to consume Dataverse Custom API from Power Portals?

    Right. We may use Azure APIM to make it secure. Not aware of Portal Implicit Grant Flows, will explore it. Thank you for sharing 🙂

  • Fubar Profile Picture
    8,032 Super User 2025 Season 2 on 18 Aug 2022 at 22:12:01
    Re: How to consume Dataverse Custom API from Power Portals?

    @Sahil wrote:

    ......

    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.


    Just be aware that the url for the Flow's HTTP trigger can be called publicly by default (i.e. you may need to add security to it).  Alternatively use the Portals Implicit Grant Flow https://docs.microsoft.com/en-us/power-apps/maker/portals/oauth-implicit-grant-flow

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Announcing our 2025 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for…

Paul Stork – Community Spotlight

We are honored to recognize Paul Stork as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Pages

#1
Lucas001 Profile Picture

Lucas001 60 Super User 2025 Season 2

#2
Fubar Profile Picture

Fubar 55 Super User 2025 Season 2

#3
surya narayanan Profile Picture

surya narayanan 35

Featured topics

Loading complete