跳转至

Working with lists and list items with REST.note

Source: /Volumes/X9 Pro/ObsNotes/YoudaoYunNotes/默认笔记本/Working with lists and list items with REST.note.pdf Converted: 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

1

2

true 3

100 4

0 5

false 6

2012-06-26T23:15:58Z 7

00000000-0000-0000-0000-

000000000000

8

A list created by Project Based Retention used to store Project

Policy Items.

9

none 10

11

0 12

true 13

false 14

false 15

false 16

false 17

ProjectPolicyItemList 18

false 19

false 20

true 21

74de3ff3-029c-42f9-bd2a-1e9463def69d 22

/_layouts/15/images/itgen.gif 23

false 24

false 25

false 26

false 27

false 28

false 29

0 30

2012-06-

26T23:15:58Z

31

2012-06-

26T23:15:59Z

32

SP.Data.ProjectPolicyItemListItem</d:ListItemEntityTypeFu

llName>

33

false 34

true 35

The following example shows how to create a list.

The following example shows how to update a list by using the MERGE method.

/ 36

<d:ServerTemplateCanCreateFolders

m:type="Edm.Boolean">true

37

00bfea71-de22-43b2-a848-

c05709900100

38

Project Policy Item List 39

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

1

2

03

14

15

0x010049564F321A0F0543BA8C6303316C8C0F6

an item7

2012-07-24T22:47:26Z8

2012-07-24T22:47:26Z9

1110

1111

1.012

false13

eb6850c5-9a30-4636-b282-234eda8b105714

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