Github REST API full example

You were close:) Lets assume, that

1) your login: YourUsername

2) your access token: 123a321

3) repository to be updated: YourRepo

4) file to be created: file.txt

5) folder that will contains new file: f1/f2

According to those assumptions your request should be following:

type : PUT

url : https://api.github.com/repos/YourUsername/YourRepo/contents/f1/f2/file.txt

headers :

{
 "Content-Type" : "application/vnd.github.v3+json",
 "Authorization" : "token 123a321"
}

body :

{
  "message": "my commit message",
  "committer": {
    "name": "My name",
    "email": "my email"
  },
  "content": "base64encoded"
}


UPD If you write in java, you can use GitHubFileAPI library, that I recently pushed to the maven central repository.

Tags:

Rest

Github