seratch / notion-translator

CLI tool to translate Notion pages into a different language
MIT License
70 stars 20 forks source link

400 validation error when createNewPageForTranslation #3

Closed pavzagor closed 1 year ago

pavzagor commented 1 year ago

Gist

Seem to create the empty page but then fails with a 400 validation error. Might be something connected to Notion API changes (error is obviously from Notion API). It creates a page but then fails to fill it with elements.

I tried debugging myself but I'm not good at JS + don't really know how to debug CLIs.

I think it should be something simple. Perhaps some condition needed to ignore empty blocks. Judging from the output, the error is in one particular child block.

Inputs

ru → en-us Page for translation (accessible via seratch@gmail.com)

Output

Last login: Wed Nov  9 16:43:23 on ttys000
bash: brew: command not found

The default interactive shell is now zsh.
To update your account to use zsh, please run `chsh -s /bin/zsh`.
For more details, please visit https://support.apple.com/kb/HT208050.
pavzagor-Macbook-pro-14:~ pavelzagorodnikh$ notion-translator -f ru -t en-us -u https://www.notion.so/kodland/Magic-of-code-with-Scratch-M4L4-20-1-83e1a53899e14019ae1a50553cd318f0

Wait a minute! Now translating the following Notion page:
https://www.notion.so/kodland/Magic-of-code-with-Scratch-M4L4-20-1-83e1a53899e14019ae1a50553cd318f0

