Skip to content

Commit 388b4ce

Browse files
committed
updated collections
1 parent 568d6c0 commit 388b4ce

File tree

2 files changed

+76
-98
lines changed

2 files changed

+76
-98
lines changed

graph/GuidelinesGraph.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -277,11 +277,10 @@ For an additional list of standard HTTP methods, see the [RFC7230](https://www.r
277277
"code": "badRequest",
278278
"message": "Cannot process the request because a required field is missing.",
279279
"target": "query",
280-
"innererror": {
281-
"code": "requiredFieldMissing",
282-
283-
}
284-
}
280+
"innererror":{
281+
"code": "requiredFieldMissing",
282+
"message": "A required field is missing.",
283+
}
285284
}
286285
```
287286

@@ -308,7 +307,7 @@ The top-level error code MUST match the HTTP response status code description, c
308307
"message": "Cannot process the request because it is malformed or incorrect.",
309308
"innererror": {
310309
"code": "requiredFieldOrParameterMissing",
311-
310+
"message": "A required field or parameter is missing.",
312311
}
313312
}
314313
}

graph/articles/collections.md

Lines changed: 71 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,72 @@
1-
# Collections
1+
# Collections
2+
23
## 1. Item keys
3-
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.
44

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.
68

79
## 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.
912

1013
## 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".
1216

1317
For example:
1418

1519
```http
16-
GET https://api.contoso.com/v1.0/people
20+
GET https://graph.microsoft.com/v1.0/teamwork/devices
1721
```
1822

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".
2024
For example:
2125

2226
```http
23-
GET https://{serviceRoot}/{collection}/{id}
27+
GET https://graph.microsoft.com/beta/teamwork/devices/0f3ce432-e432-0f3c-32e4-3c0f32e43c0f
2428
```
2529

2630
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.
3035

3136
### 3.1. Nested collections and properties
37+
3238
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:
3440

3541
```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
3743
```
3844

3945
```json
46+
4047
{
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+
}
4561
}
4662
```
4763

4864
## 4. Big collections
65+
4966
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.
5370

5471
Clients MUST be resilient to collection data being either paged or nonpaged for any given request.
5572

@@ -66,37 +83,34 @@ Clients MUST be resilient to collection data being either paged or nonpaged for
6683
```
6784

6885
## 5. Changing collections
86+
6987
POST requests are not idempotent.
7088
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.
7189
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).
7291

7392
For example, the following request:
7493

7594
```http
76-
POST https://api.contoso.com/v1.0/people
77-
```
95+
POST https://graph.microsoft.com/beta/teamwork/devices
7896
7997
Would lead to a response indicating the location of the new collection item:
8098
8199
```http
82100
201 Created
83-
Location: https://api.contoso.com/v1.0/people/123
101+
Location: https://graph.microsoft.com/beta/teamwork/devices/123
84102
```
85103

86104
And once executed again, would likely lead to another resource:
87105

88106
```http
89107
201 Created
90-
Location: https://api.contoso.com/v1.0/people/124
108+
Location: https://graph.microsoft.com/beta/teamwork/devices/124
91109
```
92110

