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
  • 323
  • 3
  • 14

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
  • 198,364
  • 44
  • 396
  • 360