(this may take some time) ....................................../opt/homebrew/lib/node_modules/notion-translator/node_modules/@notionhq/client/build/src/errors.js:162
        return new APIResponseError({
               ^

APIResponseError: body failed validation. Fix one:
body.children[28].embed should be defined, instead was `undefined`.
body.children[28].bookmark should be defined, instead was `undefined`.
body.children[28].image should be defined, instead was `undefined`.
body.children[28].video should be defined, instead was `undefined`.
body.children[28].pdf should be defined, instead was `undefined`.
body.children[28].file should be defined, instead was `undefined`.
body.children[28].audio should be defined, instead was `undefined`.
body.children[28].code should be defined, instead was `undefined`.
body.children[28].equation should be defined, instead was `undefined`.
body.children[28].divider should be defined, instead was `undefined`.
body.children[28].breadcrumb should be defined, instead was `undefined`.
body.children[28].table_of_contents should be defined, instead was `undefined`.
body.children[28].link_to_page should be defined, instead was `undefined`.
body.children[28].table_row should be defined, instead was `undefined`.
body.children[28].column_list should be defined, instead was `undefined`.
body.children[28].column should be defined, instead was `undefined`.
body.children[28].table should be defined, instead was `undefined`.
body.children[28].heading_1 should be defined, instead was `undefined`.
body.children[28].heading_2 should be defined, instead was `undefined`.
body.children[28].heading_3 should be defined, instead was `undefined`.
body.children[28].paragraph should be defined, instead was `undefined`.
body.children[28].bulleted_list_item should be defined, instead was `undefined`.
body.children[28].numbered_list_item should be defined, instead was `undefined`.
body.children[28].quote should be defined, instead was `undefined`.
body.children[28].to_do should be defined, instead was `undefined`.
body.children[28].toggle should be defined, instead was `undefined`.
body.children[28].template should be defined, instead was `undefined`.
body.children[28].callout should be defined, instead was `undefined`.
body.children[28].synced_block should be defined, instead was `undefined`.
    at buildRequestError (/opt/homebrew/lib/node_modules/notion-translator/node_modules/@notionhq/client/build/src/errors.js:162:16)
    at Client.request (/opt/homebrew/lib/node_modules/notion-translator/node_modules/@notionhq/client/build/src/Client.js:304:54)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async /opt/homebrew/lib/node_modules/notion-translator/index.js:396:26 {
  code: 'validation_error',
  status: 400,
  headers: Headers {
    [Symbol(map)]: [Object: null prototype] {
      date: [ 'Wed, 09 Nov 2022 14:17:20 GMT' ],
      'content-type': [ 'application/json; charset=utf-8' ],
      'transfer-encoding': [ 'chunked' ],
      connection: [ 'close' ],
      'set-cookie': [
        'notion_browser_id=some_id; Domain=www.notion.so; Path=/; Expires=Thu, 09 Nov 2023 14:17:19 GMT; Secure',
        'notion_check_cookie_consent=true; Domain=www.notion.so; Path=/; Expires=Thu, 10 Nov 2022 14:17:19 GMT; Secure'
      ],
      'content-security-policy': [
        "script-src 'self' 'unsafe-inline' 'unsafe-eval' https://gist.github.com https://apis.google.com https://www.google.com https://www.gstatic.com https://cdn.amplitude.com https://api.amplitude.com https://hkfxbbdzib.notion.so https://widget.intercom.io https://js.intercomcdn.com https://static.zdassets.com https://api.smooch.io\t https://logs-01.loggly.com https://http-inputs-notion.splunkcloud.com https://cdn.segment.com https://analytics.pgncs.notion.so https://o324374.ingest.sentry.io https://checkout.stripe.com https://js.stripe.com https://embed.typeform.com https://admin.typeform.com https://public.profitwell.com js.sentry-cdn.com https://js.chilipiper.com https://platform.twitter.com https://cdn.syndication.twimg.com https://accounts.google.com https://www.googletagmanager.com https://www.googleadservices.com https://googleads.g.doubleclick.net https://api-v2.mutinyhq.io https://client-registry.mutinycdn.com https://client.mutinycdn.com https://user-data.mutinycdn.com https://metadata-static-files.sfo2.cdn.digitaloceanspaces.com https://platformapi.metadata.io https://cdn01.boxcdn.net;connect-src 'self' https://msgstore.www.notion.so wss://msgstore.www.notion.so ws://localhost:* ws://127.0.0.1:* https://notion-emojis.s3-us-west-2.amazonaws.com https://s3-us-west-2.amazonaws.com https://s3.us-west-2.amazonaws.com https://notion-production-snapshots-2.s3.us-west-2.amazonaws.com https://cdn.amplitude.com https://api.amplitude.com https://hkfxbbdzib.notion.so https://www.notion.so https://api.embed.ly https://js.intercomcdn.com https://api-iam.intercom.io https://uploads.intercomcdn.com wss://nexus-websocket-a.intercom.io https://ekr.zdassets.com https://ekr.zendesk.com\t https://makenotion.zendesk.com\t https://api.smooch.io\t wss://api.smooch.io\t https://logs-01.loggly.com https://http-inputs-notion.splunkcloud.com https://cdn.segment.com https://api.segment.io https://analytics.pgncs.notion.so https://api.pgncs.notion.so https://o324374.ingest.sentry.io https://checkout.stripe.com https://js.stripe.com https://cdn.contentful.com https://preview.contentful.com https://images.ctfassets.net https://www2.profitwell.com https://tracking.chilipiper.com https://api.chilipiper.com https://api.unsplash.com https://boards-api.greenhouse.io https://accounts.google.com https://oauth2.googleapis.com https://www.googletagmanager.com https://analytics.google.com https://www.googleadservices.com https://googleads.g.doubleclick.net https://region1.google-analytics.com https://region1.analytics.google.com https://www.google-analytics.com https://api-v2.mutinyhq.io https://client-registry.mutinycdn.com https://client.mutinycdn.com https://user-data.mutinycdn.com https://metadata-static-files.sfo2.cdn.digitaloceanspaces.com https://platformapi.metadata.io https://api.statuspage.io https://pgncd.notion.so https://api.statsig.com https://statsigapi.net https://exp.notion.so https://file.notion.so https://api.box.com;font-src 'self' data: https://cdnjs.cloudflare.com https://js.intercomcdn.com https://cdn01.boxcdn.net;img-src 'self' data: blob: https: https://platform.twitter.com https://syndication.twitter.com https://pbs.twimg.com https://ton.twimg.com https://region1.google-analytics.com https://region1.analytics.google.com;style-src 'self' 'unsafe-inline' https://cdnjs.cloudflare.com https://github.githubassets.com https://js.chilipiper.com https://platform.twitter.com https://ton.twimg.com https://accounts.google.com https://cdn01.boxcdn.net;frame-src https: http: https://accounts.google.com;media-src https: http: https://file.notion.so"
      ],
      'x-dns-prefetch-control': [ 'off' ],
      'x-frame-options': [ 'SAMEORIGIN' ],
      'strict-transport-security': [ 'max-age=5184000; includeSubDomains' ],
      'x-download-options': [ 'noopen' ],
      'x-content-type-options': [ 'nosniff' ],
      'x-permitted-cross-domain-policies': [ 'none' ],
      'referrer-policy': [ 'strict-origin-when-cross-origin' ],
      'x-xss-protection': [ '0' ],
      etag: [ 'W/"895-wGCgVAkQCsyYKFvOSpC/PhmY/jI"' ],
      vary: [ 'Accept-Encoding' ],
      'content-encoding': [ 'gzip' ],
      'cf-cache-status': [ 'DYNAMIC' ],
      server: [ 'cloudflare' ],
      'cf-ray': [ '76772bda88c26249-OTP' ]
    }
  },
  body: '{"object":"error","status":400,"code":"validation_error","message":"body failed validation. Fix one:\\nbody.children[28].embed should be defined, instead was `undefined`.\\nbody.children[28].bookmark should be defined, instead was `undefined`.\\nbody.children[28].image should be defined, instead was `undefined`.\\nbody.children[28].video should be defined, instead was `undefined`.\\nbody.children[28].pdf should be defined, instead was `undefined`.\\nbody.children[28].file should be defined, instead was `undefined`.\\nbody.children[28].audio should be defined, instead was `undefined`.\\nbody.children[28].code should be defined, instead was `undefined`.\\nbody.children[28].equation should be defined, instead was `undefined`.\\nbody.children[28].divider should be defined, instead was `undefined`.\\nbody.children[28].breadcrumb should be defined, instead was `undefined`.\\nbody.children[28].table_of_contents should be defined, instead was `undefined`.\\nbody.children[28].link_to_page should be defined, instead was `undefined`.\\nbody.children[28].table_row should be defined, instead was `undefined`.\\nbody.children[28].column_list should be defined, instead was `undefined`.\\nbody.children[28].column should be defined, instead was `undefined`.\\nbody.children[28].table should be defined, instead was `undefined`.\\nbody.children[28].heading_1 should be defined, instead was `undefined`.\\nbody.children[28].heading_2 should be defined, instead was `undefined`.\\nbody.children[28].heading_3 should be defined, instead was `undefined`.\\nbody.children[28].paragraph should be defined, instead was `undefined`.\\nbody.children[28].bulleted_list_item should be defined, instead was `undefined`.\\nbody.children[28].numbered_list_item should be defined, instead was `undefined`.\\nbody.children[28].quote should be defined, instead was `undefined`.\\nbody.children[28].to_do should be defined, instead was `undefined`.\\nbody.children[28].toggle should be defined, instead was `undefined`.\\nbody.children[28].template should be defined, instead was `undefined`.\\nbody.children[28].callout should be defined, instead was `undefined`.\\nbody.children[28].synced_block should be defined, instead was `undefined`."}'
}

Node.js v19.0.1
seratch commented 1 year ago

Hi @pavzagor, thanks for reporting this issue! I've resolved it in the latest version - 0.0.3. Please upgrade to the latest version.

RuslanCheboksarov commented 1 year ago

Hello. Even though I've upgraded notion-translator to 0.0.3 version the issue still remains

ruslanceboksarov@MacBook-Air-Ruslan ~ % npm list ruslanceboksarov@ /Users/ruslanceboksarov └── notion-translator@0.0.3

`@notionhq/client info: request start {
  method: 'patch',
  path: 'blocks/9f6d6a8f-53d4-4a2c-9c3b-ae30b1baf564/children'
}
@notionhq/client warn: request fail {
  code: 'validation_error',
  message: 'Content creation Failed. Fix the following: \n' +
    "Could not find user with ID: 4664ffc2-a79c-4c82-8d0d-25c05c854116. Only members and guests in the integration's workspace are visible."
}
@notionhq/client debug: failed response body {
  body: `{"object":"error","status":400,"code":"validation_error","message":"Content creation Failed. Fix the following: \\nCould not find user with ID: 4664ffc2-a79c-4c82-8d0d-25c05c854116. Only members and guests in the integration's workspace are visible."}`
}
/Users/ruslanceboksarov/.nvm/versions/node/v19.0.1/lib/node_modules/notion-translator/node_modules/@notionhq/client/build/src/errors.js:162
        return new APIResponseError({
               ^

APIResponseError: Content creation Failed. Fix the following: 
Could not find user with ID: 4664ffc2-a79c-4c82-8d0d-25c05c854116. Only members and guests in the integration's workspace are visible.
    at buildRequestError (/Users/ruslanceboksarov/.nvm/versions/node/v19.0.1/lib/node_modules/notion-translator/node_modules/@notionhq/client/build/src/errors.js:162:16)
    at Client.request (/Users/ruslanceboksarov/.nvm/versions/node/v19.0.1/lib/node_modules/notion-translator/node_modules/@notionhq/client/build/src/Client.js:304:54)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async /Users/ruslanceboksarov/.nvm/versions/node/v19.0.1/lib/node_modules/notion-translator/index.js:399:26 {
  code: 'validation_error',
  status: 400,
  headers: Headers {
    [Symbol(map)]: [Object: null prototype] {
      date: [ 'Thu, 10 Nov 2022 09:12:59 GMT' ],
      'content-type': [ 'application/json; charset=utf-8' ],
      'content-length': [ '250' ],
      connection: [ 'close' ],
      'set-cookie': [
        'notion_browser_id=692e2d40-a762-46d0-a183-59b826663097; Domain=www.notion.so; Path=/; Expires=Fri, 10 Nov 2023 09:12:59 GMT; Secure',
        'notion_check_cookie_consent=false; Domain=www.notion.so; Path=/; Expires=Fri, 11 Nov 2022 09:12:59 GMT; Secure'
      ],
      'content-security-policy': [
        "script-src 'self' 'unsafe-inline' 'unsafe-eval' https://gist.github.com https://apis.google.com https://www.google.com https://www.gstatic.com https://cdn.amplitude.com https://api.amplitude.com https://hkfxbbdzib.notion.so https://widget.intercom.io https://js.intercomcdn.com https://static.zdassets.com https://api.smooch.io\t https://logs-01.loggly.com https://http-inputs-notion.splunkcloud.com https://cdn.segment.com https://analytics.pgncs.notion.so https://o324374.ingest.sentry.io https://checkout.stripe.com https://js.stripe.com https://embed.typeform.com https://admin.typeform.com https://public.profitwell.com js.sentry-cdn.com https://js.chilipiper.com https://platform.twitter.com https://cdn.syndication.twimg.com https://accounts.google.com https://www.googletagmanager.com https://www.googleadservices.com https://googleads.g.doubleclick.net https://api-v2.mutinyhq.io https://client-registry.mutinycdn.com https://client.mutinycdn.com https://user-data.mutinycdn.com https://metadata-static-files.sfo2.cdn.digitaloceanspaces.com https://platformapi.metadata.io https://cdn01.boxcdn.net;connect-src 'self' https://msgstore.www.notion.so wss://msgstore.www.notion.so ws://localhost:* ws://127.0.0.1:* https://notion-emojis.s3-us-west-2.amazonaws.com https://s3-us-west-2.amazonaws.com https://s3.us-west-2.amazonaws.com https://notion-production-snapshots-2.s3.us-west-2.amazonaws.com https://cdn.amplitude.com https://api.amplitude.com https://hkfxbbdzib.notion.so https://www.notion.so https://api.embed.ly https://js.intercomcdn.com https://api-iam.intercom.io https://uploads.intercomcdn.com wss://nexus-websocket-a.intercom.io https://ekr.zdassets.com https://ekr.zendesk.com\t https://makenotion.zendesk.com\t https://api.smooch.io\t wss://api.smooch.io\t https://logs-01.loggly.com https://http-inputs-notion.splunkcloud.com https://cdn.segment.com https://api.segment.io https://analytics.pgncs.notion.so https://api.pgncs.notion.so https://o324374.ingest.sentry.io https://checkout.stripe.com https://js.stripe.com https://cdn.contentful.com https://preview.contentful.com https://images.ctfassets.net https://www2.profitwell.com https://tracking.chilipiper.com https://api.chilipiper.com https://api.unsplash.com https://boards-api.greenhouse.io https://accounts.google.com https://oauth2.googleapis.com https://www.googletagmanager.com https://analytics.google.com https://www.googleadservices.com https://googleads.g.doubleclick.net https://region1.google-analytics.com https://region1.analytics.google.com https://www.google-analytics.com https://api-v2.mutinyhq.io https://client-registry.mutinycdn.com https://client.mutinycdn.com https://user-data.mutinycdn.com https://metadata-static-files.sfo2.cdn.digitaloceanspaces.com https://platformapi.metadata.io https://api.statuspage.io https://pgncd.notion.so https://api.statsig.com https://statsigapi.net https://exp.notion.so https://file.notion.so https://api.box.com;font-src 'self' data: https://cdnjs.cloudflare.com https://js.intercomcdn.com https://cdn01.boxcdn.net;img-src 'self' data: blob: https: https://platform.twitter.com https://syndication.twitter.com https://pbs.twimg.com https://ton.twimg.com https://region1.google-analytics.com https://region1.analytics.google.com;style-src 'self' 'unsafe-inline' https://cdnjs.cloudflare.com https://github.githubassets.com https://js.chilipiper.com https://platform.twitter.com https://ton.twimg.com https://accounts.google.com https://cdn01.boxcdn.net;frame-src https: http: https://accounts.google.com;media-src https: http: https://file.notion.so"
      ],
      'x-dns-prefetch-control': [ 'off' ],
      'x-frame-options': [ 'SAMEORIGIN' ],
      'strict-transport-security': [ 'max-age=5184000; includeSubDomains' ],
      'x-download-options': [ 'noopen' ],
      'x-content-type-options': [ 'nosniff' ],
      'x-permitted-cross-domain-policies': [ 'none' ],
      'referrer-policy': [ 'strict-origin-when-cross-origin' ],
      'x-xss-protection': [ '0' ],
      etag: [ 'W/"fa-gF64dbew3UstziatZl/83dCY3f0"' ],
      vary: [ 'Accept-Encoding' ],
      'cf-cache-status': [ 'DYNAMIC' ],
      server: [ 'cloudflare' ],
      'cf-ray': [ '767dab6a7ace16cf-DME' ]
    }
  },
  body: `{"object":"error","status":400,"code":"validation_error","message":"Content creation Failed. Fix the following: \\nCould not find user with ID: 4664ffc2-a79c-4c82-8d0d-25c05c854116. Only members and guests in the integration's workspace are visible."}`
}

Node.js v19.0.1`

Also I've attached JSON file that I've created after launching the following command: ruslanceboksarov@MacBook-Air-Ruslan ~ % notion-translator -d -f ru -t en-us -u https://www.notion.so/kodland/Magic-of-code-with-Scratch-M4L4-20-1-a262eabb5f4542a2a3d6bbc66ed3ece3

Debug-result.json.zip

seratch commented 1 year ago

@pavzagor When you have mentions in a page, the API token needs to have the permission to read user information. Please update your integration settings at https://www.notion.so/my-integrations as below:

I will update the README to cover this pattern later.

RuslanCheboksarov commented 1 year ago
Снимок экрана 2022-11-10 в 5 15 53 PM

We have following integration settings @seratch

seratch commented 1 year ago

I don't think it fails with the settings. Please make sure that you're using the correct token for running this tool

RuslanCheboksarov commented 1 year ago

@seratch idk why but it worked - I've been using old integration token and now when it's updated it worked correctly. Thank you for you time!

pavzagor commented 1 year ago

Still breaks 😢

Details in the commit comment: https://github.com/seratch/notion-translator/commit/d5df5a0cd3f7ff5e3b9c1d6845fa825ddef79ad0#commitcomment-90249848