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
GitHub Codesearch can be found at github.com/codesearch and will let you type in anything you're looking for in source code and get highlighted results of any files in our public repositories that match.
If you want to use the GitHub REST API for personal use, you can create a personal access token. The REST API operations used in this article require repo scope for personal access tokens (classic) or, unless otherwise noted, read-only access to public repositories for fine-grained personal access tokens.
Github has its own search syntax with qualifiers you can add, but not full regex. The api uses the same syntax as the in-browser search. Save this answer.
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/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With