title: Microsoft Graph API - 503 Service Unavailable
body: <p>I'm working to integrate Microsoft Graph with a Rails web application. We're trying to send multiple email messages via Graph, but every now and then we get a <code>503 Service Unavailable</code> with the following headers and body:</p>
  
  <p>Response headers:</p>
  
  <pre class="lang-html prettyprint-override"><code>{
    "content-type": [
      "text/html; charset=us-ascii"
    ],
    "server": [
      "Microsoft-HTTPAPI/2.0"
    ],
    "date": [
      "Wed, 30 May 2018 22:05:31 GMT"
    ],
    "connection": [
      "close"
    ],
    "content-length": [
      326
    ]
  }
  </code></pre>
  
  <p>Response body:</p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd"&gt;
  &lt;HTML&gt;
  &lt;HEAD&gt;
      &lt;TITLE&gt;Service Unavailable&lt;/TITLE&gt;
      &lt;META HTTP-EQUIV="Content-Type" Content="text/html; charset=us-ascii"&gt;
  &lt;/HEAD&gt;
  &lt;BODY&gt;
      &lt;h2&gt;Service Unavailable&lt;/h2&gt;
      &lt;hr&gt;
      &lt;p&gt;HTTP Error 503. The service is unavailable.&lt;/p&gt;
  &lt;/BODY&gt;
  &lt;/HTML&gt;
  </code></pre>
  
  <p>We use the <code>POST https://graph.microsoft.com/v1.0/me/sendMail</code> call to send hundreds of outlook emails. After sending roughly 100-200 emails with the Graph API we get the <code>503 Service Unavailable</code> error. <strong>This is problematic when we have to send 1000+ customized emails</strong> since it is unclear to me how we could properly <strong>handle the error without knowing how long to wait before retrying and other Graph API request</strong>.</p>
  
  <p>I'm wondering if anyone has run into a similar issue before. I've read about something similar along the lines of client throttling (<a href="https://stackoverflow.com/questions/47654844/microsoft-graph-api-throttling">Microsoft Graph API - Throttling</a>), but in this post, they're getting <code>409</code> (with a <code>retry-after</code> header), not <code>503</code>.</p>
  
  <p>Based on the <a href="https://developer.microsoft.com/en-us/graph/docs/concepts/errors" rel="noreferrer">Graph documentations</a>, we're supposed to receive a JSON object that may contain a <code>Retry-After</code> header. However, as shown above, we're neither getting the <code>Retry-After</code> header nor a JSON object for the <code>503</code> error.</p>