YouTube.js icon indicating copy to clipboard operation
YouTube.js copied to clipboard

Getting 400 BadRequest "Request contains an invalid argument" from almost every getX method

Open koraybilgi opened this issue 9 months ago • 12 comments

Description:

When executing the Innertube.getHistory method the request fails with a 400 status code. It was working without any problems for a number of clients about 8 hours ago.

Update:

Getting the same error almost every getX function

Steps to reproduce:

  1. Initialize Innertube client
  2. Try to fetch watch hisroty data using getHistory()
...

this.#sessionClient = await Innertube.create({
  ...options,
  timezone: LOCAL_TIMEZONE,
  lang: "en",
  cache: new UniversalCache(true, getCacheDir(sessionId))
});

...

const history = await this.#sessionClient?.getHistory();

Failure Logs:

InnertubeError: Request to https://www.youtube.com/youtubei/v1/browse?prettyPrint=false&alt=json failed with status 400
    at HTTPClient.fetch (/opt/youtube-client/node_modules/youtubei.js/src/utils/HTTPClient.ts:162:11)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at Actions.execute (/opt/youtube-client/node_modules/youtubei.js/src/core/Actions.ts:166:22)
    at Innertube.getHistory (/opt/youtube-client/node_modules/youtubei.js/src/Innertube.ts:339:22)
    {
  info: '{\n' +
    '  "error": {\n' +
    '    "code": 400,\n' +
    '    "message": "Request contains an invalid argument.",\n' +
    '    "errors": [\n' +
    '      {\n' +
    '        "message": "Request contains an invalid argument.",\n' +
    '        "domain": "global",\n' +
    '        "reason": "badRequest"\n' +
    '      }\n' +
    '    ],\n' +
    '    "status": "INVALID_ARGUMENT"\n' +
    '  }\n' +
    '}\n',
  date: 2025-03-08T03:12:10.115Z,
  version: '13.1.0'
}

Additional Context:

  • Using a verified Google OAuth Platform client with the scopes:
    • auth/youtube
    • auth/youtube.force-ssl
    • auth/youtube-paid-content
  • Tried YoutubeTv client as well.

Environment:

  • YouTube.js version: 13.1.0
  • Node.js version: v20.12.2
  • Operating System: Ubuntu 22.04

Expected behavior:

  • Should return history data.
  • Should work similarly to YouTube's web interface.

Current behavior:

Returns error 400 (Bad Request):

InnertubeError: Request to https://www.youtube.com/youtubei/v1/browse?prettyPrint=false&alt=json failed with status 400
    at HTTPClient.fetch (/opt/youtube-client/node_modules/youtubei.js/src/utils/HTTPClient.ts:162:11)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at Actions.execute (/opt/youtube-client/node_modules/youtubei.js/src/core/Actions.ts:166:22)
    at Innertube.getHistory (/opt/youtube-client/node_modules/youtubei.js/src/Innertube.ts:339:22)
    {
  info: '{\n' +
    '  "error": {\n' +
    '    "code": 400,\n' +
    '    "message": "Request contains an invalid argument.",\n' +
    '    "errors": [\n' +
    '      {\n' +
    '        "message": "Request contains an invalid argument.",\n' +
    '        "domain": "global",\n' +
    '        "reason": "badRequest"\n' +
    '      }\n' +
    '    ],\n' +
    '    "status": "INVALID_ARGUMENT"\n' +
    '  }\n' +
    '}\n',
  date: 2025-03-08T03:12:10.115Z,
  version: '13.1.0'
}

Version

13.1.0

Anything else?

No

Checklist:

  • [x] I am running the latest version.
  • [x] I checked the documentation and found no answer.
  • [x] I have searched the existing issues and made sure this is not a duplicate.
  • [x] I have provided sufficient information.

koraybilgi avatar Mar 08 '25 03:03 koraybilgi

I'm having the same issue. I tried logging in with a different account and a different device, but it's still the same. Maybe YouTube updated their API

farhaanaliii avatar Mar 08 '25 04:03 farhaanaliii

Same problem here with getFeed - was also working yesterday.

edit: I am using custom google oAuth

a7medkamel avatar Mar 08 '25 16:03 a7medkamel

i have the same probles calling getLibrary

yestoall avatar Mar 09 '25 09:03 yestoall

I'ts happening on almost every getX method.

