title: Error (403) when using UrlFetchApp to address an endpoint from https://discord.com
body: <p>Discord recently announced that they move their API from discordapp.com to discord.com.</p>
  <p>I'm in the midst of rewriting some code of mine (Google Apps Script project) to account for that, but I'm running into the problem of not being able to access the <code>discord.com</code>-endpoints, e.g.:</p>
  <pre class="lang-js prettyprint-override"><code>function example(){
    var headers =
    {
      &quot;Authorization&quot;: &quot;Bot AbCdEfG123&quot;,
      &quot;Accept&quot;: &quot;*/*&quot;
    };
    var options =
    {
      &quot;method&quot;: &quot;GET&quot;,
      &quot;headers&quot;: headers,
    };
    var response = UrlFetchApp.fetch(&quot;https://discord.com/api/guilds/&quot;+GUILD_ID+&quot;/members/&quot;+MEMBER_ID, options);
  }
  </code></pre>
  <p>even though using the old <code>discordapp.com</code> works perfectly fine.
  Using <code>discord.com</code> results in a 403 error, with <code>error code 1020</code>.</p>
  <p>Further investigation:</p>
  <ul>
  <li>Performing the same requests (against <code>discord.com</code>) via Postman or curl is successful, so it looks like the problem lies with UrlFetchApp</li>
  <li>By adding <code>&quot;Accept&quot;: &quot;*/*&quot;</code> to the headers, I found out that the error comes from Cloudflare, along with the message <code>Please enable cookies</code>.</li>
  <li>Adding a User-Agent to the headers, e.g. <code>&quot;User-Agent&quot;: &quot;MyBot/1.0&quot;</code> doesn't change anything</li>
  </ul>
  <p>I have no idea how to deal with this and I'm wondering if anyone else has encountered this issue. I'm grateful for any help.</p>
  <p><strong>edit:</strong></p>
  <p>Here's the requested documentation:</p>
  <ul>
  <li>Discord: <a href="https://discord.com/developers/docs/reference" rel="nofollow noreferrer">https://discord.com/developers/docs/reference</a></li>
  <li>UrlFetchApp: <a href="https://developers.google.com/apps-script/reference/url-fetch/url-fetch-app" rel="nofollow noreferrer">https://developers.google.com/apps-script/reference/url-fetch/url-fetch-app</a></li>
  </ul>
  <p>The curl code that works is</p>
  <pre><code>curl -H &quot;Authorization: Bot [...]&quot; &quot;https://discord.com/api/guilds/[...]/members/[...]&quot;
  </code></pre>
  <p>with an ellipsis <code>[...]</code> representing the token or IDs</p>
  <p><strong>edit 2:</strong></p>
  <p>Google Apps Script uses the following unmodifiable user-agent:</p>
  <pre><code>Mozilla/5.0 (compatible; Google-Apps-Script; beanserver; +https://script.google.com; id: [...])
  </code></pre>
  <p>Even if I take only the Mozilla part into my curl command, i.e.</p>
  <pre><code>curl -H &quot;Authorization: Bot [...]&quot; -H &quot;user-agent: Mozilla&quot; &quot;https://discord.com/api/guilds/[...]/members/[...]&quot;
  </code></pre>
  <p>I get the same <code>1020</code> error code.</p>