Gists API
Authentication
You can read public gists and create them for anonymous users without a token; however, to read or write gists on a user’s behalf the gists oAuth scope is required.
List gists
List a user’s gists:
GET /users/:user/gists
List the authenticated user’s gists or if called anonymously, this will return all public gists:
GET /gists
List all public gists:
GET /gists/public
List the authenticated user’s starred gists:
GET /gists/starred
Response
Status: 200 OK
Link: <https://api.github.com/resource?page=2>; rel="next",
<https://api.github.com/resource?page=5>; rel="last"
X-RateLimit-Limit: 5000
X-RateLimit-Remaining: 4999
[
{
"url": "https://api.github.com/gists/1",
"id": "1",
"description": "description of gist",
"public": true,
"user": {
"login": "octocat",
"id": 1,
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
"gravatar_id": "somehexcode",
"url": "https://api.github.com/users/octocat"
},
"files": {
"ring.erl": {
"size": 932,
"filename": "ring.erl",
"raw_url": "https://gist.github.com/raw/365370/8c4d2d43d178df44f4c03a7f2ac0ff512853564e/ring.erl",
"content": "contents of gist"
}
},
"comments": 0,
"html_url": "https://gist.github.com/1",
"git_pull_url": "git://gist.github.com/1.git",
"git_push_url": "git@gist.github.com:1.git",
"created_at": "2010-04-14T02:15:15Z"
}
]
Get a single gist
GET /gists/:id
Response
Status: 200 OK
X-RateLimit-Limit: 5000
X-RateLimit-Remaining: 4999
{
"url": "https://api.github.com/gists/1",
"id": "1",
"description": "description of gist",
"public": true,
"user": {
"login": "octocat",
"id": 1,
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
"gravatar_id": "somehexcode",
"url": "https://api.github.com/users/octocat"
},
"files": {
"ring.erl": {
"size": 932,
"filename": "ring.erl",
"raw_url": "https://gist.github.com/raw/365370/8c4d2d43d178df44f4c03a7f2ac0ff512853564e/ring.erl",
"content": "contents of gist"
}
},
"comments": 0,
"html_url": "https://gist.github.com/1",
"git_pull_url": "git://gist.github.com/1.git",
"git_push_url": "git@gist.github.com:1.git",
"created_at": "2010-04-14T02:15:15Z",
"forks": [
{
"user": {
"login": "octocat",
"id": 1,
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
"gravatar_id": "somehexcode",
"url": "https://api.github.com/users/octocat"
},
"url": "https://api.github.com/gists/5",
"created_at": "2011-04-14T16:00:49Z"
}
],
"history": [
{
"url": "https://api.github.com/gists/1/57a7f021a713b1c5a6a199b54cc514735d2d462f",
"version": "57a7f021a713b1c5a6a199b54cc514735d2d462f",
"user": {
"login": "octocat",
"id": 1,
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
"gravatar_id": "somehexcode",
"url": "https://api.github.com/users/octocat"
},
"change_status": {
"deletions": 0,
"additions": 180,
"total": 180
},
"committed_at": "2010-04-14T02:15:15Z"
}
]
}
Create a gist
POST /gists
Input
- description
- Optional string
- public
- Required boolean
- files
-
Required hash - Files that make up this gist. The key of which
should be a required string filename and the value another
required hash with parameters:
- content
- Required string - File contents.
{
"description": "the description for this gist",
"public": true,
"files": {
"file1.txt": {
"content": "String file contents"
}
}
}
Response
Status: 201 Created
Location: https://api.github.com/gists/1
X-RateLimit-Limit: 5000
X-RateLimit-Remaining: 4999
{
"url": "https://api.github.com/gists/1",
"id": "1",
"description": "description of gist",
"public": true,
"user": {
"login": "octocat",
"id": 1,
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
"gravatar_id": "somehexcode",
"url": "https://api.github.com/users/octocat"
},
"files": {
"ring.erl": {
"size": 932,
"filename": "ring.erl",
"raw_url": "https://gist.github.com/raw/365370/8c4d2d43d178df44f4c03a7f2ac0ff512853564e/ring.erl",
"content": "contents of gist"
}
},
"comments": 0,
"html_url": "https://gist.github.com/1",
"git_pull_url": "git://gist.github.com/1.git",
"git_push_url": "git@gist.github.com:1.git",
"created_at": "2010-04-14T02:15:15Z",
"forks": [
{
"user": {
"login": "octocat",
"id": 1,
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
"gravatar_id": "somehexcode",
"url": "https://api.github.com/users/octocat"
},
"url": "https://api.github.com/gists/5",
"created_at": "2011-04-14T16:00:49Z"
}
],
"history": [
{
"url": "https://api.github.com/gists/1/57a7f021a713b1c5a6a199b54cc514735d2d462f",
"version": "57a7f021a713b1c5a6a199b54cc514735d2d462f",
"user": {
"login": "octocat",
"id": 1,
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
"gravatar_id": "somehexcode",
"url": "https://api.github.com/users/octocat"
},
"change_status": {
"deletions": 0,
"additions": 180,
"total": 180
},
"committed_at": "2010-04-14T02:15:15Z"
}
]
}
Edit a gist
PATCH /gists/:id
Input
- description
- Optional string
- files
-
Optional hash - Files that make up this gist. The key of which
should be an optional string filename and the value another
optional hash with parameters:
- content
- Optional string - Updated file contents.
- filename
- Optional string - New name for this file.
NOTE: All files from the previous version of the gist are carried over by default if not included in the hash. Deletes can be performed by including the filename with a null hash.
{
"description": "the description for this gist",
"files": {
"file1.txt": {
"content": "updated file contents"
},
"old_name.txt": {
"filename": "new_name.txt",
"content": "modified contents"
},
"new_file.txt": {
"content": "a new file"
},
"delete_this_file.txt": null
}
}
Response
Status: 200 OK
X-RateLimit-Limit: 5000
X-RateLimit-Remaining: 4999
{
"url": "https://api.github.com/gists/1",
"id": "1",
"description": "description of gist",
"public": true,
"user": {
"login": "octocat",
"id": 1,
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
"gravatar_id": "somehexcode",
"url": "https://api.github.com/users/octocat"
},
"files": {
"ring.erl": {
"size": 932,
"filename": "ring.erl",
"raw_url": "https://gist.github.com/raw/365370/8c4d2d43d178df44f4c03a7f2ac0ff512853564e/ring.erl",
"content": "contents of gist"
}
},
"comments": 0,
"html_url": "https://gist.github.com/1",
"git_pull_url": "git://gist.github.com/1.git",
"git_push_url": "git@gist.github.com:1.git",
"created_at": "2010-04-14T02:15:15Z",
"forks": [
{
"user": {
"login": "octocat",
"id": 1,
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
"gravatar_id": "somehexcode",
"url": "https://api.github.com/users/octocat"
},
"url": "https://api.github.com/gists/5",
"created_at": "2011-04-14T16:00:49Z"
}
],
"history": [
{
"url": "https://api.github.com/gists/1/57a7f021a713b1c5a6a199b54cc514735d2d462f",
"version": "57a7f021a713b1c5a6a199b54cc514735d2d462f",
"user": {
"login": "octocat",
"id": 1,
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
"gravatar_id": "somehexcode",
"url": "https://api.github.com/users/octocat"
},
"change_status": {
"deletions": 0,
"additions": 180,
"total": 180
},
"committed_at": "2010-04-14T02:15:15Z"
}
]
}
Star a gist
PUT /gists/:id/star
Response
Status: 204 No Content
X-RateLimit-Limit: 5000
X-RateLimit-Remaining: 4999
Unstar a gist
DELETE /gists/:id/star
Response
Status: 204 No Content
X-RateLimit-Limit: 5000
X-RateLimit-Remaining: 4999
Check if a gist is starred
GET /gists/:id/star
Response if gist is starred
Status: 204 No Content
X-RateLimit-Limit: 5000
X-RateLimit-Remaining: 4999
Response if gist is not starred
Status: 404 Not Found
X-RateLimit-Limit: 5000
X-RateLimit-Remaining: 4999
Fork a gist
POST /gists/:id/fork
Response
Status: 201 Created
Location: https://api.github.com/gists/2
X-RateLimit-Limit: 5000
X-RateLimit-Remaining: 4999
{
"url": "https://api.github.com/gists/1",
"id": "1",
"description": "description of gist",
"public": true,
"user": {
"login": "octocat",
"id": 1,
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
"gravatar_id": "somehexcode",
"url": "https://api.github.com/users/octocat"
},
"files": {
"ring.erl": {
"size": 932,
"filename": "ring.erl",
"raw_url": "https://gist.github.com/raw/365370/8c4d2d43d178df44f4c03a7f2ac0ff512853564e/ring.erl",
"content": "contents of gist"
}
},
"comments": 0,
"html_url": "https://gist.github.com/1",
"git_pull_url": "git://gist.github.com/1.git",
"git_push_url": "git@gist.github.com:1.git",
"created_at": "2010-04-14T02:15:15Z"
}
Delete a gist
DELETE /gists/:id
Response
Status: 204 No Content
X-RateLimit-Limit: 5000
X-RateLimit-Remaining: 4999