{"id":1977,"date":"2018-11-06T11:00:44","date_gmt":"2018-11-06T11:00:44","guid":{"rendered":"https:\/\/developer.microsoft.com\/en-us\/office\/blogs\/?p=1977"},"modified":"2018-11-06T11:00:44","modified_gmt":"2018-11-06T11:00:44","slug":"30daysmsgraph-day-6-query-parameters-part-2","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/30daysmsgraph-day-6-query-parameters-part-2\/","title":{"rendered":"30DaysMSGraph \u2013 Day 6 \u2013 Query Parameters Part 2"},"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-5-query-parameters-part-1\">Day 5<\/a> we began discussing the query parameters available for Microsoft Graph requests.\u00a0 Today we&#8217;ll continue looking at query parameters available for requests against Microsoft Graph.<\/p>\n<p><img decoding=\"async\" class=\"aligncenter wp-image-1992\" src=\"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2018\/11\/30DaysMSGraph_Day6_Source-300x135.jpg\" alt=\"\" width=\"599\" height=\"270\" srcset=\"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2018\/11\/30DaysMSGraph_Day6_Source-300x135.jpg 300w, https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2018\/11\/30DaysMSGraph_Day6_Source-1024x462.jpg 1024w, https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2018\/11\/30DaysMSGraph_Day6_Source-768x346.jpg 768w, https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2018\/11\/30DaysMSGraph_Day6_Source.jpg 1280w\" sizes=\"(max-width: 599px) 100vw, 599px\" \/><\/p>\n<h3><a href=\"https:\/\/developer.microsoft.com\/en-us\/graph\/docs\/concepts\/query_parameters#count-parameter\">Count<\/a><\/h3>\n<p>Count is a useful query parameter to use when your app needs to know the number of records that exist for a given endpoint.\u00a0 The count of records will be returned as a property.<\/p>\n<p><strong>Syntax<\/strong><\/p>\n<p style=\"padding-left: 30px\">&lt;baseGraphQuery&gt;?$count=&lt;boolean&gt;<\/p>\n<p><strong>Ex.<\/strong> \u2013 Get number of contacts for the logged in user<\/p>\n<p style=\"padding-left: 30px\">https:\/\/graph.microsoft.com\/v1.0\/me\/contacts?$count=true<\/p>\n<p>&nbsp;<\/p>\n<h3><a href=\"https:\/\/developer.microsoft.com\/en-us\/graph\/docs\/concepts\/query_parameters#top-parameter\">Top<\/a><\/h3>\n<p>Queries to Microsoft Graph sometimes have more records in the result than can be returned in a single response.\u00a0 You can use the Top query parameter to set the maximum number of results to be returned.<\/p>\n<p><strong>Syntax<\/strong><\/p>\n<p style=\"padding-left: 30px\">&lt;baseGraphQuery&gt;?$top=&lt;int&gt;<\/p>\n<p><strong>Ex.<\/strong> \u2013 Get the logged in user&#8217;s OneNote notebooks, 2 per page<\/p>\n<p style=\"padding-left: 30px\">https:\/\/graph.microsoft.com\/v1.0\/me\/onenote\/notebooks?$top=2<\/p>\n<p>&nbsp;<\/p>\n<h3><a href=\"https:\/\/developer.microsoft.com\/en-us\/graph\/docs\/concepts\/query_parameters#skip-parameter\">Skip<\/a><\/h3>\n<p>Skip is another query parameter primarily used when paging results back from Microsoft Graph.\u00a0 An @odata.nextlink will typically contain a Skip or SkipToken query parameter.\u00a0 When used by itself a Skip query parameter will skip the first N number of items in the results.<\/p>\n<p><strong>Syntax<\/strong><\/p>\n<p style=\"padding-left: 30px\">&lt;baseGraphQuery&gt;?$skip=&lt;int&gt;<\/p>\n<p><strong>Ex.<\/strong> \u2013 Get the logged in user&#8217;s emails starting with the 11<sup>th<\/sup> email<\/p>\n<p style=\"padding-left: 30px\">https:\/\/graph.microsoft.com\/v1.0\/me\/messages?$skip=10<\/p>\n<p>&nbsp;<\/p>\n<h3><a href=\"https:\/\/developer.microsoft.com\/en-us\/graph\/docs\/concepts\/query_parameters#search-parameter\">Search<\/a><\/h3>\n<p>Search is like Filter in that you are restricting the response to a subset of results.\u00a0 Search has the benefit of allowing for free-text search expressions at the cost of only being available for the &#8220;message&#8221; and &#8220;person&#8221; resources.<\/p>\n<p><strong>Syntax<\/strong><\/p>\n<p style=\"padding-left: 30px\">&lt;baseGraphQuery&gt;?$search=&lt;searchCriteria&gt;<\/p>\n<p><strong>Ex.<\/strong> \u2013 Get the logged in user&#8217;s emails that contain the word &#8220;Contoso&#8221; in the message body<\/p>\n<p style=\"padding-left: 30px\">https:\/\/graph.microsoft.com\/v1.0\/me\/messages?$search=&#8221;body:Contoso&#8221;<\/p>\n<p>&nbsp;<\/p>\n<h3><a href=\"https:\/\/developer.microsoft.com\/en-us\/graph\/docs\/concepts\/query_parameters#expand-parameter\">Expand<\/a><\/h3>\n<p>As mentioned on <a href=\"https:\/\/developer.microsoft.com\/en-us\/office\/blogs\/30daysmsgraph-day-4-request-syntax\/\">Day 4<\/a>, many times entities on Microsoft Graph will have relationships to each other.\u00a0 Use the Expand query parameter to return more information about complex data types or related entities.<\/p>\n<p><strong>Syntax<\/strong><\/p>\n<p style=\"padding-left: 30px\">&lt;baseGraphQuery&gt;?$expand=&lt;property&gt;<\/p>\n<p><strong>Ex.<\/strong> \u2013 Get expanded information for logged in user&#8217;s manager<\/p>\n<p style=\"padding-left: 30px\">https:\/\/graph.microsoft.com\/beta\/me?$expand=manager<\/p>\n<p><em>Note: this example uses the beta endpoint as User entities only support the Expand query parameter on the beta version of APIs as of time of writing (Nov 2018).<\/em><\/p>\n<p>&nbsp;<\/p>\n<h2>Try It Out<\/h2>\n<p>Use query parameters we covered today to count, search, expand, and restrict results.\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\/Day06-QueryParamPt2.md\">Day 6 repo link<\/a><\/p>\n<ol>\n<li>Get number of contacts for the logged in user\n<ul>\n<li><a href=\"https:\/\/graph.microsoft.com\/v1.0\/me\/contacts?$count=true\">https:\/\/graph.microsoft.com\/v1.0\/me\/contacts?$count=true<\/a><\/li>\n<\/ul>\n<\/li>\n<li>Get the logged in user&#8217;s OneNote notebooks, 2 per page\n<ul>\n<li><a href=\"https:\/\/graph.microsoft.com\/v1.0\/me\/onenote\/notebooks?$top=2\">https:\/\/graph.microsoft.com\/v1.0\/me\/onenote\/notebooks?$top=2<\/a><\/li>\n<\/ul>\n<\/li>\n<li>Get the logged in user&#8217;s emails starting with the 11th email\n<ul>\n<li><a href=\"https:\/\/graph.microsoft.com\/v1.0\/me\/messages?$skip=10\">https:\/\/graph.microsoft.com\/v1.0\/me\/messages?$skip=10<\/a><\/li>\n<\/ul>\n<\/li>\n<li>Get the logged in user&#8217;s emails that contain the word &#8220;Contoso&#8221; in the message body\n<ul>\n<li><a href=\"https:\/\/graph.microsoft.com\/v1.0\/me\/messages?$search=%22body:Contoso\">https:\/\/graph.microsoft.com\/v1.0\/me\/messages?$search=&#8221;body:Contoso<\/a>&#8220;<\/li>\n<\/ul>\n<\/li>\n<li>Get expanded information for logged in user&#8217;s manager\n<ul>\n<li><a href=\"https:\/\/graph.microsoft.com\/beta\/me?$expand=manager\">https:\/\/graph.microsoft.com\/beta\/me?$expand=manager<\/a><\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<p>Join us tomorrow as we review paging Microsoft Graph result sets in <a href=\"https:\/\/developer.microsoft.com\/en-us\/graph\/blogs\/30daysmsgraph-day-7-paging-and-nextlink\">Day 7<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In Day 5 we began discussing the query parameters available for Microsoft Graph requests.\u00a0 Today we&#8217;ll continue 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-1977","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-microsoft-graph","tag-30daysmsgraph"],"acf":[],"blog_post_summary":"<p>In Day 5 we began discussing the query parameters available for Microsoft Graph requests.\u00a0 Today we&#8217;ll continue 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\/1977","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=1977"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/posts\/1977\/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=1977"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/categories?post=1977"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/tags?post=1977"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}