4

I've been looking for quite some time if it is even possible to do this.

I'd like to make a RESTful POST call with a javascript without the use of a server (node) to send a json object in the request body to update a json file in a github repo triggering a commit/push.

geschwe1
  • 315
  • 2
  • 14
  • Have you tried? Did you get any error messages? – Chris Jan 19 '15 at 20:49
  • I don't really know where to begin, im using postman to get data back from the repo just fine, but i dont see any way to send a post and an object – geschwe1 Jan 19 '15 at 21:29
  • https://developer.github.com/v3/repos/contents/#create-a-file - when i try to do this i get `{ "message": "Not Found", "documentation_url": "https://developer.github.com/v3/repos/contents/" }` as the response. – geschwe1 Jan 19 '15 at 21:42
  • You're pointing at a repository that already exists? You have properly authenticated? – Chris Jan 19 '15 at 22:21

1 Answers1

3

Yes, it's possible to do this using the Github API.

The URL must be something like that: https://api.github.com/repos/{repositoryName}/contents/{path}

repositoryName is the repository where you want to put your file and path its path within this repository.

Regarding the authentication, you need to follow this link https://developer.github.com/v3/#authentication. I successfully tested with basic auth.

You need then to use an HTTP method PUT with content with the following structure:

{
  "message": "a commit message",
  "content": "bXkgbmV3IGZpbGUgY29udGVudHM="
}

The field content corresponds to the content of your file encoded with base 64.

Hope it helps. Thierry

Thierry Templier
  • 182,931
  • 35
  • 372
  • 339