title: Graph Mail API: 504 Gateway Timeout Errors
body: <p>I have a script which downloads messages from an Office 365 mailbox. In the logs for the script I am noticing a lot of responses with this error <code>Response: 504, Gateway Timeout</code>. The error occurs a few times a week at somewhat sporadic times. Here are the dateimes for the last few occurances: </p>
  
  <ul>
  <li>12/05/2018 07:51:44 PM </li>
  <li>12/05/2018 05:50:58 PM </li>
  <li>12/05/2018 03:50:54 PM</li>
  <li>12/05/2018 03:51:01 AM </li>
  <li>12/04/2018 05:53:13 PM </li>
  <li>11/28/2018 03:50:53 AM</li>
  <li>11/22/2018 11:50:53 PM</li>
  </ul>
  
  <p>The rest of the time the script works perfectly without error. The <a href="https://docs.microsoft.com/en-us/graph/errors" rel="nofollow noreferrer">documentation</a> state's that this error code indicates that: </p>
  
  <blockquote>
    <p>"The server, while acting as a proxy, did not receive a timely
    response from the upstream server it needed to access in attempting to
    complete the request. May occur together with 503."</p>
  </blockquote>
  
  <p>I have seen a few other posts about this but none of them really offered an explanation as to why this error occurs, or what can be done to avoid it. If the server response is timing out does this mean that I need to change my requests? Right now I am requesting the messages in chunks of 1000 using the <code>@odata.nextLink</code> response parameter to request the next chunk. </p>