spscript
v5.1.1
Published
ShareP0oint Rest Api Wrappers
Downloads
81
Maintainers
Readme
SPScript
Visit https://spcript.com for full documentation.
SPScript is a collection of javascript helpers for the SharePoint Rest API. Some features include...
- Easy querying of list data.
- Add and Update list items in 1 line of code.
- Easily utilize SharePoint search
- Work with the Profile Service
- Check permissions on sites and lists
- Work with CustomActions
Installation
Add the SPScript npm
package to your project
NPM
npm install spscript
Yarn
yarn add spscript
Importing
You can use SPScript in your Javascript/Typescript files with:
import SPScript from "spscript";
ProTip: Dynamically/Temporarily add SPScript to a Modern page with Dev Tools
You can enter the following into a browser console to dynamically load SPScript on a page.
let script = document.createElement("script");
script.src = "https://unpkg.com/spscript@beta/dist/spscript.browser.js";
document.head.appendChild(script);
SPScript Context
Almost everything in SPScript is based off an SPScript Context
class.
- An SPScript Context is tied to specific SharePoint site.
- You get a Context by calling
SPScript.createContext(siteUrl)
.
You get a Context by calling
SPScript.createContext(siteUrl)
.
This line of code is the entry point to almost everything SPScript provides.
let ctx = SPScript.createContext(siteUrl);
Example Usage: Get the News Pages of the specified site.
import SPScript from "spscript";
const getPublishedNews = async function (siteUrl) {
let ctx = SPScript.createContext(siteUrl);
let pages = await ctx.lists("Site Pages").findItems("PromotedState", 2);
console.log(pages); // This will show an Array of Page List Items
return pages;
};
Throughout the docs you'll see a variable, ctx
, representing an instance of an SPScript Context
.
Troubleshooting
If you are using Typescript, you may have to use the syntax:
import * as SPScript from "spscript";
If you don't like that, add "allowSyntheticDefaultImports": true
to your tsconfig.json
.