Listing all gists, including secret gists via Github REST API

I seem to be only able to get my public gists when using the following (Scala):

  final val Token = "MY_TOKEN"

  val headers = Map(
    "Authorization" -> s"token $Token",
    "Accept" -> "application/vnd.github.v3+json"
  )

  val gistsUrl = "https://api.github.com/gists"

I successfully get back all my public gists, but not my private ones. How do I get the private/secret gists? I looked through the documentation and did not see an endpoint that makes more sense than this one.

Is the token a personal access token for your account?

It works fine for me in cURL:

curl -H "Accept: application/vnd.github.v3+json" -H "Authorization: token ghp_REDACTED" https://api.github.com/gists

The token is a PAT with the gist scope.

[
  {
    "url": "https://api.github.com/gists/<id>",
    "forks_url": "https://api.github.com/gists/<id>/forks",
    "commits_url": "https://api.github.com/gists/<id>/commits",
    "id": "<id>",
    "node_id": "...",
    "git_pull_url": "https://gist.github.com/<id>.git",
    "git_push_url": "https://gist.github.com/<id>.git",
    "html_url": "https://gist.github.com/<id>",
    "files": { ... },
    "public": false,  // <------- definitely a private gist!
    ...

Your token might not have the necessary permissions, or are the latest 30 gists all public perhaps? The endpoints returns 30 gists (per page) by default.

Yeah it is, just made it today.

Made a new key with full permissions, I guess I messed up the permissions on the first key. Thanks! I can see my secret gists now - however I only get the 30x as you mentioned, but that is an easy change to make.

1 Like