Install add-ins In SharePoint Using Office 365 CLI

Office365 CLI is a native cross-platform command line interface, similar to the Azure CLI. You can install this on any platform (Windows, MacOS or Linux) and manage your Office 365 tenant from the command line. SharePoint add-ins are designed to integrate seamlessly into the SharePoint environment and can be packed full with the time-saving tools. SPFx Web parts/Extensions and SharePoint provider hosted apps are the two major add-in models which are used in SharePoint Online. Now let’s see how to use Office 365 CLI to work with SharePoint Online apps.

Prerequisite

You'll first need to make sure the Office 365 CLI is installed on your machine. Verify this by running office365 or o365 from the command line. If not follow the below steps to install Office 365 CLI.

  • Download and Install Node.js in your platform from this link. Make sure that you’re installing a version above 6.
  • Office 365 CLI is distributed as a Node.js package and you can install it by running the below command.
    1. npm install -g @pnp/office365-cli@latest  

Connect to Office 365 CLI

  • Run “office365” or “o365” in your command line interface. I am using Windows command prompt to do it.
  • Connect to SharePoint online tenant using below command.

    1. spo connect https://yourtenant-admin.sharepoint.com  

It will give you the URL and auth code, you should provide the code and log into the SharePoint Online site using your authentication credentials.

Office 365

Enter the auth code after opening "https://microsoft.com/devicelogin", then log in using your Office 365 credentials.

                                        
 
Move add-ins to app catalog

To start with this installation, you have to create and package the SharePoint add-ins;  it can be either a SPFx or SharePoint provider hosted app. After packaging, you can move the apps to the app catalog using the below commands.

  1. spo app add -p "SPFX-Extensions-Header\sharepoint\solution\spfx-extensions-header.sppkg" –overwrite  
  2. spo app add -p "C:\Users\ADMIN\Downloads\HF.Forms.Local.app" –overwrite  
 

SPFx apps(sppkg) can be deployed and installed using this single command, by using “skipFeatureDeployment” feature which makes the app available in all the Site Collections. skipFeatureDeployment is configured in package-solution.json file. You can see the changes in the app catalog.

Office 365 

Install add-ins

To install the add-in, pick the ID of the app from app catalog using the below command

  1. spo app list   

Office 365 

Pick the app id which needs to be installed and run the below command.

  1. spo app install -i c2b86b2f-44fd-45aa-a4c4-1bdfbb3fb420 -s "https://<your_tenant>.sharepoint.com/sites/demo/ "  

In this command, -s resembles the target site in which we have to install the app.

After installation, see the installed app in your site.

 Office 365
Limitations

To install provider hosted add-ins we have to make sure that we have implemented app renew process. If not, you can use this link to perform it. Also, if the app is given with Tenant level or permissions related to the tenant, the app should be approved by the app catalog admins to install it.

Hope this article brings you the SharePoint add-in deployment automation technique. Please feel free to give your thoughts on the article through the comment section below.

X

Build smarter apps with Machine Learning, Bots, Cognitive Services - Start free.

Start Learning Now