Skip to content

Instantly share code, notes, and snippets.

@wilmoore
Last active November 1, 2024 23:30
Show Gist options
  • Select an option

  • Save wilmoore/700c6becdfd00549d12f351c50edc118 to your computer and use it in GitHub Desktop.

Select an option

Save wilmoore/700c6becdfd00549d12f351c50edc118 to your computer and use it in GitHub Desktop.
Software Engineering :: Source Control :: VCS :: Git :: Managed Hosting Platform :: GitHub :: Gist :: API :: Reference :: Create a gist

Software Engineering :: Source Control :: VCS :: Git :: Managed Hosting Platform :: GitHub :: Gist :: API :: Reference :: Create a gist

⪼ Made with 💜 by Polyglot.

Create Gist

creating a new gist creates a new git repo which can be cloned.

  • $GIST_API_TOKEN
  • $GIST_DESCRIPTION: The title of the gist and main header for the readme.md file which is the default file created in the repo
  • $GIST_TITLE_QUOTE: The quoted line of gist.
❯ curl -sH "Authorization: token $GIST_API_TOKEN" \
          -X POST \
          --data "{\"description\":\"$GIST_DESCRIPTION\",\"public\":\"false\",\"files\":{\"readme.md\":{\"content\"
:\"# $GIST_DESCRIPTION\n$GIST_TITLE_QUOTE\"}}}" \
    https://api.github.com/gists

API

  • url: https://api.github.com/gists
  • method: GET

Parameters

  • page: 1
  • per_page: 100

Headers

  • Accept: application/vnd.github+json
  • Authorization: Bearer {process.env.GIST_API_TOKEN}
  • X-Github-Api-Version: 2022-11-28

Code

Bruno

meta {
  name: List gists for the authenticated user
  type: http
  seq: 1
}

get {
  url: https://api.github.com/gists?per_page=100&page=1
  body: none
  auth: bearer
}

params:query {
  per_page: 100
  page: 1
}

headers {
  Accept: application/vnd.github+json
  X-GitHub-Api-Version: 2022-11-28
}

auth:bearer {
  token: {{process.env.GIST_API_TOKEN}}
}

curl

curl --request GET \
  --url 'https://api.github.com/gists?per_page=100' \
  --header 'Accept: application/vnd.github+json' \
  --header 'Authorization: Bearer {{process.env.GIST_API_TOKEN}}' \
  --header 'X-GitHub-Api-Version: 2022-11-28'

Response

[
  {
    "url": "https://api.github.com/gists/a1b2c3d4e5f6g7h8i9j0",
    "forks_url": "https://api.github.com/gists/a1b2c3d4e5f6g7h8i9j0/forks",
    "commits_url": "https://api.github.com/gists/a1b2c3d4e5f6g7h8i9j0/commits",
    "id": "a1b2c3d4e5f6g7h8i9j0",
    "node_id": "G_kwDOABc0FACA1YjNiM2Q0ZTVmNmI3aDhiOTYwZDAz",
    "git_pull_url": "https://gist.github.com/a1b2c3d4e5f6g7h8i9j0.git",
    "git_push_url": "https://gist.github.com/a1b2c3d4e5f6g7h8i9j0.git",
    "html_url": "https://gist.github.com/johndoe/a1b2c3d4e5f6g7h8i9j0",
    "files": {
      "readme.md": {
        "filename": "readme.md",
        "type": "text/markdown",
        "language": "Markdown",
        "raw_url": "https://gist.githubusercontent.com/johndoe/a1b2c3d4e5f6g7h8i9j0/raw/d2f45e3f4e9a79db1d8c4d9d2d3e3d4e/readme.md",
        "size": 1087
      }
    },
    "public": false,
    "created_at": "2024-10-22T18:02:04Z",
    "updated_at": "2024-10-22T18:13:29Z",
    "description": "The Anatomy of a GitHub Gist API Request",
    "comments": 0,
    "user": null,
    "comments_url": "https://api.github.com/gists/a1b2c3d4e5f6g7h8i9j0/comments",
    "owner": {
      "login": "johndoe",
      "id": 12345,
      "node_id": "MDQ6VXNlcjEyMzQ1",
      "avatar_url": "https://avatars.githubusercontent.com/u/12345?v=4",
      "gravatar_id": "",
      "url": "https://api.github.com/users/johndoe",
      "html_url": "https://github.com/johndoe",
      "followers_url": "https://api.github.com/users/johndoe/followers",
      "following_url": "https://api.github.com/users/johndoe/following{/other_user}",
      "gists_url": "https://api.github.com/users/johndoe/gists{/gist_id}",
      "starred_url": "https://api.github.com/users/johndoe/starred{/owner}{/repo}",
      "subscriptions_url": "https://api.github.com/users/johndoe/subscriptions",
      "organizations_url": "https://api.github.com/users/johndoe/orgs",
      "repos_url": "https://api.github.com/users/johndoe/repos",
      "events_url": "https://api.github.com/users/johndoe/events{/privacy}",
      "received_events_url": "https://api.github.com/users/johndoe/received_events",
      "type": "User",
      "user_view_type": "public",
      "site_admin": false
    },
    "truncated": false
  }
  ...
]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment