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.