(SharePoint-Y not use this lib forREQuestS!)
Spyreqs is a library that contains general purpose methods useful for interacting with the sharepoint lists and files. It is dependent on the jQuery. It will work with a Sharepoint auto-hosted app even without the hostUrl & appUrl URLquery properties!
With spyreqs, you can manage:- Web, (Host/App web)
- Lists,
- List items,
- Inheritance,
- Users,
- Permissions,
- 'Recent' elements node,
- Recycle Bin
- Files
- The rest property which is an object that contains rest methods
- The jsom property which is an object that contains jsom methods
- The utils property which is an object that contains general purpose methods
Both spyreqs.rest and spyreqs.jsom contains methods that refers either to the Application scope or to the Host Site scope. If the method is for use in the App scope then it contains 'App' in its name otherwise it contains 'Host'. Because description, parameters and results of both app methods and host methods are identical for each case there will be documentation for one of them. All spyreqs.rest and spyreqs.jsom methods return jQuery promises which are compatible with Q promises library and the subset of Q contained in Angular Framework.
rest.
getHostLists, getAppLists
getHostListByTitle, getAppListByTitle
getHostListItems, getAppListItems
getHostListFields, getAppListFields
createHostList, createAppList
addHostListItem, addAppListItem
addAppFolder, addHostFolder
deleteHostListItem, deleteAppListItem
updateHostListItem, updateAppListItem
updateHostListField, updateAppListField
addHostListField, addAppListField
breakRoleInheritanceOfHostList, breakRoleInheritanceOfAppList
resetRoleInheritanceOfHostList, resetRoleInheritanceOfAppList
breakRoleInheritanceOfHostWeb, breakRoleInheritanceOfAppWeb
resetRoleInheritanceOfHostWeb, resetRoleInheritanceOfAppWeb
addHostFile, addAppFile
addHostBinaryFile, addAppBinaryFile
getHostFolderFiles
getHostFolderFolders
addHostFolder
getHostListItemAttachments, addHostListItemAttachment
getSiteUsers, getCurrentUser
updateHostList
givePermissionToGroupToAppList
getHostListRoleAssigmnent, deleteAppFolder
postAsynq, getAsynq
jsom.
checkHostList, checkAppList
getHostList, getAppList
deleteHostList, deleteAppList
recycleHostList, recycleAppList
recycleHostListItem, recycleAppListItem
getHostListItems, getAppListItems
addHostListItem, addAppListItem
updateAppListItem, updateHostListItem
getAppListItemsPaginated, getHostListItemsPaginated
updateHostListItemsPaginated, recycleHostListItemsPaginated
deleteHostListItemsPaginated, deleteAppListItemsPaginated
removeHostRecentElemByTitle, removeAppRecentElemByTitle
createHostList, createAppList
getAppListPermissions
getHostListItemHasUniquePerms, getAppListItemHasUniquePerms
getAllHostListsHasUniquePerms, getAllAppListsHasUniquePerms
getHostProperty, getAppProperty
setHostProperty, setAppProperty
You can use $filter,$select and so on. Full documentation
description: gets all the Lists from the Host Site that the App was installed.
parameters:
- string query (optional): the query to execute
spyreqs.rest.getHostLists(query).then(function(data){
var lists = data.d.results;
//do something with the lists
});
**parameters:**
- string listTitle (required) : the title of the list to get
- string query (optional): the query to execute
returns: a promise which when resolved contains an object the list.
spyreqs.rest.getHostListByTitle(listTitle,query).then(function(data){
var list = data.d;
//do something with the list
});
**parameters:**
- string listTitle (required): the title of the list
- string query (optional): the query to execute on items
spyreqs.rest.getHostListItems(listTitle,query).then(function(data){
var items = data.d.results;
//do something with the items
});
description: gets the Fields of a List from the Host Site.
parameters:
- string listTitle (required): the title of the list
- string query (optional) : the query to execute on Items
spyreqs.rest.getHostListFields(listTitle,query).then(function(data){
var fields = data.d.results;
//do something with the fields
});
description: gets the Fields of an App List. Parameters and return value same as spyreqs.rest.getAppListFields.
**parameters:**
- object list (required) : the list to create. the list object must have the properties
- string Title : the list Title
- number Template : the list Template number(for a generic SP List 100)
var list={Title:"Demo",Template:100};
spyreqs.rest.createHostList(list).then(function(data){
var createdList = data.d;
},function(error){
//handle the error
});
**parameters:**
- string listTitle (required): the title of the List to which the item should be added
- object item (required) : the item to add.The item object must have the properies
- string Title : the Title of the item
- objext __metadata: the metadata object must have the property
- string type : the type of the item
var listTile="Demo", item = { Title:"DemoItem", __metadata:{ type:"SP.Data.DemoListItem" } };
spyreqs.rest.addHostListItem(listTitle,item).then(function(data){ var addedItem = data.d; },function(error){ //handle the error });
<h3>spyreqs.rest.addAppListItem</h3>
**description:** adds an App List Item. Parameters and return value same as spyreqs.rest.addAppListItem.
<h3>spyreqs.rest.deleteHostListItem</h3>
**description:** deletes an Item in a Host List. <br>
**parameters:**
<ul>
<li>string listTitle (required) : the title of the List</li>
<li>string itemId (required) : the id of the Item to delete</li>
<li>string etag (optional) : the etag property of the item. if not provided defaults to "*"</li>
</ul>
**returns:**A promise that is resolved when the item is deleted or rejected if the deletion fails.
```javascript
spyreqs.rest.deleteHostListItem(listTitle,itemId,"*").then(function(){
//successfully deleted
},function(error){
//handle the error
});
**parameters:**
- string listTitle (required) : the title of the List
- object item (required) : the item to update. Must have the properties
- string Id : the guid of the item
- any property of the item you want to change
- object __metadata : the metadata object must have the properties
- string type: the type of the object e.g. "SP.Data.DemoListItem"
- string etag (optional) : defaults to "*"
spyreqs.rest.updateHostListItem(listTitle,item).then(function(){ //successfully updated },function(error){ //handle the error });
<h3>spyreqs.rest.updateAppListItem</h3>
**description:** updates an Item in an App List. Parameters and return value same as spyreqs.rest.updateHostListItem.
<h3>spyreqs.rest.updateHostListField</h3>
**description:** updates a Field to a Host List. <br>
**parameters:**
<ul>
<li>string listTitle (required) : the Title of the List</li>
<li>object field (required) : the field to update.The field object must have the properties
<ul>
<li>string Id:the guid of the field</li>
<li>object __metadata: the metadata object must have the properties
<ul>
<li>string type (required): the type of the field e.g ""SP.Field""</li>
<li>string etag (optional): defaults to "*"</li>
</ul>
</li>
</ul>
</li>
</ul>
<h3>spyreqs.rest.updateAppListField</h3>
**description:** updates a Field to an App List. Parameters and return value same as spyreqs.rest.updateHostListField.
<h3>spyreqs.rest.addHostListField</h3>
**description:** adds a Field to a Host List. <br>
**parameters:**
<ul>
<li>string listGuid (required) : the guid of the list</li>
<li>string fieldType (optional) : the type of the field, defaults to the generic "SP.Field"</li>
<li>object field (required) : the field to add. The object must have the properties
<ul>
<li>string Title : the title of the field</li>
<li>number FieldTypeKind : <a href="http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.client.fieldtype.aspx">documentation about FieldTypeKind</a></li>
<li>boolean Required: if the field is required or not</li>
<li>boolean EnforceUniqueValues</li>
<li>string StaticName: the static name of the field</li>
</ul>
</li>
</ul>
**returns:** A promise that contains the added field
```javascript
spyreqs.rest.addHostListField(listGuid, field, fieldType).then(function(data){
var field = data.d;
},function(error){
//handle the error
});
**parameters:** empty
**returns:** A promise that contains an object with info about the current user, like Email and Id ```javascript
spyreqs.rest.getCurrentUser().then(function(data){ var currentUser = data.d; },function(error){ //handle the error });
<h3>spyreqs.rest.getHostFile</h3>
**description:** gets a File from the Host Site.(not tested on binary files)<br>
**parameters:**
<ul>
<li>string fileUrl: the relative file url</li>
</ul>
**returns:** A promise that contains the file.
```javascript
spyreqs.rest.getHostFile(fileUrl).then(function(data){
var file = data;
},function(error){
//handle the error
});
Parameters and return value same as spyreqs.rest.getHostFile. **description:** adds a File to the Host Site.(not tested on binary files)
**parameters:**
- string folderPath: the relative url of the folder to which the file should be added
- string fileName
- file: the file to add
spyreqs.rest.addHostFile(fileUrl).then(function(data){ var file = data; },function(error){ //handle the error });
<h3>spyreqs.rest.addAppFile</h3>
**description:** adds a File to the App Site.(not tested on binary files)<br>
Parameters and return value same as spyreqs.rest.addHostFile.
<h3>spyreqs.rest.getSiteUsers</h3>
**description:** gets all the users of the host Site<br>
**parameters:** empty <br>
**returns:** A promise that contains an array with the users of the site.
```javascript
spyreqs.rest.getSiteUsers(fileUrl).then(function(data){
var siteUsers = data.d.results;
},function(error){
//handle the error
});
**description:** checks wether a Host list exists or not.
**parameters:**
- string listTitle:the list Title
**description:** gets the items of a Host List.
**parameters:**
- string listTitle:the list Title
- string query : the query to execute
spyreqs.jsom.getHostListItems(listTitle,query).then(function(resultCollection) { var listItemEnumerator = resultCollection.getEnumerator(), out=" ";
while (listItemEnumerator.moveNext()) {
var oListItem = listItemEnumerator.get_current();
out += oListItem.get_item('ClassStudentGroupID');
}
alert(out);
}, function(error) { alert('getAppListItems request failed. ' + error.args.get_message() + '\n' + error.args.get_stackTrace()); });
<h3>spyreqs.jsom.getAppListItems</h3>
**description:** gets the items of an App List. Parameters and return value same as spyreqs.jsom.getHostListItems.<br>
<h3>spyreqs.jsom.addHostListItem</h3>
**description:** adds an item to a Host List.<br>
**parameters:**
<ul>
<li>string listTitle:the list Title</li>
<li>object itemObj : the item to add</li>
</ul>
**returns:** A promise that contains the id of the created item
```javascript
spyreqs.jsom.addHostListItem("My List", {"Title":"my item", "Score":90})
.then(function(itemId) {
alert("item was added, id:"+itemId);
},
function(error) {
alert('addHostListItem request failed. ' + error.args.get_message() + '\n' + error.args.get_stackTrace());
});
**parameters:**
- string listTitle:the list Title
- object itemObj : the item contents to update
- number itemId : the item id
**parameters:**
- object listObj:the list to create
spyreqs.jsom.createHostList(listObj) .then(function(data){ //success },function(error){ //error });
<h3>spyreqs.jsom.createAppList</h3>
**description:** creates a List to the App Site.Parameters and return value same as spyreqs.jsom.createHostList.<br>
<h3>spyreqs.jsom.getTestHostContext</h3>
**description:** When you need spyreqs to have a job done with spyreqs, but there is not a method for what you need, you can use getTestHostContext and getTestAppContext for quick jsom init.<br>
**returns:** An objects that contains jsom appContextSite and context objects
```javascript
var file, item, c, oWeb, oList;
function renameHostFile(listTitle, fileItemID, newName) {
c = spyreqs.jsom.getTestHostContext();
oWeb = c.appContextSite.get_web();
oList = oWeb.get_lists().getByTitle(listTitle);
item = oList.getItemById(fileItemID);
file = item.get_file();
file.checkOut();
c.context.load(item);
c.context.load(file);
c.context.executeQueryAsync( OnLoadSuccess, fail );
}
function OnLoadSuccess(sender, args) {
console.log(file.get_name() + " ok");
item.set_item("Title","oktitleokefd");
file.set_item("Name","okefd");
item.update();
file.checkIn();
c.context.load(item);
c.context.load(file);
c.context.executeQueryAsync( OnLoadSuccess2, fail );
}
function fail(sender, args) {
console.log('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}
renameHostFile("GP_iSprings", 33, "renamed-ok.txt");
**description:** gets the url parameters.
**parameters:** empty.
**returns:** an object with the url parameters as key, value ```javascript //for example if the url is http://www.example.com?user=adam&email=adam@gmail.cmom //then var params = spyreqs.utils.urlParamsObj(); //params = {user:adam,email:adam@gmail.com} ``` **description:** builds a query string
**parameters:**
- string str : the string to which the query string is added
- string param : the parameter to add to the query string
- string or number or boolean val : the value of the parameter to add to the query string
and if it has the log method
**parameters:**
- anything you want to log
**parameters:**
- string query:the query to execute