How do I edit github file from web-browser with github API?
ajax, github, github-api, javascript, jquery
Solution
As illustrated in GitHub API Commits, you would need to provide some form of authentication to your url when pushing new content.
Either a `-u "username:PASSWORD"` or a `access_token=OAUTH-TOKEN` parameter.
See also "POST to GitHub v3 API using ajax and JavaScript fails with a HTTP 404" for a full example.
Problem
I am trying to implement a PUT edit to a file in my repository, and am running into issues... Here's what I have so far.. ``` // GET content from github file $.get('https://api.github.com/repos/redemption23/trackerApp/contents/file.txt', function(data){ var content = atob(data.content); $('#box').append(content); }); ``` This is pulling the content in just fine... however trying to PUT an edit back into the file is failing.. ``` // PUT edit to github file $.ajax({ method: "PUT", url: "https://api.github.com/repos/redemption23/trackerApp/contents/file.txt" data: { "message": "my commit message", "committer": { "name": "Matt", "email": //omitted for stack overflow }, "content": text, "sha": //omitted for stack overflow } }) .done(function( msg ) { console.log( "Data Saved: " + msg ); }); console.log(text); ``` I am able to pull the content from the file and append it to the body of my web app, but trying to send the edit via the api isn't working.. returning with this error.. ``` jquery.min.js:4 PUT https://api.github.com/repos/redemption23/trackerApp/contents/file.txt ``` Any ideas??