Registry / storage / sprestlib

sprestlib

JSON →
library1.9.0jsnpmunverified

A pure JavaScript library for SharePoint REST web services (v1.9.0, last release 2021). Provides promise-based CRUD for lists, files, folders, users, and site properties across SharePoint 2013, 2016, and Online. Unlike CSOM, it has no dependency on SharePoint client DLLs, enabling lightweight SPAs and add-ins. OData v3 compatible.

npm install sprestlib
INSTALL
IMPORT
SIG · SPRESTLIB
S
sprestlib
storagejavascriptv1.9.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

sprLib
import sprLib from 'sprestlib'
import { sprLib } from 'sprestlib'
Default export only; named import will give undefined.
sprLib.rest
const result = await sprLib.rest({ url: '/_api/web/lists' })
const result = await sprLib.rest('/_api/web/lists')
Options object required, not a string URL.
sprLib.list
import sprLib from 'sprestlib'; const items = await sprLib.list('My List').items()
const { list } = require('sprestlib'); list('My List').items()
Requires default import. CommonJS require patterns work but the destructure is wrong.

Shows default import, fetching list items with CAML query, and arbitrary REST call.

// ESM import (default) import sprLib from 'sprestlib'; // Get list items with inline CAML query const items = await sprLib.list('Announcements').items({ query: "<View><Query><Where><Eq><FieldRef Name='Title'/><Value Type='Text'>Hello</Value></Eq></Where></Query></View>", select: ['Title', 'Modified'], top: 10 }); // Execute arbitrary REST call const site = await sprLib.rest({ url: `${_spPageContextInfo.webAbsoluteUrl}/_api/web`, headers: { 'Accept': 'application/json;odata=verbose' } }); console.log(items, site);
Debug
Known issues
breakingIn v2.0, sprLib.rest() will change from accepting a string to an options object only. String usage deprecated since v1.8.
fix
Always pass an options object: sprLib.rest({ url: '...' })
affects: >=1.8
deprecatedsprLib.list().cols() and .info() are deprecated; use sprLib.rest() to call /_api/web/lists/getbytitle('...')/fields or /_api/web/lists/getbytitle('...') directly.
fix
Replace with sprLib.rest() calls for better future compatibility.
affects: >=1.7
gotchaWhen using sprLib.list().items(), the 'query' string must be valid CAML XML wrapped in a <View> tag. Many errors come from malformed CAML.
fix
Ensure CAML starts with <View><Query>...</Query></View> and is properly escaped.
affects: >=0.1
gotchaOData v3 verbose JSON format is used by default. If your SharePoint Online expects minimal metadata, set headers: { 'Accept': 'application/json;odata=minimalmetadata' }.
fix
Explicitly set Accept header in sprLib.rest() options when needed.
affects: >=1.0
breakingv2.0 will drop support for Internet Explorer 11 due to missing Promise polyfills. Consider bundling a polyfill if targeting IE11.
fix
Include core-js or a Promise polyfill for IE11.
affects: >=2.0
Errors
Common errors & fixes
TypeError: sprLib is not a function
Importing as named import instead of default import.
fix
Use: import sprLib from 'sprestlib' (no curly braces)
Unable to get property 'items' of undefined or null reference
Calling sprLib.list() without importing sprLib correctly (e.g., using require('sprestlib').sprLib).
fix
Ensure default import: const sprLib = require('sprestlib'); then sprLib.list('List').items();
The query string is not valid CAML: Expected '<View>' root element.
CAML query not wrapped in <View> tag.
fix
Wrap CAML: '<View><Query><Where>...</Where></Query></View>'
401 Unauthorized - The request requires user authentication
Not running within a SharePoint context or missing authentication headers.
fix
Ensure the script runs on a SharePoint page with _spPageContextInfo available, or pass proper digest in headers.
Upgrade
Version history
1.9.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
29 hits · last 30 days
node
26
Resources