BTW I also tried this with the standard Youtube TV client as well.

await innertube.getBasicInfo('oAA9nCqNfR4');
await innertube.getChannel('UCUQo7nzH1sXVpzL92VesANw');
await innertube.getGuide();
await innertube.getLibrary();
await innertube.getNotifications();
await innertube.getUnseenNotificationsCount();
await innertube.getTrending();

Logs:

RESPONSE: 400, TARGET_ENDPOINT: player, BODY: {"videoId":"oAA9nCqNfR4","racyCheckOk":false,"contentCheckOk":false,"playbackContext":{"contentPlaybackContext":{"vis":0,"splay":false,"lactMilliseconds":"-1","signatureTimestamp":20152}}}
---------------------------------------------------
RESPONSE: 400, TARGET_ENDPOINT: browse, BODY: {"browseId":"UCUQo7nzH1sXVpzL92VesANw"}
---------------------------------------------------
RESPONSE: 400, TARGET_ENDPOINT: /guide, BODY: {}
---------------------------------------------------
RESPONSE: 400, TARGET_ENDPOINT: browse, BODY: {"browseId":"FElibrary"}
---------------------------------------------------
RESPONSE: 400, TARGET_ENDPOINT: /notification/get_notification_menu, BODY: {"notificationsMenuRequestType":"NOTIFICATIONS_MENU_REQUEST_TYPE_INBOX"}
---------------------------------------------------
RESPONSE: 400, TARGET_ENDPOINT: /notification/get_unseen_count, BODY: {}
---------------------------------------------------
RESPONSE: 400, TARGET_ENDPOINT: browse, BODY: {"browseId":"FEtrending"}

koraybilgi avatar Mar 09 '25 22:03 koraybilgi

I have encountered the same issue. Neither the custom OAuth nor YouTube TV works, but using cookies directly seems to be effective. Does anyone have a better solution?

1162064779 avatar Mar 10 '25 02:03 1162064779

I have encountered the same issue. Neither the custom OAuth nor YouTube TV works, but using cookies directly seems to be effective. Does anyone have a better solution?

I used OAuth and it's still not work too.

RikiNozomu avatar Mar 10 '25 08:03 RikiNozomu

Folks, I'm a bit confused; is this happening only when using OAuth? If so, I'm afraid YouTube might have removed the ability to use OAuth with the WEB client altogether.

For now, use cookies or wait for #872.

LuanRT avatar Mar 10 '25 09:03 LuanRT

Hi @LuanRT, thanks for the comment. Unfortunately, #872 doesn’t resolve this issue either. The PR is quite heavy and includes some out-of-context implementations. To be sure, I tested the getHistory method with all available client types.

Here are the #872 output for the getHistory method:

ClientType: WEB - Error: 400
ClientType: MWEB - Error: 400
ClientType: WEB_KIDS - Error: 401
ClientType: WEB_REMIX - Error: 404
ClientType: iOS - Error: 404
ClientType: ANDROID - Error: 404
ClientType: ANDROID_MUSIC - Error: 404
ClientType: ANDROID_CREATOR - Error: 404
ClientType: TVHTML5 - Error: 404
ClientType: TVHTML5_SIMPLY_EMBEDDED_PLAYER - Error: 404
ClientType: WEB_EMBEDDED_PLAYER - Error: 400
ClientType: WEB_CREATOR - Error: 404

I tried this with the default "YouTube on TV" app and a custom OAuth app as well.

I'm not very familiar with the Innertube API and its internals. If I'm missing something or if you have any guidance or directions, please let me know. I'll do my best to participate in finding a solution.

koraybilgi avatar Mar 12 '25 17:03 koraybilgi

Ah, now I get it! I need to use the innertube.tv property and implement a getHistory method within that namespace.

koraybilgi avatar Mar 13 '25 10:03 koraybilgi

@koraybilgi - were you able to make progress on this?

a7medkamel avatar Apr 28 '25 21:04 a7medkamel

Hey @koraybilgi @a7medkamel did you figure out how to use it! It’s giving 400 on all get requests, it’s strange. I tried with react native, there it gives even worse errors. All i want is to create a youtube-skin application

amanzrx4 avatar Jun 08 '25 04:06 amanzrx4

No.. and hitting dead ends with the TV client as well

a7medkamel avatar Jun 27 '25 11:06 a7medkamel