Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to search using GitHub API in private organizations

I have a private organization GitHub (enterprise) repository, e.g. github.mycompany.com.

I want to search strings in code using the GitHub API. How do I search in mycompany-specific GitHub repositories?

I tried the query below and received 404:

curl -i -H "Authorization: token <token>" https://github.mycompany.com/api/v3/search/code?q=class

It seems to be authenticating fine, since I tried curl -u <userName> and

  • If I give the wrong password, I get an authentication error.
  • If I give the right password, it goes through, but returns 404 for the search query.
like image 600
suman j Avatar asked Feb 18 '26 01:02

suman j


1 Answers

Currently, the Search API is still in preview on GitHub Enterprise. As a result, you need to specify a special media type in the Accept header to get things working.

Give this a try:

curl -i -H "Accept: application/vnd.github.preview+json" -H "Authorization: token <token>" https://github.mycompany.com/api/v3/search/code?q=class

like image 123
Ivan Zuzak Avatar answered Feb 21 '26 13:02

Ivan Zuzak