10

I want to get a list of repositories or files where the contents of the files contained in the repositories match the keywords I specify in the search. I tried doing a simple search using https GET request and it looks like the search is not possible without specifying the repository or organization name. I get the below error.

https://api.github.com/search/code?q=authorization+in:file

{
  "message": "Validation Failed",
  "errors": [
    {
      "message": "Must include at least one user, organization, or repository",
      "resource": "Search",
      "field": "q",
      "code": "invalid"
    }
  ],
  "documentation_url": "https://developer.github.com/v3/search/#search-code"
}

I understand that searching without repository or organization name will be resource-intensive operation. Is there any work-around for this? I was assuming that since I am able to get results by using online search, I should be able to achieve the same using git search api.

So basically I am trying to simulate the below:

https://github.com/search?utf8=%E2%9C%93&q=authorization&type=Code&ref=searchresults

Has QUIT--Anony-Mousse
  • 76,138
  • 12
  • 138
  • 194
Zack
  • 2,078
  • 10
  • 33
  • 58
  • 2
    I think the documentation is not intact with the actual restrictions. Unfortunately. I also think your best shot for getting reliable answer in timely manner is to use official contact, and ask them specifically. And self-answer here. – luk32 Feb 09 '15 at 04:59
  • @luk32 Yeah! I will do that. I was just thinking if anybody has a better idea. I was thinking if any google search api could help. I could pass the website to search on and see if it works. Something like "keyword sites:github.com" we do in google search. Sounds crazy but just giving it a thought ! Need to look for alternatives. – Zack Feb 09 '15 at 05:05
  • 1
    GitHub Community official: https://github.community/t/is-it-possible-to-global-search-with-api/122230/3 , you really need a Personal Access Token – PotatoChips Nov 02 '21 at 07:37

1 Answers1

4

Is there any work-around for this? I was assuming that since I am able to get results by using online search, I should be able to achieve the same using git search api.

The behavior you observed is expected for now -- you indeed need to specify a user, org or repository when using the code search API (something you don't need to do when using the Web UI), and currently there is no way around that.

https://developer.github.com/changes/2013-10-18-new-code-search-requirements/

Ivan Zuzak
  • 18,068
  • 3
  • 69
  • 61
  • Do you know if there's a way to get the stats only? Like, number of results, top 10 languages and how much of the results each, etc.? – yuvi Mar 31 '16 at 19:08