93-
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-
```
98111

99112
## 6. Sorting collections
113+
100114
The results of a collection query MAY be sorted based on property values.
101115
The property is determined by the value of the _$orderBy_ query parameter.
102116

@@ -114,56 +128,54 @@ The sort order is the inherent order for the type of the property.
114128
For example:
115129

116130
```http
117-
GET https://api.contoso.com/v1.0/people?$orderBy=name
131+
GET https://graph.microsoft.com/beta/teamwork/devices?$orderBy=companyAssetTag
118132
```
119133

120-
Will return all people sorted by name in ascending order.
134+
Will return all devices sorted by companyAssetTag in ascending order.
121135

122136
For example:
123137

124138
```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
126140
```
127141

128-
Will return all people sorted by name in descending order.
142+
Will return all devices sorted by companyAssetTag in descending order.
129143

130144
Sub-sorts can be specified by a comma-separated list of property names with OPTIONAL direction qualifier.
131145

132146
For example:
133147

134148
```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
136150
```
137151

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.
141153

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.
145155

146-
Will return all people whose name is David sorted in ascending order by hireDate.
147156

148157
### 6.1. Interpreting a sorting expression
158+
149159
Sorting parameters MUST be consistent across pages, as both client and server-side paging is fully compatible with sorting.
150160

151161
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.
152162

153163
## 7. Filtering
164+
154165
The _$filter_ querystring parameter allows clients to filter a collection of resources that are addressed by a request URL.
155166
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.
156167
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.
157168

158-
Example: return all Products whose Price is less than $10.00
169+
Example: return all devices with activity state equal to 'Active'
159170

160171
```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')
162173
```
163174

164175
The value of the _$filter_ option is a Boolean expression.
165176

166177
### 7.1. Filter operations
178+
167179
Services that support _$filter_ SHOULD support the following minimal set of operations.
168180

169181
Operator | Description | Example
@@ -182,40 +194,6 @@ not | Logical negation | not price le 3.5
182194
Grouping Operators | |
183195
( ) | Precedence grouping | (priority eq 1 or city eq 'Redmond') and price gt 100
184196

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
219197
Services MUST use the following operator precedence for supported operators when evaluating _$filter_ expressions.
220198
Operators are listed by category in order of precedence from highest to lowest.
221199
Operators in the same category have equal precedence:
@@ -225,15 +203,16 @@ Operators in the same category have equal precedence:
225203
| Grouping | ( ) | Precedence grouping |
226204
| Unary | not | Logical Negation |
227205
| Relational | gt | Greater Than |
228-
| | ge | Greater than or Equal |
206+
| | ge | Greater Than or Equal |
229207
| | lt | Less Than |
230-
| | le | Less than or Equal |
208+
| | le | Less Than or Equal |
231209
| Equality | eq | Equal |
232210
| | ne | Not Equal |
233211
| Conditional AND | and | Logical And |
234212
| Conditional OR | or | Logical Or |
235213

236214
## 8. Pagination
215+
237216
RESTful APIs that return collections MAY return partial sets.
238217
Consumers of these services MUST expect partial result sets and correctly page through to retrieve an entire set.
239218

@@ -244,6 +223,7 @@ Client-driven paging enables clients to request only the number of resources tha
244223
Sorting and Filtering parameters MUST be consistent across pages, because both client- and server-side paging is fully compatible with both filtering and sorting.
245224

246225
### 8.1. Server-driven paging
226+
247227
Paginated responses MUST indicate a partial result by including a continuation token in the response.
248228
The absence of a continuation token means that no additional pages are available.
249229

@@ -252,20 +232,20 @@ Clients MUST treat the continuation URL as opaque, which means that query option
252232
Example:
253233

254234
```http
255-
GET http://api.contoso.com/v1.0/people HTTP/1.1
235+
GET https://graph.microsoft.com/beta/teamwork/devices
256236
Accept: application/json
257237
258238
HTTP/1.1 200 OK
259239
Content-Type: application/json
260240
261241
{
262-
...,
263242
"value": [...],
264243
"@nextLink": "{opaqueUrl}"
265244
}
266245
```
267246

268247
### 8.2. Client-driven paging
248+
269249
Clients MAY use _$top_ and _$skip_ query parameters to specify a number of results to return and an offset into the collection.
270250

271251
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
278258
Example:
279259

280260
```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+
282263
Accept: application/json
283264
284265
HTTP/1.1 200 OK
285266
Content-Type: application/json
286267
287268
{
288-
...,
289-
"value": [...]
269+
"value": [...]
290270
}
291271
```
292272

293273
### 8.3. Additional considerations
274+
294275
**Stable order prerequisite:** Both forms of paging depend on the collection of items having a stable order.
295276
The server MUST supplement any specified order criteria with additional sorts (typically by key) to ensure that items are always ordered consistently.
296277

@@ -310,31 +291,29 @@ If a server paginates an embedded collection, it MUST include additional continu
310291
**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.
311292

312293
## 9. Compound collection operations
294+
313295
Filtering, Sorting and Pagination operations MAY all be performed against a given collection.
314296
When these operations are performed together, the evaluation order MUST be:
315297

316298
1. **Filtering**. This includes all range expressions performed as an AND operation.
317299
2. **Sorting**. The potentially filtered list is sorted according to the sort criteria.
318300
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+
320302
## 10. Empty Results
321-
</mark>
303+
322304
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.
323305
In this example the filters supplied by the client resulted in a empty result set.
324306
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.
327308

328309
```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')
330311
Accept: application/json
331312
332313
HTTP/1.1 200 OK
333314
Content-Type: application/json
334315
335316
{
336-
...,
337-
"maxItems": 0,
338-
"value": []
317+
"value": []
339318
}
340319
```

0 commit comments

Comments
 (0)