{"id":4056,"date":"2023-02-28T20:47:58","date_gmt":"2023-02-28T19:47:58","guid":{"rendered":"https:\/\/www.lieben.nu\/liebensraum\/?p=4056"},"modified":"2023-02-28T20:47:58","modified_gmt":"2023-02-28T19:47:58","slug":"the-mysterious-x-ms-forest-header","status":"publish","type":"post","link":"https:\/\/lieben.nu\/liebensraum\/2023\/02\/the-mysterious-x-ms-forest-header\/","title":{"rendered":"The mysterious X-MS-Forest header"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">When working with the api.interfaces.records.teams.microsoft.com API, I noticed that the MS portal uses an X-MS-Forest header.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">At first, ignoring this went fine as doing GET calls to this api didn&#8217;t seem to require it. But, of course the moment I wanted more, it suddenly WAS required (PUT\/POST).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The question was; how does the portal determine the value for this header and how do we replicate that? Well, that wasn&#8217;t difficult: apparently a call to api.interfaces.records.teams.microsoft.com\/Teams.Tenant\/tenants suffices and returns the value for the X-MS-Forest header for the tenant identified in your token. Example:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: powershell; title: ; notranslate\" title=\"\">\n    $headers = Get-GraphToken -tenantid $tenantId -scope \"https:\/\/api.interfaces.records.teams.microsoft.com\/user_impersonation\"\n    #get the correct forest\n    $tenantInfo = Invoke-RestMethod -Method GET -uri \"https:\/\/api.interfaces.records.teams.microsoft.com\/Teams.Tenant\/tenants\" -UseBasicParsing -ContentType \"application\/json\" -Headers $headers\n    #add the X-MS-Forest header (required) for subsequent calls\n    $headers&#x5B;\"X-MS-Forest\"] = $tenantInfo.serviceDiscovery.Headers.'X-MS-Forest'\n<\/pre><\/div>\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n\n<\/pre><\/div>","protected":false},"excerpt":{"rendered":"<p>When working with the api.interfaces.records.teams.microsoft.com API, I noticed that the MS portal uses an X-MS-Forest header. At first, ignoring this went fine as doing GET calls to this api didn&#8217;t seem to require it. But, of course the moment I wanted more, it suddenly WAS required (PUT\/POST). The question was; how does the portal determine &hellip; <a href=\"https:\/\/lieben.nu\/liebensraum\/2023\/02\/the-mysterious-x-ms-forest-header\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">The mysterious X-MS-Forest header<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_crdt_document":"","footnotes":""},"categories":[4,7,27,32,39,45],"tags":[],"class_list":["post-4056","post","type-post","status-publish","format-standard","hentry","category-automation","category-azuread","category-microsoft-teams","category-office-365","category-powershell","category-skype-online"],"_links":{"self":[{"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/posts\/4056","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/comments?post=4056"}],"version-history":[{"count":0,"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/posts\/4056\/revisions"}],"wp:attachment":[{"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/media?parent=4056"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/categories?post=4056"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/tags?post=4056"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}