g10-spapi
v1.4.4
Published
Helper library for SharePoint API.
Downloads
33
Readme
g10-spapi
Helper library for SharePoint API.
import SpBuilder from 'g10-spapi'
const sp = new SpBuilder()
Configure an instance of axios
import { axiosManager } from 'g10-spapi'
axiosManager.setInstance('https://myportal.mydomain.com/sites/MySite/', { cookie: global.data.cookie, timeout:10000, metadata: 'nometadata' })
axiosManager.setInstance('https://myproxy:4443/sites/MySite/', { mode: 'sp-rest-proxy' })
This library doesn't support authentification. You must suministrate a cookie for raw mode (node-sp-auth), o using sp-rest-proxy
- Basic Examples
run() --> runs the query directly to Sharepoint(raw), or vía Rest Proxy SP (sp-rest-proxy)
build() --> Give you information of the url and options.
List management
await sp.lists().queryByTitle('MyList').exist() //--> List exists.
await sp.lists().queryBy({ BaseTemplate: 100 }).run() //--> Query for list with Base Template 100
await sp.lists().add({ Title: 'MyList', DisableCommenting: true }).run() //--> List creation
await sp.lists().getByTitle('MyList').update({ DisableCommenting: false }).run() //--> List update
await sp.lists().getByTitle('MyList').del().run() //--> Delete list
...
Field/List management. Include lookups.
await sp.fields(listName).getById(r.Id).exist() // --> Field exists.
await sp.fields(listName).add({ Title: 'isActive', FieldTypeKind: eKind.Boolean, DefaultValue: true }).run() // --> Create boolean field.
await sp.fields(listName).add({ Title: 'Salary', FieldTypeKind: eKind.Number, MinimumValue: 0 }).run()
await sp.fields(listName).add({ Title: 'MyField', LookupListName: 'MyListB', EnforceUniqueValues: true }).run()
await sp.fields(listName).getByTitle('MyField').update({RelationshipDeleteBehavior: eBehavior.None }).run()
...
Items
await sp.items(listName).queryBy().run()
await sp.items(listName).add({ Title: 'Theodora Swaniawski', Numb1: 5 }).run()
await sp.items(listName).queryBy({ isActive: true }, ['Title'], { top: 7 }).run()
await sp.items(listName).queryBy({ Title: 'Hester Weimann MD', Numb1: 100, $or: { Numb1: 1000 } }).run()
await sp.items(listName).queryBy({ Created: { $gt: g.date.addNowDays(-2) } }).run()
await sp
.items(listName)
.queryBy()
.math({ $count: ['ID'], $sum: ['Numb1'], $avg: ['Numb1'], $max: ['Numb1'], $min: ['Numb1'], $countUniq: ['Tipo'], $exist: ['Title'], $trend: ['Numb1'] })
.groupBy(['Tipo'])
.run()
Views
Very similar to list, items, and fiels.
....
Search
await sp.search('text to search in portal', url: 'url to Portal.')
Utils
await sp.utils.exportList('MyList') --> Schema. Export list, no data. List, fields, views.
await sp.utils.importList('MyList')
await sp.utils.analyzeDependencies()
In de future:
** Documents
** Batch