From 7068bf124402103bdd8cc1eb429da1d9498f03cc Mon Sep 17 00:00:00 2001 From: Asish Kumar Date: Fri, 24 Apr 2026 03:00:16 +0530 Subject: [PATCH 1/2] Updates CLI API usage docs. Closes #5699 --- docs/docs/user-guide/use-cli-api.mdx | 29 ++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/docs/docs/user-guide/use-cli-api.mdx b/docs/docs/user-guide/use-cli-api.mdx index 75d37090190..68a56087156 100644 --- a/docs/docs/user-guide/use-cli-api.mdx +++ b/docs/docs/user-guide/use-cli-api.mdx @@ -7,6 +7,31 @@ sidebar_position: 16 Typically, you'll work with CLI for Microsoft 365 in a command line. You'll either call specific commands or build automation scripts to combine multiple tasks. But if you're building software, you might want to use CLI for Microsoft 365 from your code. +## Configure your Node.js app + +CLI for Microsoft 365 is published as an ES module. To use the API in a Node.js app, configure your project to use ES modules. + +```json title="package.json" +{ + "type": "module", + "dependencies": { + "@pnp/cli-microsoft365": "latest" + } +} +``` + +Install the dependency by executing: + +```sh +npm install @pnp/cli-microsoft365 +``` + +You can then import the API from a `.js` file and run the app with Node.js: + +```sh +node index.js +``` + ## Integrate CLI for Microsoft 365 in your app If you build apps in Node.js, you can integrate CLI for Microsoft 365 using its API. This API lets you call any of the CLI's commands. The following examples show how you could call several CLI for Microsoft 365 commands in a Node.js app: @@ -34,8 +59,8 @@ try { } const siteUrl = sites[0].Url; - // m365 spo web get --webUrl https://contoso.sharepoint.com/sites/project-x --withGroups - const siteInfo = await executeCommand('spo web get', { webUrl: siteUrl, withGroups: true }); + // m365 spo web get --url https://contoso.sharepoint.com/sites/project-x --withGroups + const siteInfo = await executeCommand('spo web get', { url: siteUrl, withGroups: true }); console.log(siteInfo.stdout); From c6dd3d6bd7d14b1fff6eac9da2af8831a92b4bd4 Mon Sep 17 00:00:00 2001 From: Asish Kumar Date: Mon, 4 May 2026 11:46:36 +0530 Subject: [PATCH 2/2] Address CLI API docs review feedback --- docs/docs/user-guide/use-cli-api.mdx | 27 +-------------------------- 1 file changed, 1 insertion(+), 26 deletions(-) diff --git a/docs/docs/user-guide/use-cli-api.mdx b/docs/docs/user-guide/use-cli-api.mdx index 68a56087156..6fe608e2fcd 100644 --- a/docs/docs/user-guide/use-cli-api.mdx +++ b/docs/docs/user-guide/use-cli-api.mdx @@ -7,34 +7,9 @@ sidebar_position: 16 Typically, you'll work with CLI for Microsoft 365 in a command line. You'll either call specific commands or build automation scripts to combine multiple tasks. But if you're building software, you might want to use CLI for Microsoft 365 from your code. -## Configure your Node.js app - -CLI for Microsoft 365 is published as an ES module. To use the API in a Node.js app, configure your project to use ES modules. - -```json title="package.json" -{ - "type": "module", - "dependencies": { - "@pnp/cli-microsoft365": "latest" - } -} -``` - -Install the dependency by executing: - -```sh -npm install @pnp/cli-microsoft365 -``` - -You can then import the API from a `.js` file and run the app with Node.js: - -```sh -node index.js -``` - ## Integrate CLI for Microsoft 365 in your app -If you build apps in Node.js, you can integrate CLI for Microsoft 365 using its API. This API lets you call any of the CLI's commands. The following examples show how you could call several CLI for Microsoft 365 commands in a Node.js app: +If you build apps in Node.js, you can integrate CLI for Microsoft 365 using its API. CLI for Microsoft 365 is published as an ES module, so an app that imports it should use ES modules as well. To add the package to your app, execute `npm install @pnp/cli-microsoft365`. This API lets you call any of the CLI's commands. The following examples show how you could call several CLI for Microsoft 365 commands in a Node.js app: ```javascript import { executeCommand } from '@pnp/cli-microsoft365';