Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Notion API request fails with HTTP 504 Gateway Timeout #311

Open
fortran01 opened this issue Feb 22, 2025 · 2 comments
Open

Notion API request fails with HTTP 504 Gateway Timeout #311

fortran01 opened this issue Feb 22, 2025 · 2 comments

Comments

@fortran01
Copy link

fortran01 commented Feb 22, 2025

See the simplified logs below. I also tried reducing concurrency to 1; see the difference below.

Simplified Debug Log for 504 Gateway Timeout Issue

AxiosError: Request failed with status code 504
    at settle (...)  
    at IncomingMessage.handleStreamEnd (...)  
    at process.processTicksAndRejections (...)  

Error Code: 'ERR_BAD_RESPONSE'

Request Details:

  • Method: POST
  • URL: https://www.notion.so/api/v3/enqueueTask
  • Headers:
    • Accept: application/json, text/plain, /
    • Content-Type: application/json
    • Cookie: token_v2=***
    • User-Agent: axios/1.7.9
    • Accept-Encoding: gzip, compress, deflate, br
  • Request Body: (redacted but relevant structure)
    {
      "task": {
        "eventName": "exportBlock",
        "request": {
          "block": {
            "id": "BLOCK_ID_PLACEHOLDER",
            "spaceId": "SPACE_ID_PLACEHOLDER"
          },
          "exportOptions": {
            "exportType": "markdown",
            "locale": "en",
            "timeZone": "Europe/Vienna"
          },
          "recursive": true
        }
      }
    }

Response Details:

  • Status Code: 504 (Gateway Timeout)
  • Status Message: Gateway Timeout
  • Response Headers:
    • Server: cloudflare
    • CF-Cache-Status: DYNAMIC
    • Strict-Transport-Security: max-age=31536000; includeSubDomains; preload
    • X-Content-Type-Options: nosniff
    • Date: Sat, 22 Feb 2025 15:38:38 GMT

Response Data (HTML):

<html>
<head><title>504 Gateway Time-out</title></head>
<body>
<center><h1>504 Gateway Time-out</h1></center>
</body>
</html>

Environment:

  • Node.js Version: v22.13.1
  • Axios Version: 1.7.9
  • Timeout Setting: 0 (no timeout)

Reduce concurrency=1

diff --git a/index.ts b/index.ts
index f0c15d7..7caad01 100644
--- a/index.ts
+++ b/index.ts
@@ -5,6 +5,10 @@ import axios from 'axios';
 import extract from 'extract-zip';
 import pMap from 'p-map';
 
+// Configure the number of concurrent export tasks
+// Default is 1 to be conservative with API rate limits
+const CONCURRENT_EXPORTS = 1;
+
 const blocks = [
   {
     // Find the page block ID by either:
@@ -97,6 +101,7 @@ function delay(ms: number) {
 
 // Enqueue all export tasks immediately, without waiting for the
 // export tasks to complete
+// Process blocks with configured concurrency to avoid timeouts
 const enqueuedBlocks = await pMap(blocks, async (block) => {
   const {
     data: { taskId },
@@ -137,7 +142,7 @@ const enqueuedBlocks = await pMap(blocks, async (block) => {
     ...block,
     task: task,
   };
-});
+}, { concurrency: CONCURRENT_EXPORTS }); // Control number of concurrent exports
 
 let retries = 0;
@karlhorky
Copy link
Member

karlhorky commented Feb 23, 2025

Thanks for the issue! I can confirm that I've also been seeing 504 errors.

cc @richartkeil in case this also affects Notion Guardian

@karlhorky karlhorky changed the title Notion API request fails with 504 Gateway Timeout Notion API request fails with HTTP 504 Gateway Timeout Feb 25, 2025
@karlhorky
Copy link
Member

Looks like this is related to the X-Notion-Space-Id header - looks like we'll need to add that to the request... 🤔

eg this format:

X-Notion-Space-Id: a0b12c34-56de-7890-1f23-4gh567ij8k90

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants