2 minute read

Add App to Catalog

Code Example

// Get the sppkg file
var fileContent = $REST.Web().getFileByServerRelativeUrl("/sites/dev/siteassets/pkgs/demo-webpart.sppkg").content().execute(function(data) {
    // Add the app file
    var appFile = $REST.Web().TenantAppCatalog().add("demo-webpart.sppkg", true, content).executeAndWait();

    // Get the context for the app catalog, this is required since we are doing a cross site-collection request
    $REST.ContextInfo.getWeb("/sites/appcatalog").execute(function(ctx) {
        // Get the app
        $REST.Web("/sites/appcatalog", { requestDigest: ctx.GetContextWebInformation.FormDigestValue }).TenantAppCatalog().AvailableApps()
            .query({ Filter: "Title eq 'demo-webpart-client-side-solution'" }).execute(function (apps) {
                // Get the app
                var app = apps.results[0];
                if(app == null) { return; }

                // Deploy the app
                app.deploy().execute(function (response) {
                    // App is deployed
                    console.log("The app has been deployed.");
                }, true)
        });
    });
});

Tenant App Catalog

The tenant app catalog is available from the ‘Web’ property.

  • add(overwrite: boolean, url: string, content: ArrayBuffer):File
    • Method to add an app to the catalog
  • AvailableApps(): TenantApps
    • List available packages from tenant app catalog
  • AvailableApps(‘guid’): TenantApp
    • Returns an available package from the tenant app catalog
  • getById(‘guid’): TenantApp
    • Returns an available package from the tenant app catalog
  • SiteCollectionAppCatalogsSites: any
    • Need to find the documentation for this property

Tenant Apps

  • getById(‘guid’): TenantApp
    • Returns an available package from the tenant app catalog

Tenant App

Properties

  • AppCatalogVersion: string
    • The app version.
  • CanUpgrade: boolean
    • Flag indicating an upgrade is available.;
  • CurrentVersionDeployed: boolean
    • Flag indicating if the current version is deployed.
  • Deployed: boolean
    • Flag indicating if the app is deployed.
  • ID: string
    • The app id.
  • InstalledVersion: string
    • The installed version.
  • IsClientSideSolution: boolean
    • Flag indicating if this is a client-side solution.
  • Title: string
    • The app title.

Methods

  • deploy()
    • Enable solution to be available to install to specific sites. This API is designed to be executed in the context of the tenant app catalog site.
  • install()
    • Install a solution package with specific identifier from tenant app catalog to the site based on URL context. This REST call can be executed in the context of the site where the install operation should happen.
  • remove()
    • Remove the solution package from the tenant app catalog. This API is designed to be executed in the context of the tenant app catalog site.
  • retract()
    • Retract solution to be available from the sites. This API is designed to be executed in the context of the tenant app catalog site.
  • uninstall()
    • Uninstall a solution package from the site. This REST call can be executed in the context of the site where the uninstall operation should happen.
  • upgrade()
    • Upgrade a solution package from the site to a newer version available in the tenant app catalog. This REST call can be executed in the context of the site where the upgrade operation should happen.