Working with lists and list items with REST.note¶
Source:
/Volumes/X9 Pro/ObsNotes/YoudaoYunNotes/默认笔记本/Working with lists and list items with REST.note.pdfConverted: 2025-12-10 12:19:25
SharePoint Add-ins
Learn how to perform basic create, read, update, and delete (CRUD) operations on lists and list items
with the SharePoint 2013 REST interface.
Last modified: September 17, 2015
Applies to: apps for SharePoint | SharePoint Add-ins | SharePoint Server 2013
This topic assumes that you are already familiar with the topics
and . It does not
provide code snippets.
The following example shows how to retrieve a specific list if you know its GUID.
Working with lists and list items with REST
Note
The name "apps for SharePoint" is changing to "SharePoint Add-ins". During the transition, the
documentation and the UI of some SharePoint products and Visual Studio tools might still use the
term "apps for SharePoint". For details, see .New name for apps for Office and SharePoint
Tip
The SharePoint Online (and on-premise SharePoint 2016 and later) REST service supports
combining multiple requests into a single call to the service by using the OData $batch query
option. For details and links to code samples, see .Make batch requests with the REST APIs
Prerequisites
Get to know the SharePoint 2013 RE
ST service Complete basic operations using SharePoint 2013 REST endpoints
Retrieving lists and list properties with REST
url:
url:
1
http://site
method: GET2
Headers:3
Authorization: "Bearer " + accessToken4
accept: "application/json;odata=verbose" or "application/atom+xml"5
6
7
The following example shows how to retrieve a specific list if you know its title.
The following XML shows an example of the list properties that are returned when you request the
XML content type.
Note
Use application/json;odata=verbose in the accept header if you want the response in
JSON. Use application/atom+xml in the accept header if you want the response in Atom
format.
url:
url:
1
http://site
method: GET2
Headers:3
Authorization: "Bearer " + accessToken4
accept: "application/json;odata=verbose" or "application/atom+xml"5
6
7
XML
000000000000
8
Policy Items.
9
26T23:15:58Z
31
26T23:15:59Z
32
llName>
33
The following example shows how to create a list.
The following example shows how to update a list by using the MERGE method.
<d:ServerTemplateCanCreateFolders
m:type="Edm.Boolean">true
37
c05709900100
38
40
41
42
Note
The ListItemEntityTypeFullName property (SP.Data.ProjectPolicyItemListItem in the previous
example) is especially important if you want to create and update list items. This value must be
passed as the type property in the metadata that you pass in the body of the HTTP request
whenever you create and update list items.
Working with lists by using REST
url:
url:
1
http://site
method: POST2
body: { '__metadata': { 'type': 'SP.List' }, 'AllowContentTypes': true,
'BaseTemplate': 100,
3
'ContentTypesEnabled': true, 'Description': 'My list description', 'Title': 'Test' }4
Headers: 5
Authorization: "Bearer " + accessToken6
X-RequestDigest: form digest value7
accept: "application/json;odata=verbose"8
content-type: "application/json;odata=verbose"9
content-length:length of post body10
11
The following example shows how to create a custom field for a list.
The following example shows how to delete a list.
url:
url:
1
http://site
method: POST2
body: { '__metadata': { 'type': 'SP.List' }, 'Title': 'New title' }3
Headers: 4
Authorization: "Bearer " + accessToken5
X-RequestDigest: form digest value6
IF-MATCH": etag or "*"7
X-HTTP-Method: MERGE,8
accept: "application/json;odata=verbose"9
content-type: "application/json;odata=verbose"10
content-length:length of post body11
12
Url: url:
Url: url:
1
http://site
Method:POST2
Body: { '__metadata': { 'type': 'SP.Field' }, 'Title': 'field title', 'FieldTypeKind':
FieldType value,'Required': 'true/false', 'EnforceUniqueValues':
'true/false','StaticName': 'field name'}
3
Headers: 4
Authorization: "Bearer " + accessToken5
X-RequestDigest: form digest value6
content-type: "application/json;odata=verbose"7
content-length:length of post body8
9
The following example shows how to retrieve all of a list’s items.
The following example shows how to retrieve a specific list item.
url:
url:
1
http://site
method: POST2
Headers: 3
Authorization: "Bearer " + accessToken4
X-RequestDigest: form digest value5
IF-MATCH: etag or "*"6
X-HTTP-Method: DELETE7
8
9
Working with list items by using REST
Note
The OData $skip query option does not work when querying list items. In may situations, you can
use the option instead.$skiptoken
url:
url:
1
http://site
method: GET2
headers:3
Authorization: "Bearer " + accessToken4
accept: "application/json;odata=verbose" or "application/atom+xml"5
6
7
The following XML shows an example of the list item properties that are returned when you request
the XML content type.
The following example shows how to create a list item.
url:
url:
1
http://site
method: GET2
headers:3
Authorization: "Bearer " + accessToken4
accept: "application/json;odata=verbose" or "application/atom+xml"5
6
7
XML
15
16
17
Note
To do this operation, you must know the ListItemEntityTypeFullName property of the list and pass
that as the value of type in the HTTP request body.
The following example shows how to update a list item.
The following example shows how to delete a list item.
url:
url:
1
http://site
method: POST2
body: { '__metadata': { 'type': 'SP.Data.TestListItem' }, 'Title': 'Test'}3
headers:4
Authorization: "Bearer " + accessToken5
X-RequestDigest: form digest value6
accept: "application/json;odata=verbose"7
content-type: "application/json;odata=verbose"8
content-length:length of post body9
10
Note
To do this operation, you must know the ListItemEntityTypeFullName property of the list and pass
that as the value of type in the HTTP request body.
url:
url:
1
http://site
method: POST2
body: { '__metadata': { 'type': 'SP.Data.TestListItem' }, 'Title': 'TestUpdated'}3
headers:4
Authorization: "Bearer " + accessToken5
X-RequestDigest: form digest value6
"IF-MATCH": etag or "*"7
"X-HTTP-Method":"MERGE",8
accept: "application/json;odata=verbose"9
content-type: "application/json;odata=verbose"10
content-length:length of post body11
12
The SharePoint REST service, which follows the , uses
of SharePoint lists and list items. To check on an item’s version when you perform
a PUT, MERGE, or DELETE request, specify an ETag in the If-Match HTTP request header.
If the ETag you specify in your request does not match the ETag of the document or list item on the
server, the REST service returns a 412 exception, per the OData specification.
ETag value to "*".
ETag, SharePoint overwrites the item regardless of version.
Within SharePoint, ETags apply only to SharePoint lists and list items.
url:
url:
1
http://site
method: POST2
headers:3
Authorization: "Bearer " + accessToken4
X-RequestDigest: form digest value5
"IF-MATCH": etag or "*"6
"X-HTTP-Method":"DELETE"7
8
9
Using ETag values to determine document and list item versioning
OData standard HTML ETags for concurrency
control
To force an overwrite of the item regardless of version, set the
If you do not specify an