3

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??

1 Answer 1

4

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.