Question

Is there a way to programmatically get the App Catalog site URL in a SharePoint Framework (SPFx) Web Part? I'd like to read/set the SharePoint Tenant Properties in my Web Part. However, we need to know the App Catalog site URL in order to use the @pnp library or make REST call.

Since there is only one App Catalog site for each tenant, is there a way we can find its URL using JavaScript instead of asking users' input?

Thanks.

Was it helpful?

Solution

When it comes to SPFx, Waldek to the rescue !

You need to make GET request to an undocumented endpoint /_api/SP_TenantSettings_Current which will give you the App Catalog Url.

Minimal code for that is:

var appCatalogUrl = "https://<your-tenant>.sharepoint.com/_api/SP_TenantSettings_Current";
this.context.spHttpClient.get(appCatalogUrl,
  SPHttpClient.configurations.v1,
  {
    headers: {
      'Accept': 'application/json;odata=nometadata',
      'odata-version': ''
    }
  })
  .then((response: SPHttpClientResponse) => {
    response.json().then((value: any) => {
      console.log(value);

      var appCatalogUrlValue = value.CorporateCatalogUrl;

      if(appCatalogUrlValue && appCatalogUrlValue.length > 0){
        // do some stuff using it
      }       
});

Reference - Get the tenant app catalog URL using the REST API

As mentioned in the blog, it is undocumented and looks like it is reverse engineered from the tenantSettings.CorporateCatalogUrl CSOM property. So, you can use it in production at your own risk !

Best option would be to ask for user's input if you are only using REST, because since the API is in preview it might be subject to change by Microsoft which can break your solution.

If its an option for you to use CSOM, would suggest that you use the TenantSettings.CorporateCatalogUrl property itself since it is defined in the CSOM code itself.

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top