Get the tenant app catalog URL using the REST API
When building SharePoint solutions, you might need to get the URL of the tenant app catalog. Recent changes to the SharePoint API make it very easy.
To get the URL of the tenant app catalog in your SharePoint tenant, execute the following REST call:
GET https://contoso.sharepoint.com/_api/SP_TenantSettings_Current
accept: application/json;odata=nometadata
If the request succeeds, you will get back a JSON object with a single property named CorporateCatalogUrl
, which contains the absolute URL of the tenant app catalog in your tenant:
{
"CorporateCatalogUrl": "https://contoso.sharepoint.com/sites/apps"
}
Why would you need the URL of the tenant app catalog
It’s been a common practice for a few years now, to build solutions that aren’t hosted on SharePoint servers. Instead, they should be hosted on separate servers and communicate with SharePoint using its client-side object model (CSOM) or REST APIs. In Office 365 you don’t have much choice: to guarantee the SLA of Office 365 for all their customers, Microsoft doesn’t allow us to deploy custom code on their servers. And if you’re running SharePoint on your own premises, you should consider the same practice as well.
Many SharePoint solutions we build automate specific tasks and operations typically users or even administrators perform. With the recently released application lifecycle management (ALM) APIs, these solutions are now capable even of deploying solution packages to the app catalog and installing them in sites. But to do this, you have to know the URL of the tenant app catalog.
Inconvenient tenant app catalog URL
When you create a new Office 365 tenant, it doesn’t contain a tenant app catalog and you have to create it yourself. As such, each organization can choose their own name for the app catalog site. Often, it’s named something like apps or appcatalog, but any name works, and that’s exactly the problem.
While the tenant app catalog plays a crucial role in managing SharePoint solutions, up until recently, there was no reliable way of discovering its URL reliably. One way, that was frequently used, was to use SharePoint search and try to find the app catalog site using its site template. In general, there should be only one instance of the tenant app catalog in the tenant, so using search should work, right? What if the tenant app catalog hasn’t been indexed yet or if it’s been excluded from the search index altogether?
Tenant app catalog URL, but for everyone?
Recently, there was an update to the SharePoint CSOM libraries where Microsoft added the ability to reliably retrieve the URL of the tenant app catalog. Unfortunately, if you’re not at liberty of using CSOM, you’re out of luck.
Well, not quite. It turns out, that there is another way of retrieving the URL of the tenant app catalog after all.
Get the URL of the tenant app catalog using the REST API
You can get the URL of the tenant app catalog in your tenant, by issuing a GET request to the /_api/SP_TenantSettings_Current
API. If the request succeeds, it will return a JSON object with the CorporateCatalogUrl
property that contains the absolute URL of the tenant app catalog site in your tenant.
At the moment of writing this article, this API is in preview and is not supported for use in your solutions. But if you need to get the URL of the tenant app catalog in your solutions reliably, then you have little choice but to use it and let Microsoft know that this should be a public API.