Below you'll see the JSON returned by Graph Explorer.
2 QUESTIONS:
This query will return an array of owner objects.
https://graph.microsoft.com/v1.0/me/calendars?$select=owner
However, what if I only wanted the address element of the owner object returned?
What if I only wanted the 2nd Calendar in the array of Calendar objects returned? What would that query look like?
These questions are simply for me to gain more knowledge of how to traverse JSON paths using Graph Explorer. I'm well aware that I can specify the calendar ID of the calendar I want, and that I can retrieve the owner object and select the element I would like.
{
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users('-- USER ID --')/calendars",
"value": [
{
"id": "-- CALENDAR ID --",
"name": "Holiday Schedule",
"color": "auto",
"hexColor": "",
"isDefaultCalendar": false,
"changeKey": "-- ID --",
"canShare": false,
"canViewPrivateItems": true,
"canEdit": false,
"allowedOnlineMeetingProviders": [],
"defaultOnlineMeetingProvider": "unknown",
"isTallyingResponses": false,
"isRemovable": true,
"owner": {
"name": "John Smith",
"address": "Joh.Smith@mybusiness.com"
}
},
{
"id": "-- CALENDAR ID --",
"name": "Calendar",
"color": "auto",
"hexColor": "",
"isDefaultCalendar": true,
"changeKey": "-- ID --",
"canShare": true,
"canViewPrivateItems": true,
"canEdit": true,
"allowedOnlineMeetingProviders": [
"teamsForBusiness"
],
"defaultOnlineMeetingProvider": "teamsForBusiness",
"isTallyingResponses": true,
"isRemovable": false,
"owner": {
"name": "Jane Smith",
"address": "Jane.Smith@mybusiness.com"
}
},
{
"id": "--- CALENDAR ID --",
"name": "School Schedule",
"color": "auto",
"hexColor": "",
"isDefaultCalendar": false,
"changeKey": "-- ID --",
"canShare": false,
"canViewPrivateItems": true,
"canEdit": false,
"allowedOnlineMeetingProviders": [],
"defaultOnlineMeetingProvider": "unknown",
"isTallyingResponses": false,
"isRemovable": true,
"owner": {
"name": "Bobby Smith",
"address": "Bobby.Smith@mybusiness.com"
}
}
]
}
Nested select is not supported by the Graph API, so this query will not work
GET /v1.0/me/calendars?$select=owner($select=address)
To the second question, you can't return only item of the array on specific index. There is no such way for this in the Graph API and for OData in general.
You can use $filter
but /me/calendars
support filtering only by name
, color
and isDefaultCalendar
property.
GET /v1.0/me/calendars?$filter=name eq 'Calendar'
GET /v1.0/me/calendars?$filter=color eq 'auto'
GET /v1.0/me/calendars?$filter=isDefaultCalendar eq true
You can access item on the specific index on the client when processing the response from the Graph API but you can never count on ane item at a particular index to always have the same value.