2

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.

3

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.

  • Cool ! You can accept it as answer by ticking the checkmark besides the answer and upvote as well ! Thanks – Gautam Sheth Aug 7 '18 at 13:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.