SharePoint REST with Angular
This AngularJS service helps to create a list item, get items that are already created, update or delete an item from the list using functions that automatically builds REST API query. This service also has a filter builder which helps to build OData query for filtering and fetching desired items from the list.
Install
NPM
npm install sharepoint-rest
Bower
bower install sharepoint-rest
Available Methods
| Method | Purpose |
|---|---|
getListItems |
Get items from lists |
createListItem |
Create a new list item |
updateListItem |
Update an existing list item |
deleteListItem |
Delete an existing list item |
getFromURL |
Get response from the provided API URL |
getSiteURL |
Get the base URL of the site or sub-site |
getFormDigestValue |
Get the Form Digest Value for that session |
Example
Getting list items
sharepointRESTService.getListItems('list_name', filter).then(function(response) {
console.log('Response :', response);
});
Creating a list item
sharepointRESTService.createListItem('list_name', data).then(function(response) {
console.log('Response :', response);
});
Updating a list item
sharepointRESTService.updateListItem('list_name', data.Id, data).then(function(response) {
console.log('Response :', response);
});
Deleting a list Item
sharepointRESTService.deleteListItem('list_name', Id).then(function(response) {
console.log('Response :', response);
});
Getting from a URL
var url = "/_api/contextinfo";
sharepointRESTService.getFromURL(url).then(function(response) {
console.log('Response :', response);
});
Sending Email
sharepointRESTService.sendEmail(emailObj);
emailObj can hold following keys:
- to
- cc
- bcc
- subject
- body
Note: to, cc, bcc keys can be hold
- string value like
sankar.animation@gmail.com - array value like
[sankar.animation@gmail.com, sankar.animation@hotmail.com]
Building filters
Following keys can be used to build OData query:
var filter = {
select: ['field_name', 'id'],
expand: {
'list_name': ['field_name1', 'field_name2']
},
orderby: 'field_name asc/desc',
filter: {
'field_name': ['lt/gt/eq/ne', 'value']
},
top : 5,
skip : 5
};