API access to GitHub organisation repo using personal access token

Viewed 1473

I get refused access to my GitHub organisation's repos when trying to access the API using a personal token:

(Python)

GITHUB_API_TOKEN = 'XXX'
GITHUB_HEADERS =  {
    'Authorization': GITHUB_API_TOKEN,
}

issues = 'https://api.github.com/repos/my_org_name/my_repo_name/issues?state=all&page=1&per_page=100'
request = requests.get(issues, headers=GITHUB_HEADERS)
[{'message': 'Not Found'}]

Accessing a personal repo works. I have full access to my org's repos.

What's the best way around this?

1 Answers

You need to set the Authorization header to token YOUR_TOKEN :

import requests

GITHUB_API_TOKEN = 'YOUR_TOKEN'
GITHUB_HEADERS =  {
    'Authorization': "token " + GITHUB_API_TOKEN,
}

issues = 'https://api.github.com/repos/my_org_name/my_repo_name/issues?state=all&page=1&per_page=100'
request = requests.get(issues, headers=GITHUB_HEADERS)

print(request.text)

Note that Bearer YOUR_TOKEN also works

Also you need the repo scope on your personnal access token

Related