PowerApps Portals API – Clear Cache

The cache has been the achilles heel sometimes of the Dynamics 365 portal and now Power Portals. A common function is to clear or reset the cache of the portal so you can see your changes and you can now do that through a hidden API call.

Most of us Dynamics 365 portal users know of the /about/_services method when logged in as an administrator to the portal but now also this API to perform the same function.

In the still yet to be released podcast Dileep mentions that clear cache is initiated when you browse the site from the Portals Design Studio. As when you click browse your are expecting to see your changes you just made clearing the cache prior to navigating your there is a good procedure.

Looking into how it occurs also reveals the portal has an admin API that can be accessed programmatically and you can call clear cache easily from POST call providing the right parameters and authentication token.

How do you use outside of the design studio?!

The various portal regions all have a infrastructure API, below is the root address for Canada (you will need to determine your region URL):

https://portalsitewide-can.portal-infra.dynamics.com/api/v1/powerportal/

After this root address there are various actions like…ClearCache! It takes a single parameter of the portal add-on Id. You will also need to provide a Bearer token that has access to the resource https://portal.dynamics.com for authentication as you don’t want just anyone being able to do this.

If you paste the following into your browser you can retrieve the response and copy the access_token parameter to include in your later request as your authentication.

https://login.microsoftonline.com/common/oauth2/authorize?response_type=token&client_id=a8f7a65c-f5ba-4859-b2d6-df772c264e9d&resource=https%3A%2F%2Fportal.dynamics.com&redirect_uri=https%3A%2F%2Fmake.powerapps.com%2Fauth&response_mode=fragment

You will get back a URL that includes #access_token=, copy the value from here and save to include in your clear cache request.

From POSTMAN a great tool for doing sample HTTP requests you can create a new request to and set the method to POST, then use the following address:

https://portalsitewide-can.portal-infra.dynamics.com/api/v1/powerportal/ClearCache?portalId={PORTAL_ADDON_ID}

You will need to fill-in your portal add-on ID which you can retrieve by going to the make.powerapps.com/apps (ensure you have the correct environment selected), select the ellipsis (…) beside the desired portal app and select details. From the URL at the top grab the PORTAL_ADDON_ID, i.e. /powerportals/{PORTAL_ADDON_ID}/details and replace in your URL.

Next you will need to include the access token from before, select the Authorization tab, change the type as Bearer Token and then paste in the token value.

Filled out POSTMAN request.

Once you have both the portal add-on Id filled and the bearer token entered then click send and this will nuke the full cache of your portal. Getting back ‘true’ means everything succeeded.

Yes it works also on non-CDS portals.

The bearer token you have will expire every 3600 seconds, aka 60 minutes so you will need to refresh this token to continue to use the API action.

What other APIs exist is probably your next question. Well there is one for listing all the Portals by organization (or environment):

https://portalsitewide-can.portal-infra.dynamics.com/api/v1/powerPortal/ListPortalsByOrgId?orgId={ORG_ID}

This provides a very detailed output of the portal add-ons or apps installed in your environment.

[  
   {  
      "Id":"cfdc126f-c2a6-484b-b52a-06943bab2d60",
      "Name":"handlebars-cds-preview portal",
      "Created":"2019-07-26T18:29:57",
      "ApplicationType":"Trial",
      "PortalAudience":"Customer",
      "PackageUniqueName":"CDSStarterPortal",
      "PortalUrl":"https://handlebars-cds-preview.powerappsportals.com",
      "PrimaryRegion":"CanadaCentral",
      "SecondaryRegion":null,
      "TenantId":"a505f8b4-1b44-4e0a-86d3-213825c01837",
      "CrmEditUrl":"https://org03c0b390.crm3.dynamics.com/",
      "CrmInstanceId":"31ee0342-e79b-4ffc-bb23-9565313ef140",
      "Status":"StateConfigured",
      "EntitlementId":null,
      "Purpose":"PowerPortal",
      "CrmInstance":"org5070f220",
      "CrmDatacenter":"YQB",
      "LastUpgradeVersion":null,
      "DeployedAppPackageVersion":"9.1.6.9",
      "SubscriptionId":"bddf495c-6f1c-44d3-9dbf-84026a2980cc",
      "CrmGeo":"CAN",
      "PackageName":"CDSStarterPortal[LCID:1033]",
      "PackageId":"6c85e391-d7b9-4fc3-aeb0-5a81a2209331",
      "Lcid":"1033",
      "NumberOfTimesProvisioningTried":1,
      "ResourceGroupName":"pp-hostingrg-d798f9ff-bea5-4737-8234-544c5894e659",
      "PrimaryHostingPlan":"sf-f8a7f41f-9378-4c3b-a707-388476b03d7b-CAc",
      "SecondaryHostingPlan":null,
      "PrimaryWebApp":"site-cfdc126f-c2a6-484b-b52a-06943bab2d60-CAc",
      "SecondaryWebApp":null,
      "TrafficManager":null,
      "PortalType":"PowerPortal",
      "HostNames":"handlebars-cds-preview.powerappsportals.com",
      "CustomHostNames":"",
      "EarlyUpgradeOn":false,
      "PrimaryCertificateExpirationTime":"7/17/2021 9:06:23 AM",
      "WebsiteId":"f46b70cc-580b-4f1a-87c3-41deb48eb90d",
      "PartitionKey":"a505f8b4-1b44-4e0a-86d3-213825c01837",
      "RowKey":"cfdc126f-c2a6-484b-b52a-06943bab2d60",
      "Timestamp":"2019-08-06T17:25:03.4160305+00:00",
      "IsStacked":true,
      "Subdomain":"handlebars-cds-preview",
      "PackageStatus":"Installed",
      "CategoryBrowse":{  
         "State":true,
         "Reason":""
      },
      "CategoryDeleteAllowed":{  
         "State":true,
         "Reason":""
      },
      "CategoryOperationAllowed":{  
         "State":true,
         "Reason":""
      }
   }
]

There are likely lots of others as well that will need to be discovered

Eventually you will hopefully hear that podcast…working its way through the necessary hurdles 😊.