Search code examples
microsoft-dynamicspowerappsdynamics-365dataversepowerapps-portal

Query (HTTP GET) data in Power Apps Portal from Web API with JavaScript


I have a "Starter Portal" Power App Portal. I would like to utilize JavaScript and the Web API for querying data. Documentation states

You can use the Web API to perform create, update, and delete operations across all Microsoft Dataverse tables from your portal pages.

Further documentation only lists the CREATE, UPDATE, DELETE operations, and this API being accessible as

[Portal URI]/_api

And I have found how to successfully authenticate using a helper method to get a token for the header:

shell.getTokenDeferred().done(function (token) { ...}

This allows authentication as the user logged into the portal so I believe all relevant Table Permissions, etc. are applied.

But, I would like to retrieve data (HTTP GET). I know this is possible from the Dataverse Web API.. This api is exposed as

[Organization URI]/api/data/v9.1/

Are these really the same API, just exposed a different way for the portal? Is it possible to use the GET endpoints or the second API altogether, authenticated as a Portal Contact user like the previous operations?


Solution

  • It's the same API but permissions are different, you will need to enable the tables you want to access inside the _api endpoint.

    You can read more info at this page: https://learn.microsoft.com/en-us/powerapps/maker/portals/read-operations, there is also an XrmToolBox tool to assist you in this operation (but I didn't try it) https://www.xrmtoolbox.com/plugins/PowerPortalWebAPIHelper/

    Regarding the Web API calls, I released a new tool to create them (similar to CRM REST Builder) I also added a "Portals" syntax (is in preview) but the generated urls are the same. Link: https://github.com/GuidoPreite/DRB