{"id":1975,"date":"2018-11-05T10:00:19","date_gmt":"2018-11-05T10:00:19","guid":{"rendered":"https:\/\/developer.microsoft.com\/en-us\/office\/blogs\/?p=1975"},"modified":"2018-11-05T10:00:19","modified_gmt":"2018-11-05T10:00:19","slug":"30daysmsgraph-day-5-query-parameters-part-1","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/30daysmsgraph-day-5-query-parameters-part-1\/","title":{"rendered":"30DaysMSGraph \u2013 Day 5 \u2013 Query Parameters Part 1"},"content":{"rendered":"<p><a href=\"https:\/\/aka.ms\/30DaysMSGraph\">List of all posts in the #30DaysMSGraph series<\/a><\/p>\n<p>In <a href=\"https:\/\/developer.microsoft.com\/en-us\/graph\/blogs\/30daysmsgraph-day-4-request-syntax\/\">day 4<\/a> we discussed the syntax for Microsoft Graph requests.\u00a0 Today we&#8217;ll begin looking at query parameters available for requests against Microsoft Graph.\u00a0 For a full listing of the query parameters available and additional information \/ examples please see the full documentation: <a href=\"https:\/\/developer.microsoft.com\/en-us\/graph\/docs\/concepts\/query_parameters\">Use query parameters to customize responses<\/a>.<\/p>\n<p><img decoding=\"async\" class=\"aligncenter wp-image-1991\" src=\"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2018\/11\/30DaysMSGraph_Day5_Source-300x199.jpg\" alt=\"\" width=\"529\" height=\"350\" srcset=\"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2018\/11\/30DaysMSGraph_Day5_Source-300x199.jpg 300w, https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2018\/11\/30DaysMSGraph_Day5_Source-1024x678.jpg 1024w, https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2018\/11\/30DaysMSGraph_Day5_Source-768x508.jpg 768w, https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2018\/11\/30DaysMSGraph_Day5_Source.jpg 1280w\" sizes=\"(max-width: 529px) 100vw, 529px\" \/><\/p>\n<h3><a href=\"https:\/\/developer.microsoft.com\/en-us\/graph\/docs\/concepts\/query_parameters#filter-parameter\">Filter<\/a><\/h3>\n<p>Filter is one of the more common query parameters that you may use or encounter.\u00a0 Filter retrieves a subset of rows from the total results that match the specified conditions.<\/p>\n<p><strong>Syntax<\/strong><\/p>\n<p style=\"padding-left: 30px\">&lt;baseGraphQuery&gt;?$filter=&lt;conditions&gt;<\/p>\n<p><strong>Ex.<\/strong> \u2013 Get users whose display name starts with &#8220;A&#8221;<\/p>\n<p style=\"padding-left: 30px\">https:\/\/graph.microsoft.com\/v1.0\/users?$filter=startswith(displayName,&#8217;A&#8217;)<\/p>\n<p>&nbsp;<\/p>\n<h3><a href=\"https:\/\/developer.microsoft.com\/en-us\/graph\/docs\/concepts\/query_parameters#select-parameter\">Select<\/a><\/h3>\n<p>Select allows for retrieving a subset or superset of properties rather than the default properties.\u00a0 This can be especially helpful if you are returning many records that have a high number of default properties returned.\u00a0 Reduce memory usage and network bandwidth usage by limiting the number of properties returned to only the ones that your app needs.<\/p>\n<p><strong>Syntax<\/strong><\/p>\n<p style=\"padding-left: 30px\">&lt;baseGraphQuery&gt;?$select=&lt;property1&gt;,&lt;property2&gt;,\u2026,&lt;propertyN&gt;<\/p>\n<p><strong>Ex.<\/strong> \u2013 Get name, size, and webUrl of logged in user&#8217;s OneDrive site files<\/p>\n<p style=\"padding-left: 30px\">https:\/\/graph.microsoft.com\/v1.0\/me\/drive\/root\/children?$select=name,size,webUrl<\/p>\n<p>&nbsp;<\/p>\n<h3><a href=\"https:\/\/developer.microsoft.com\/en-us\/graph\/docs\/concepts\/query_parameters#orderby-parameter\">OrderBy<\/a><\/h3>\n<p>OrderBy will sort the results returned from a query using the specified property.\u00a0 Certain APIs do support multiple properties to sort on.<\/p>\n<p><strong>Syntax<\/strong><\/p>\n<p style=\"padding-left: 30px\">&lt;baseGraphQuery&gt;?$orderby=&lt;property1&gt;,&lt;property2&gt;,\u2026,&lt;propertyN&gt;<\/p>\n<p><strong>Ex.<\/strong> \u2013 Get logged in user&#8217;s contacts sorted by birthday (default ascending)<\/p>\n<p style=\"padding-left: 30px\">https:\/\/graph.microsoft.com\/v1.0\/me\/contacts?$orderby=birthday<\/p>\n<p>&nbsp;<\/p>\n<p>Additionally, you can specify ascending or descending order by appending a space plus &#8220;asc&#8221; (default in most cases) or &#8220;desc&#8221; to the property name.<\/p>\n<p><strong>Ex.<\/strong> \u2013 Get logged in user&#8217;s contacts sorted by birthday descending.<\/p>\n<p style=\"padding-left: 30px\">https:\/\/graph.microsoft.com\/v1.0\/me\/contacts?$orderby=birthday desc<\/p>\n<p>&nbsp;<\/p>\n<h3><a href=\"https:\/\/developer.microsoft.com\/en-us\/graph\/docs\/concepts\/query_parameters#format-parameter\">Format<\/a><\/h3>\n<p>Specific endpoints from Microsoft Graph will offer the ability to return results in different formats.\u00a0 This might include CSV (comma separated value) downloadable files, JSON (JavaScript object notation), or other popular formats.\u00a0 Endpoints that support the Format query parameter will default to one format but allow alternate supported formats to be requested.<\/p>\n<p><strong>Syntax<\/strong><\/p>\n<p style=\"padding-left: 30px\">&lt;baseGraphQuery&gt;?$format=&lt;formatValue&gt;<\/p>\n<p><strong>Ex.<\/strong> \u2013 Get report of Office 365 Group activity in JSON format<\/p>\n<p style=\"padding-left: 30px\">https:\/\/graph.microsoft.com\/beta\/reports\/getOffice365GroupsActivityGroupCounts(period=&#8217;D7&#8242;)?$format=application\/json<\/p>\n<p><strong>Ex.<\/strong> \u2013 Get report of Office 365 Group activity in CSV format<\/p>\n<p style=\"padding-left: 30px\">https:\/\/graph.microsoft.com\/beta\/reports\/getOffice365GroupsActivityGroupCounts(period=&#8217;D7&#8242;)?$format=text\/csv<\/p>\n<p><em>Note: To properly test out this call you will need to log into the Graph Explorer as an Office 365 Global Administrator or an Azure AD Administrator who can grant OAuth permissions to an account.\u00a0 For the time being simply note the syntax.<\/em><\/p>\n<p>&nbsp;<\/p>\n<h2>Try It Out<\/h2>\n<p>Use the query parameters covered today to filter, sort, and specify columns.\u00a0 Navigate to the <a href=\"https:\/\/aka.ms\/ge\">Graph Explorer<\/a>.\u00a0 Execute the following commands.<\/p>\n<p><a href=\"https:\/\/github.com\/microsoftgraph\/30DaysMSGraph-TryItOut\/blob\/master\/Day05-QueryParamPt1.md\">Day 5 repo link<\/a><\/p>\n<ol>\n<li>Get logged in user&#8217;s high priority emails.\n<ul>\n<li>https:\/\/graph.microsoft.com\/v1.0\/me\/messages?$filter=importance eq &#8216;High&#8217;<\/li>\n<\/ul>\n<\/li>\n<li>Get name, size, and webUrl of logged in user&#8217;s OneDrive site files.\n<ul>\n<li>https:\/\/graph.microsoft.com\/v1.0\/me\/drive\/root\/children?$select=name,size,webUrl<\/li>\n<\/ul>\n<\/li>\n<li>Get logged in user&#8217;s contacts sorted by birthday.\n<ul>\n<li>https:\/\/graph.microsoft.com\/v1.0\/me\/contacts?$orderby=birthday<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<p>Join us tomorrow as we continue with query parameters available for Microsoft Graph requests in <a href=\"https:\/\/developer.microsoft.com\/en-us\/graph\/blogs\/30daysmsgraph-day-6-query-parameters-part-2\">Day 6<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In day 4 we discussed the syntax for Microsoft Graph requests.\u00a0 Today we&#8217;ll begin looking at query parameters available for requests against Microsoft Graph.<\/p>\n","protected":false},"author":73055,"featured_media":25159,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[3],"tags":[84],"class_list":["post-1975","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-microsoft-graph","tag-30daysmsgraph"],"acf":[],"blog_post_summary":"<p>In day 4 we discussed the syntax for Microsoft Graph requests.\u00a0 Today we&#8217;ll begin looking at query parameters available for requests against Microsoft Graph.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/posts\/1975","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/users\/73055"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/comments?post=1975"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/posts\/1975\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/media\/25159"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/media?parent=1975"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/categories?post=1975"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/tags?post=1975"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}