1.1.0 • Published 12 months ago

sharepoint-api-wrapper v1.1.0

Weekly downloads
-
License
ISC
Repository
gitlab
Last release
12 months ago

Sharepoint API Wrapper

Sharepoint API Wrapper is a simple library used to interact with a Sharepoint site.

How to use it ?

Installation

First of all, you need to install the library.

npm install sharepoint-api-wrapper

Importing

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');

Configuration

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.

parametertyperequireddescription
authOptionsIAuthOptionstrueIAuthOptions from node-sp-auth
urlstringtrueUrl of Sharepoint
siteNamestringtrueName of Sharepoint site*
baseFolderstringfalseUsed 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)

Methods

.getClientContext()

Get api client context.

Returns Promise<SpClientContext | undefined>

.getSiteInfos()

Get site informations.

Returns Promise<SpWeb | undefined>

.getFolders(folderRelativeUrl)

List folders from a folder url.

parametertyperequireddescription
folderRelativeUrlstringfalsebaseFolder by default

Returns Promise<SpFolder[] | undefined>

.getFolder(folderRelativeUrl)

Get a folder from a folder url.

parametertyperequireddescription
folderRelativeUrlstringfalsebaseFolder by default

Returns Promise<SpFolder | undefined>

.createFolder(folderName, folderRelativeUrl)

Create a new folder.

parametertyperequireddescription
folderNamestringtrueName of folder to create
folderRelativeUrlstringfalseWhere to create folder (baseFolder by default)

Returns Promise<SpFolder | undefined>.

.deleteFolder(folderRelativeUrl)

Delete an existing folder.

parametertyperequireddescription
folderRelativeUrlstringtrueThe relative url of folder to delete

Returns Promise<void>

.getFiles(folderRelativeUrl)

Lists files from a folder.

parametertyperequireddescription
folderRelativeUrlstringfalsebaseFolder by default

Returns Promise<SpFile[] | undefined>

.getFile(fileRelativeUrl)

Get a file from it's relative url.

parametertyperequireddescription
fileRelativeUrlstringtrueRelative url of file to get

Returns Promise<SpFile | undefined>

.downloadFile(fileRelativeUrl)

Download a file from it's relative url.

parametertyperequireddescription
fileRelativeUrlstringtrueRelative url of file to download

Returns Promise<SpDownloadFile | undefined>

.uploadFile(fileName, file, folderRelativeUrl)

Download a file from it's relative url.

parametertyperequireddescription
fileNamestringtrueName of the file to upload with extension
fileBuffertrueContent of the file to upload
folderRelativeUrlstringtrueRelative url of folder where to upload

Returns Promise<SpFile | undefined>

.moveFile(fileRelativeUrl, folderRelativeUrl)

Move a file to another folder.

parametertyperequireddescription
fileRelativeUrlstringtrueRelative url of the file to move
folderRelativeUrlstringtrueRelative url of folder where to move the file

Returns Promise<void>

.deleteFile(fileRelativeUrl)

Delete a file.

parametertyperequireddescription
fileRelativeUrlstringtrueRelative url of the file to delete

Returns Promise<void>

Interfaces

SharepointApiOptions

propertytyperequireddescription
authOptionsIAuthOptionstrueIAuthOptions from node-sp-auth
urlstringtrueUrl of the Sharepoint
siteNamestringtrueName of Sharepoint site*
baseFolderstringfalseUsed 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)

SpDownloadFile

propertytypedescription
fileNamestringName of the file with extension
bufferBufferContent of the file
1.1.0

12 months ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago