Sharepoint API Wrapper is a simple library used to interact with a Sharepoint site.
First of all, you need to install the library.
npm install sharepoint-api-wrapper
After installation of the library, you need to import it in your project.
For ESModules :
import { SharepointApi } from 'sharepoint-api-wrapper';
For CommonJS :
const { SharepointApi } = require('sharepoint-api-wrapper');
const options = {
authOptions: {
username: 'username@outlook.com',
password: 'MyPassword',
},
url: 'https://my-organization.sharepoint.com',
siteName: 'NameOfMySite',
baseFolder: 'Shared documents', // This is optionnal
};
const api = new SharepointApi(options);
All options are interfaced with SharepointApiOptions
.
parameter | type | required | description |
---|---|---|---|
authOptions |
IAuthOptions |
true |
IAuthOptions from node-sp-auth
|
url |
string |
true | Url of Sharepoint |
siteName |
string |
true | Name of Sharepoint site* |
baseFolder |
string |
false | Used to make it root folder for api wrapper |
* To get the name of your Sharepoint site, simply go at your sharepoint from your webbrowser, then go into your Sharepoint site. You can get the name in the URL (ex: https://sharepoint.com/sites/MySite
, here MySite
is the siteName)
- .getClientContext()
- .getSiteInfos()
- .getFolders(folderRelativeUrl)
- .getFolder(folderRelativeUrl)
- .createFolder(folderName, folderRelativeUrl)
- .deleteFolder(folderRelativeUrl)
- .getFiles(folderRelativeUrl)
- .getFile(fileRelativeUrl)
- .downloadFile(fileRelativeUrl)
- .uploadFile(fileRelativeUrl)
- .moveFile(fileRelativeUrl, folderRelativeUrl)
- .deleteFile(fileRelativeUrl)
Get api client context.
Returns Promise<SpClientContext | undefined>
Get site informations.
Returns Promise<SpWeb | undefined>
List folders from a folder url.
parameter | type | required | description |
---|---|---|---|
folderRelativeUrl |
string |
false | baseFolder by default |
Returns Promise<SpFolder[] | undefined>
Get a folder from a folder url.
parameter | type | required | description |
---|---|---|---|
folderRelativeUrl |
string |
false | baseFolder by default |
Returns Promise<SpFolder | undefined>
Create a new folder.
parameter | type | required | description |
---|---|---|---|
folderName |
string |
true | Name of folder to create |
folderRelativeUrl |
string |
false | Where to create folder (baseFolder by default) |
Returns Promise<SpFolder | undefined>
.
Delete an existing folder.
parameter | type | required | description |
---|---|---|---|
folderRelativeUrl |
string |
true | The relative url of folder to delete |
Returns Promise<void>
Lists files from a folder.
parameter | type | required | description |
---|---|---|---|
folderRelativeUrl |
string |
false | baseFolder by default |
Returns Promise<SpFile[] | undefined>
Get a file from it's relative url.
parameter | type | required | description |
---|---|---|---|
fileRelativeUrl |
string |
true | Relative url of file to get |
Returns Promise<SpFile | undefined>
Download a file from it's relative url.
parameter | type | required | description |
---|---|---|---|
fileRelativeUrl |
string |
true | Relative url of file to download |
Returns Promise<SpDownloadFile | undefined>
Download a file from it's relative url.
parameter | type | required | description |
---|---|---|---|
fileName |
string |
true | Name of the file to upload with extension |
file |
Buffer |
true | Content of the file to upload |
folderRelativeUrl |
string |
true | Relative url of folder where to upload |
Returns Promise<SpFile | undefined>
Move a file to another folder.
parameter | type | required | description |
---|---|---|---|
fileRelativeUrl |
string |
true | Relative url of the file to move |
folderRelativeUrl |
string |
true | Relative url of folder where to move the file |
Returns Promise<void>
Delete a file.
parameter | type | required | description |
---|---|---|---|
fileRelativeUrl |
string |
true | Relative url of the file to delete |
Returns Promise<void>
property | type | required | description |
---|---|---|---|
authOptions |
IAuthOptions |
true |
IAuthOptions from node-sp-auth
|
url |
string |
true | Url of the Sharepoint |
siteName |
string |
true | Name of Sharepoint site* |
baseFolder |
string |
false | Used to make it root folder for api wrapper |
* To get the name of your Sharepoint site, simply go at your sharepoint from your webbrowser, then go into your Sharepoint site. You can get the name in the URL (ex: https://sharepoint.com/sites/MySite, here MySite is the siteName)
property | type | description |
---|---|---|
fileName |
string |
Name of the file with extension |
buffer |
Buffer |
Content of the file |