很多时候我们需要对SharePoint的custom list或document library进行相关操作,接下来将了解一下如何通过rest api对SharePoint进行查询、条件搜索、排序、分页等操作(适用于SharePoint 2010/2013/2016/2019/online)
示例:weburl/_api/web/lists/getbytitle('list name')/items
语法:$select=Field1, Field2, Field3
示例:weburl/_api/web/lists/getbytitle('list name')/items?$select=ID,Title
语法:$orderby=(Column Internal Name order)
升序: weburl/_api/web/lists/getbytitle('list name')/items?$select=ID,Title&$orderby= Title asc
降序: weburl/_api/web/lists/getbytitle('list name')/items?$select=ID,Title&$orderby= Title desc
语法:$filter=(Column Internal Name operator value)
示例:
Filter by Title | weburl/_api/web/lists/getbytitle('list name')/items?$filter= Title eq ‘parth' |
Filter by ID | weburl/_api/web/lists/getbytitle('list name')/items?$filter=ID eq 2 |
Filter by Date | weburl/_api/web/lists/getbytitle('list name')/items?$filter=Start_x0020_Date le datetime'2016-03-26T09:59:32Z' |
Multiple Filters | weburl/_api/web/lists/getbytitle('list name')/items?$filter=( Modified le datetime'2016-03-26T09:59:32Z') and (ID eq 2) |
Title name starts with the letter P | weburl/_api/web/lists/getbytitle(‘'list name')/items?$filter=startswith(Title,‘P’) |
Return all items from the 'list name' list modified in May | weburl/_api/web/lists/getbytitle(‘'list name')/items? $filter=month(Modified) eq 5 |
Supported | Not supported |
Numeric comparisons
|
|
String comparisons
|
|
Date and time functions
|
|
语法:$top Count
示例:weburl/_api/web/lists/getbytitle('list name')/items?$top 5
lookup字段(city为lookup表)示例:weburl/_api/web/lists/getbytitle('list name')/items?$select=ID,Title,city/Id&$expand= city/Id
person字段(Author为用户字段)示例:weburl/_api/web/lists/getbytitle('list name')/items?$select=Author/Title&$expand=Author/Id