Skip to content

Instantly share code, notes, and snippets.

@jonatasemidio
Last active April 20, 2016 17:46
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonatasemidio/3e05273bb3a7d9c924da7740cff7adb6 to your computer and use it in GitHub Desktop.
Save jonatasemidio/3e05273bb3a7d9c924da7740cff7adb6 to your computer and use it in GitHub Desktop.
GitHub API Samples Script cURL
Get a File
curl -i -X GET -H 'Authorization: token <your token>' -d '{"path": "index.html", "message": "Initial Commit", "committer": {"name": "Jonatas Emidio", "email": "jonatasemidio@gmail.com"}, "branch": "master"}' https://api.github.com/repos/jonatasemidio/blog/contents/index.html
Create a File
curl -i -X PUT -H 'Authorization: token <your token>' -d '{"path": "index.html", "message": "Initial Commit", "committer": {"name": "Jonatas Emidio", "email": "jonatasemidio@gmail.com"}, "content": "VGVzdGluZyBHaXRIdWIgQVBJ", "branch": "master"}' https://api.github.com/repos/jonatasemidio/blog/contents/index.html
Update a File
curl -i -X PUT -H 'Authorization: token <your token>' -d '{"path": "index.html", "message": "Initial Commit", "committer": {"name": "Jonatas Emidio", "email": "jonatasemidio@gmail.com"}, "content": "VGVzdGluZyBHaXRIdWIgQVBJ", "sha":"2706f84a7078ad64fbdca10558879e6f2c323694", "branch": "master"}' https://api.github.com/repos/jonatasemidio/blog/contents/index.html
Delete a File
curl -i -X DELETE -H 'Authorization: token <your token>' -d '{"path": "post2.txt", "message": "Initial Commit", "committer": {"name": "Jonatas Emidio", "email": "jonatasemidio@gmail.com"}, "sha":"904dd91b9de4dd50864026f788ac10e05df2d6f1", "branch": "master"}' https://api.github.com/repos/jonatasemidio/blog/contents/post2.txt
you can get the sha of your file with the get command.
Some URLs:
https://developer.github.com/v3/repos/contents/#get-contents
As you know, the content of your file need to be in Base64. So use this site to convert: https://www.base64encode.org/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment