Question

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.
Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top