I use same header value. but one work, one not work

when i call https://api.twitch.tv/kraken/games/top?limit=100. it work.

but when i call https://api.twitch.tv/kraken/streams/?game=Overwatch&limit=100, server send
< { error: ‘Bad Request’,
< status: 400,
< message: ‘No client id specified’ }

my code is

let twitch_top_url = ‘https://api.twitch.tv/kraken/games/top?limit=100’;
let twitch_games_url_1 = ‘https://api.twitch.tv/kraken/streams/?game=’;
let twitch_games_url_2 = ‘&limit=100’;
let twitch_api_key = ‘blablabla’;
let twitch_api_version = ‘application/vnd.twitchtv.v5+json’;
let twitch_api_header = “‘Accept’:” + twitch_api_version + “,” + “‘Client-ID’:” + twitch_api_key;

function request_get_promise(json_array, json_array_number, url, header){
url: url,
json: true,
headers: {

that twitch_api_header value is global.not local,in function

i just change url… how can i solve this problem?

There’s a disconnect between where you define the headers and where you use them. Your request.get uses the function’s parameter header and you haven’t pasted where you call it.

Your twitch_api_header being a single string with the 2 headers separated by a comma is… unusual though. request wants headers as an object (e.g.{ 'key': 'value', 'another_key': 'another_value' }). The raw HTTP ends up looking like

key: value
another_key: value

hmm… i just use

request_get_promise(json_array , json_array_number , twitch_top_url , twitch_api_header)

in function headers:{header}. is that incorrect?

in test postman. all work. but nodejs is one work, one not work

Yeah your header format is incorrect, I’m not a javascript expert but it can’t be a string like that you need to form your headers as an object like this:

headers: {
‘Client-ID’: ‘blablabla’,
‘Accept’: ‘application/vnd.twitchtv.v5+json’

This makes the entries members of an object not just an object with a string in.

The reason the first call you made works is that it does not require any headers, if you click the link you’ll get a response without using a version or Client-Id


Hope that helps


ok. i solve problem.

let twitch_api_header = {‘Accept’:twitch_api_version , ‘Client-ID’:twitch_api_key};

it work. thanks @3ventic @Adrian_Schofield

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.