Github GraphQL API: This endpoint requires you to be authenticated

Viewed 490

I'm trying to make a request with generated git token, but it seems like I'm making a wrong authentication, what am I doing wrong? Thanks


    const token = 'my github token'

    fetch('https://api.github.com/graphql', {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
        'Authorization': 'bearer' + token
      },
      body: JSON.stringify({ query: QUERY })
    })
      .then(res => res.json())
      .then(data => console.log(data))
}

Error message:

{message: 'This endpoint requires you to be authenticated.'}
1 Answers

Solved it by putting space in bearer:

'Authorization': 'bearer ' + token

Related