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
Copy file name to clipboardExpand all lines: graph/patterns/alternate-key.md
+9-7Lines changed: 9 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,15 +12,15 @@ The resources exposed in Graph are identified through a Primary Key - which guar
12
12
13
13
Take a look at the `user` resource: while the `id` remains a perfectly valid way to get the resource details, the `mail` address is also an unique property that could be used to identify it.
14
14
15
-
While it is still possible to use the OData filter, such as
15
+
While it is still possible to use the `$filter` query parameter, such as
16
16
17
-
`https://graph.microsoft.com/v1.0/users?$filter=mail eq '[email protected]'`, the returned result is wrapped in an array that needs to be unpacked.
17
+
`GET https://graph.microsoft.com/v1.0/users?$filter=mail eq '[email protected]'`, the returned result is wrapped in an array that needs to be unpacked.
18
18
19
19
## Solution
20
20
21
21
---
22
22
23
-
OData offers resource addressing via an alternate key using the same parentheses-style convention as for the canonical key, with one difference: single-part alternate keys MUST specify the key property name to unambiguously determine the alternate key. (Note: this is a hypothetical sample)
23
+
Resource addressing via an alternative key can be achieved using the same parentheses-style convention as for the canonical key, with one difference: single-part alternate keys MUST specify the key property name to unambiguously determine the alternate key. (Note: this is a hypothetical sample)
24
24
25
25
https://graph.microsoft.com/v1.0/users(0) - Retrieves the employee with ID = 0
@@ -29,7 +29,7 @@ https://graph.microsoft.com/v1.0/users(email='[email protected]') Retrieves the em
29
29
30
30
---
31
31
32
-
This pattern works and makes sense when the alternate key is good enough to identify a single resource and provides an useful alternative to the client; while it does not work if the resultset has more than one element. In such case, the workload SHOULD return `400`
32
+
This pattern works and makes sense when the alternate key is good enough to identify a single resource and provides an useful alternative to the client.
33
33
34
34
## Example
35
35
@@ -40,7 +40,7 @@ The same user identified via the alternate key SSN, the canonical (primary) key
40
40
Declare `mail` and `ssn` as alternate keys on an entity:
41
41
42
42
```xml
43
-
<EntityTypeName="User">
43
+
<EntityTypeName="user">
44
44
<Key>
45
45
<PropertyRefName="id" />
46
46
</Key>
@@ -76,7 +76,7 @@ Declare `mail` and `ssn` as alternate keys on an entity:
76
76
1. Get a specific resource through `$filter`:
77
77
78
78
```http
79
-
GET https://graph.microsoft.com/v1.0/users/?$filter=(ssn eq '123-45-6789')
79
+
GET https://graph.microsoft.com/v1.0/users/?$filter=ssn eq '123-45-6789'
80
80
```
81
81
82
82
```json
@@ -97,14 +97,16 @@ GET https://graph.microsoft.com/v1.0/users/?$filter=(ssn eq '123-45-6789')
97
97
}
98
98
```
99
99
100
-
2. Get a specific resource through its primary key, and then through the two alternate keys:
100
+
2. Get a specific resource either through its primary key, or through the two alternate keys:
101
101
102
102
```http
103
103
GET https://graph.microsoft.com/v1.0/users/1a89ade6-9f59-4fea-a139-23f84e3aef66
104
104
GET https://graph.microsoft.com/v1.0/users(ssn='123-45-6789')
105
105
GET https://graph.microsoft.com/v1.0/users(email='[email protected]')
106
106
```
107
107
108
+
**NOTE:** When requesting a resource through its primary key you might want to prefer to use key-as-segment (as shown above). Also, the key-as-segment does not work for alternate keys.
0 commit comments