{"id":1274,"date":"2018-01-19T22:47:17","date_gmt":"2018-01-20T06:47:17","guid":{"rendered":"https:\/\/officedevblogs.wpengine.com\/?p=1274"},"modified":"2021-10-18T13:17:13","modified_gmt":"2021-10-18T20:17:13","slug":"error-improvement-for-invalid-x-anchormailbox-in-rest-api-calls","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/error-improvement-for-invalid-x-anchormailbox-in-rest-api-calls\/","title":{"rendered":"Error improvement for invalid X-AnchorMailbox in REST API calls"},"content":{"rendered":"<p><strong>Update 1\/29:\u00a0<\/strong>Based on feedback, we&#8217;ve adjusted the HTTP status code to\u00a0<code>400<\/code>\u00a0instead of\u00a0<code>421<\/code>. All other details remain the same.<\/p>\n<p>We wanted to give you a heads-up on a recent change to the error returned by the Outlook REST API when the value of the\u00a0<code>X-AnchorMailbox<\/code>\u00a0is incorrect. If your app has error-handling for this scenario based on the current behavior of the service, this may be a breaking change.<\/p>\n<p>Starting immediately, the service will start returning a\u00a0<code>400 Bad Request<\/code>\u00a0status instead of a\u00a0<code>503 Service Unavailable<\/code>. The intent of this change is to return a more appropriate HTTP status and to make it easier for developers to detect why the request failed and fix the problem.<\/p>\n<h2 id=\"old-behavior\">Old behavior<\/h2>\n<p>Prior to this change, sending a REST API request with an incorrect\u00a0<code>X-AnchorMailbox<\/code>\u00a0header would result in the following response.<\/p>\n<pre><code>HTTP\/1.1 503 Service Unavailable\n\n{\n  \"error\": {\n    \"code\": \"MailboxInfoStale\",\n    \"message\": \"Mailbox info is stale.\"\n  }\n}\n<\/code><\/pre>\n<h2 id=\"new-behavior\">New behavior<\/h2>\n<p>With this change, if your app receives a\u00a0<code>400<\/code>\u00a0HTTP status from a REST call, you should check the response body for an\u00a0<code>error<\/code>\u00a0object, then check the\u00a0<code>code<\/code>\u00a0property. If it is\u00a0<code>ErrorIncorrectRoutingHint<\/code>, the value you sent in the\u00a0<code>X-AnchorMailbox<\/code>\u00a0is incorrect.<\/p>\n<pre><code>HTTP\/1.1 400 Bad Request\n\n{\n  \"error\": {\n    \"code\": \"ErrorIncorrectRoutingHint\",\n    \"message\": \"The x-anchor mailbox 'jason@contoso.com' does not match the target of the request.\"\n  }\n}\n<\/code><\/pre>\n<h2 id=\"handling-the-error\">Handling the error<\/h2>\n<p>If your app gets this error, it is recommended that you get the user&#8217;s mailbox GUID and use that for the\u00a0<code>X-AnchorMailbox<\/code>\u00a0value, instead of the user&#8217;s SMTP address. You can get the user&#8217;s mailbox GUID by making the following REST request (with no\u00a0<code>X-AnchorMailbox<\/code>header):<\/p>\n<pre><code>GET https:\/\/outlook.office.com\/api\/v2.0\/me\n<\/code><\/pre>\n<p>This will return the following response:<\/p>\n<pre><code class=\"lang-json\">{\n  \"Id\": \"3c7f0e3a-623b-85ae-4032-07d41531beff@7aeb6117-c342-4861-bec7-f8803ae85e41\",\n  \"EmailAddress\": \"jason@contoso.onmicrosoft.com\",\n  \"DisplayName\": \"Jason Johnston\",\n  \"Alias\": \"jason\",\n  \"MailboxGuid\": \"fece2b65-3577-4972-bf3d-5594fc9c9f9e\"\n}\n<\/code><\/pre>\n<p>You would then use the value of\u00a0<code>MailboxGuid<\/code>\u00a0in the\u00a0<code>X-AnchorMailbox<\/code>\u00a0for subsequent REST calls.<\/p>\n<pre><code>GET https:\/\/outlook.office.com\/api\/v2.0\/me\/messages\n\nX-AnchorMailbox: fece2b65-3577-4972-bf3d-5594fc9c9f9e<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>We wanted to give you a heads-up on a recent change to the error returned by the Outlook REST API when the value of the\u00a0X-AnchorMailbox\u00a0is incorrect. If your app has error-handling for this scenario based on the current behavior of the service, this may be a breaking change.<\/p>\n","protected":false},"author":69108,"featured_media":25159,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[12],"class_list":["post-1274","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-microsoft-365-developer","tag-outlook"],"acf":[],"blog_post_summary":"<p>We wanted to give you a heads-up on a recent change to the error returned by the Outlook REST API when the value of the\u00a0X-AnchorMailbox\u00a0is incorrect. If your app has error-handling for this scenario based on the current behavior of the service, this may be a breaking change.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/posts\/1274","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\/69108"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/comments?post=1274"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/posts\/1274\/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=1274"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/categories?post=1274"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/tags?post=1274"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}