-
Notifications
You must be signed in to change notification settings - Fork 6
Using SPScript with Node.js
Andrew Petersen edited this page Jun 22, 2017
·
1 revision
Because you can't authenticate through the browser, there is a little setup involved. You also will use the ServerDao instead of SPScript.RestDao.
- Register a SharePoint app using "_layouts/15/appregnew.aspx ". Make note of your clientId and clientSecret
- Grant your new app permissions using "_layouts/15/appinv.aspx". You can use the xml snippet below to grant site collection admin access. The key part is you set AllowAppOnlyPolicy to true.
<AppPermissionRequests AllowAppOnlyPolicy="true" >
<AppPermissionRequest Scope="http://sharepoint/content/sitecollection" Right="FullControl" />
</AppPermissionRequests>- Use the ServerDao. (This isn't exposed by default at the moment so you have to grab it the long way). Fill in the values from step 1 and the snippet below should work.
// Your path to node_modules may be different
var ServerDao = require("../node_modules/spscript/server/serverDao");
const SITE_URL = "INSERT_VALUE";
const CLIENT_ID = "INSERT_VALUE";
const CLIENT_SECRET = "INSERT_VALUE";
var dao = new ServerDao(SITE_URL, CLIENT_ID, CLIENT_SECRET);
dao.lists("Tasks")
.findItems("Status", "In Progress")
.then(items => {
console.log("In Progress:");
items.forEach(i => console.log(i.Title));
});