Skip to content

Commit ae00aba

Browse files
Updates CLI API usage docs. Closes #5699
1 parent 52da392 commit ae00aba

1 file changed

Lines changed: 27 additions & 2 deletions

File tree

docs/docs/user-guide/use-cli-api.mdx

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,31 @@ sidebar_position: 16
77

88
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.
99

10+
## Configure your Node.js app
11+
12+
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.
13+
14+
```json title="package.json"
15+
{
16+
"type": "module",
17+
"dependencies": {
18+
"@pnp/cli-microsoft365": "latest"
19+
}
20+
}
21+
```
22+
23+
Install the dependency by executing:
24+
25+
```sh
26+
npm install @pnp/cli-microsoft365
27+
```
28+
29+
You can then import the API from a `.js` file and run the app with Node.js:
30+
31+
```sh
32+
node index.js
33+
```
34+
1035
## Integrate CLI for Microsoft 365 in your app
1136

1237
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 {
3459
}
3560

3661
const siteUrl = sites[0].Url;
37-
// m365 spo web get --webUrl https://contoso.sharepoint.com/sites/project-x --withGroups
38-
const siteInfo = await executeCommand('spo web get', { webUrl: siteUrl, withGroups: true });
62+
// m365 spo web get --url https://contoso.sharepoint.com/sites/project-x --withGroups
63+
const siteInfo = await executeCommand('spo web get', { url: siteUrl, withGroups: true });
3964

4065
console.log(siteInfo.stdout);
4166

0 commit comments

Comments
 (0)