You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Services MAY support durable identifiers for each item in the collection, and that identifier SHOULD be represented in JSON as "id". These durable identifiers are often used as item keys.
4
4
5
-
Collections that support durable identifiers MAY support delta queries.
5
+
Services SHOULD support durable identifiers for each item in the collection, and that identifier SHOULD be represented in JSON as "id". These durable identifiers are often used as item keys.
6
+
7
+
Collections MAY support delta queries, see the [Change Tracking pattern](../patterns/change-tracking.md) section for more details.
6
8
7
9
## 2. Serialization
8
-
Collections are represented in JSON using standard array notation.
10
+
11
+
Collections are represented in JSON using standard array notation for `value` property.
9
12
10
13
## 3. Collection URL patterns
11
-
Collections are located directly under the service root when they are top-level, or as a segment under another resource when scoped to that resource. Collection names usually use plural nouns with no suffixes, such as "Collection" or "List".
14
+
15
+
While there are multiple collections located directly under the Graph root going forward, you MUST have a singleton for the top-level segment and scope collections to an appropriate singleton. Collection names SHOULD be plural nouns when possible. Collection names shouldn't use suffixes, such as "Collection" or "List".
12
16
13
17
For example:
14
18
15
19
```http
16
-
GET https://api.contoso.com/v1.0/people
20
+
GET https://graph.microsoft.com/v1.0/teamwork/devices
17
21
```
18
22
19
-
<mark> Whenever possible, services MUST support the "/" pattern.</mark>
23
+
Collections elements MUST be addressable by a unique id property. The id property MUST be a String and MUST be unique within the collection. The id property MUST be represented in JSON as "id".
20
24
For example:
21
25
22
26
```http
23
-
GET https://{serviceRoot}/{collection}/{id}
27
+
GET https://graph.microsoft.com/beta/teamwork/devices/0f3ce432-e432-0f3c-32e4-3c0f32e43c0f
24
28
```
25
29
26
30
Where:
27
-
- {serviceRoot} – the combination of host (site URL) + the root path to the service
28
-
- {collection} – the name of the collection, unabbreviated, pluralized
29
-
- {id} – the value of the unique id property. When using the "/" pattern this MUST be the raw string/number/guid value with no quoting but properly escaped to fit in a URL segment.
31
+
32
+
- "https://graph.microsoft.com/beta/teamwork" - the service root represented as the combination of host (site URL) + the root path to the service.
33
+
- "devices" – the name of the collection, unabbreviated, pluralized.
34
+
- "0f3ce432-e432-0f3c-32e4-3c0f32e43c0f" – the value of the unique id property that MUST be the raw string/number/guid value with no quoting but properly escaped to fit in a URL segment.
30
35
31
36
### 3.1. Nested collections and properties
37
+
32
38
Collection items MAY contain other collections.
33
-
For example, a user collection MAY contain user resources that have multiple addresses:
39
+
For example, a devices collection MAY contain device resources that have multiple mac addresses:
34
40
35
41
```http
36
-
GET https://api.contoso.com/v1.0/people/123/addresses
42
+
GET https://graph.microsoft.com/beta/teamwork/devices/0f3ce432-e432-0f3c-32e4-3c0f32e43c0f
37
43
```
38
44
39
45
```json
46
+
40
47
{
41
-
"value": [
42
-
{ "street": "1st Avenue", "city": "Seattle" },
43
-
{ "street": "124th Ave NE", "city": "Redmond" }
44
-
]
48
+
"value": {
49
+
"@odata.type": "#microsoft.graph.teamworkDevice",
50
+
"id": "0f3ce432-e432-0f3c-32e4-3c0f32e43c0f",
51
+
"deviceType": "CollaborationBar",
52
+
"hardwareDetail": {
53
+
"serialNumber": "0189",
54
+
"uniqueId": "5abcdefgh",
55
+
"macAddresses": [],
56
+
"manufacturer": "yealink",
57
+
"model": "vc210"
58
+
},
59
+
...
60
+
}
45
61
}
46
62
```
47
63
48
64
## 4. Big collections
65
+
49
66
As data grows, so do collections.
50
-
Planning for pagination is important for all services.
51
-
Therefore, when multiple pages are available, the serialization payload MUST contain the opaque URL for the next page as appropriate.
52
-
Refer to the paging guidance for more details.
67
+
Services SHOULD support server-side pagination from day one even for all collections, as adding pagination is a breaking change.
68
+
When multiple pages are available, the serialization payload MUST contain the opaque URL for the next page as appropriate.
69
+
Refer to the [paging guidance](../Guidelines-deprecated.md#98-pagination) for more details.
53
70
54
71
Clients MUST be resilient to collection data being either paged or nonpaged for any given request.
55
72
@@ -66,37 +83,34 @@ Clients MUST be resilient to collection data being either paged or nonpaged for
66
83
```
67
84
68
85
## 5. Changing collections
86
+
69
87
POST requests are not idempotent.
70
88
This means that two POST requests sent to a collection resource with exactly the same payload MAY lead to multiple items being created in that collection.
71
89
This is often the case for insert operations on items with a server-side generated id.
90
+
For additional information refer to [Upsert pattern](../patterns/upsert.md).
72
91
73
92
For example, the following request:
74
93
75
94
```http
76
-
POST https://api.contoso.com/v1.0/people
77
-
```
95
+
POST https://graph.microsoft.com/beta/teamwork/devices
78
96
79
97
Would lead to a response indicating the location of the new collection item:
While a PUT request would require the indication of the collection item with the corresponding key instead:
94
-
95
-
```http
96
-
PUT https://api.contoso.com/v1.0/people/123
97
-
```
98
111
99
112
## 6. Sorting collections
113
+
100
114
The results of a collection query MAY be sorted based on property values.
101
115
The property is determined by the value of the _$orderBy_ query parameter.
102
116
@@ -114,56 +128,54 @@ The sort order is the inherent order for the type of the property.
114
128
For example:
115
129
116
130
```http
117
-
GET https://api.contoso.com/v1.0/people?$orderBy=name
131
+
GET https://graph.microsoft.com/beta/teamwork/devices?$orderBy=companyAssetTag
118
132
```
119
133
120
-
Will return all people sorted by name in ascending order.
134
+
Will return all devices sorted by companyAssetTag in ascending order.
121
135
122
136
For example:
123
137
124
138
```http
125
-
GET https://api.contoso.com/v1.0/people?$orderBy=name desc
139
+
GET https://graph.microsoft.com/beta/teamwork/devices?$orderBy=companyAssetTag desc
126
140
```
127
141
128
-
Will return all people sorted by name in descending order.
142
+
Will return all devices sorted by companyAssetTag in descending order.
129
143
130
144
Sub-sorts can be specified by a comma-separated list of property names with OPTIONAL direction qualifier.
131
145
132
146
For example:
133
147
134
148
```http
135
-
GET https://api.contoso.com/v1.0/people?$orderBy=name desc,hireDate
149
+
GET https://graph.microsoft.com/beta/teamwork/devices?$orderBy=companyAssetTag desc,activityState
136
150
```
137
151
138
-
Will return all people sorted by name in descending order and a secondary sort order of hireDate in ascending order.
139
-
140
-
Sorting MUST compose with filtering such that:
152
+
Will return all devices sorted by companyAssetTag in descending order and a secondary sort order of activityState in ascending order.
141
153
142
-
```http
143
-
GET https://api.contoso.com/v1.0/people?$filter=name eq 'david'&$orderBy=hireDate
144
-
```
154
+
Sorting MUST compose with filtering see [Odata 4.01 spec](https://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part2-url-conventions.html#_Toc31361038) for more details.
145
155
146
-
Will return all people whose name is David sorted in ascending order by hireDate.
147
156
148
157
### 6.1. Interpreting a sorting expression
158
+
149
159
Sorting parameters MUST be consistent across pages, as both client and server-side paging is fully compatible with sorting.
150
160
151
161
If a service does not support sorting by a property named in a _$orderBy_ expression, the service MUST respond with an error message as defined in the Responding to Unsupported Requests section.
152
162
153
163
## 7. Filtering
164
+
154
165
The _$filter_ querystring parameter allows clients to filter a collection of resources that are addressed by a request URL.
155
166
The expression specified with _$filter_ is evaluated for each resource in the collection, and only items where the expression evaluates to true are included in the response.
156
167
Resources for which the expression evaluates to false or to null, or which reference properties that are unavailable due to permissions, are omitted from the response.
157
168
158
-
Example: return all Products whose Price is less than $10.00
169
+
Example: return all devices with activity state equal to 'Active'
159
170
160
171
```http
161
-
GET https://api.contoso.com/v1.0/products?$filter=price lt 10.00
172
+
GET https://graph.microsoft.com/beta/teamwork/devices?$filter=(activityState eq 'Active')
162
173
```
163
174
164
175
The value of the _$filter_ option is a Boolean expression.
165
176
166
177
### 7.1. Filter operations
178
+
167
179
Services that support _$filter_ SHOULD support the following minimal set of operations.
168
180
169
181
Operator | Description | Example
@@ -182,40 +194,6 @@ not | Logical negation | not price le 3.5
182
194
Grouping Operators | |
183
195
( ) | Precedence grouping | (priority eq 1 or city eq 'Redmond') and price gt 100
184
196
185
-
### 7.2. Operator examples
186
-
The following examples illustrate the use and semantics of each of the logical operators.
187
-
188
-
Example: all products with a name equal to 'Milk'
189
-
190
-
```http
191
-
GET https://api.contoso.com/v1.0/products?$filter=name eq 'Milk'
192
-
```
193
-
194
-
Example: all products with a name not equal to 'Milk'
195
-
196
-
```http
197
-
GET https://api.contoso.com/v1.0/products?$filter=name ne 'Milk'
198
-
```
199
-
200
-
Example: all products with the name 'Milk' that also have a price less than 2.55:
201
-
202
-
```http
203
-
GET https://api.contoso.com/v1.0/products?$filter=name eq 'Milk' and price lt 2.55
204
-
```
205
-
206
-
Example: all products that either have the name 'Milk' or have a price less than 2.55:
207
-
208
-
```http
209
-
GET https://api.contoso.com/v1.0/products?$filter=name eq 'Milk' or price lt 2.55
210
-
```
211
-
212
-
Example: all products that have the name 'Milk' or 'Eggs' and have a price less than 2.55:
213
-
214
-
```http
215
-
GET https://api.contoso.com/v1.0/products?$filter=(name eq 'Milk' or name eq 'Eggs') and price lt 2.55
216
-
```
217
-
218
-
### 7.3. Operator precedence
219
197
Services MUST use the following operator precedence for supported operators when evaluating _$filter_ expressions.
220
198
Operators are listed by category in order of precedence from highest to lowest.
221
199
Operators in the same category have equal precedence:
@@ -225,15 +203,16 @@ Operators in the same category have equal precedence:
225
203
| Grouping | ( ) | Precedence grouping |
226
204
| Unary | not | Logical Negation |
227
205
| Relational | gt | Greater Than |
228
-
|| ge | Greater than or Equal |
206
+
|| ge | Greater Than or Equal |
229
207
|| lt | Less Than |
230
-
|| le | Less than or Equal |
208
+
|| le | Less Than or Equal |
231
209
| Equality | eq | Equal |
232
210
|| ne | Not Equal |
233
211
| Conditional AND | and | Logical And |
234
212
| Conditional OR | or | Logical Or |
235
213
236
214
## 8. Pagination
215
+
237
216
RESTful APIs that return collections MAY return partial sets.
238
217
Consumers of these services MUST expect partial result sets and correctly page through to retrieve an entire set.
239
218
@@ -244,6 +223,7 @@ Client-driven paging enables clients to request only the number of resources tha
244
223
Sorting and Filtering parameters MUST be consistent across pages, because both client- and server-side paging is fully compatible with both filtering and sorting.
245
224
246
225
### 8.1. Server-driven paging
226
+
247
227
Paginated responses MUST indicate a partial result by including a continuation token in the response.
248
228
The absence of a continuation token means that no additional pages are available.
249
229
@@ -252,20 +232,20 @@ Clients MUST treat the continuation URL as opaque, which means that query option
252
232
Example:
253
233
254
234
```http
255
-
GET http://api.contoso.com/v1.0/people HTTP/1.1
235
+
GET https://graph.microsoft.com/beta/teamwork/devices
256
236
Accept: application/json
257
237
258
238
HTTP/1.1 200 OK
259
239
Content-Type: application/json
260
240
261
241
{
262
-
...,
263
242
"value": [...],
264
243
"@nextLink": "{opaqueUrl}"
265
244
}
266
245
```
267
246
268
247
### 8.2. Client-driven paging
248
+
269
249
Clients MAY use _$top_ and _$skip_ query parameters to specify a number of results to return and an offset into the collection.
270
250
271
251
The server SHOULD honor the values specified by the client; however, clients MUST be prepared to handle responses that contain a different page size or contain a continuation token.
@@ -278,19 +258,20 @@ This will avoid the risk of the client making assumptions about the data returne
278
258
Example:
279
259
280
260
```http
281
-
GET http://api.contoso.com/v1.0/people?$top=5&$skip=2 HTTP/1.1
261
+
GET https://graph.microsoft.com/beta/teamwork/devices?$top=5&$skip=2
262
+
282
263
Accept: application/json
283
264
284
265
HTTP/1.1 200 OK
285
266
Content-Type: application/json
286
267
287
268
{
288
-
...,
289
-
"value": [...]
269
+
"value": [...]
290
270
}
291
271
```
292
272
293
273
### 8.3. Additional considerations
274
+
294
275
**Stable order prerequisite:** Both forms of paging depend on the collection of items having a stable order.
295
276
The server MUST supplement any specified order criteria with additional sorts (typically by key) to ensure that items are always ordered consistently.
296
277
@@ -310,31 +291,29 @@ If a server paginates an embedded collection, it MUST include additional continu
310
291
**Recordset count:** Developers who want to know the full number of records across all pages, MAY include the query parameter _$count=true_ to tell the server to include the count of items in the response.
311
292
312
293
## 9. Compound collection operations
294
+
313
295
Filtering, Sorting and Pagination operations MAY all be performed against a given collection.
314
296
When these operations are performed together, the evaluation order MUST be:
315
297
316
298
1.**Filtering**. This includes all range expressions performed as an AND operation.
317
299
2.**Sorting**. The potentially filtered list is sorted according to the sort criteria.
318
300
3.**Pagination**. The materialized paginated view is presented over the filtered, sorted list. This applies to both server-driven pagination and client-driven pagination.
319
-
<mark>
301
+
320
302
## 10. Empty Results
321
-
</mark>
303
+
322
304
When a filter is performed on a collection and the result set is empty you MUST respond with a valid response body and a 200 response code.
323
305
In this example the filters supplied by the client resulted in a empty result set.
324
306
The response body is returned as normal and the _value_ attribute is set to a empty collection.
325
-
<mark>A client MAY be expecting metadata attributes like _maxItems_ based on the format of your responses to similar calls which produced results.<mark>
326
-
You SHOULD maintain consistency in your API whenever possible.
307
+
You SHOULD maintain consistency in your API whenever possible.
327
308
328
309
```http
329
-
GET https://api.contoso.com/v1.0/products?$filter=(name eq 'Milk' or name eq 'Eggs') and price lt 2.55
310
+
GET https://graph.microsoft.com/beta/teamwork/devices?$filter=('deviceType' eq 'Collab' or companyAssetTa eq 'Tag1')
0 commit comments