1

I am trying to post a blob to the GitHub API in JavaScript / jQuery as per the docs https://developer.github.com/v3/git/blobs/#create-a-blob - however I keep receiving a 404 request

My current request in JavaScript looks like so:

var uploadURL ="https://api.github.com/repos/daniellevass/web-quiz/git/blobs" + accessToken;

console.log(uploadURL);

$.ajax({
  type: "POST",
  dataType: "jsonp",
  url: uploadURL,
  data:{
      "content": "my message",
      "encoding": "utf-8"
    }
})
  .done(function( data ) {
    console.log( data );
  });

The console spits out the following URL (the access token is correct):

https://api.github.com/repos/daniellevass/web-quiz/git/blobs?access_token=xxx

I get the following response:

data: Object
    documentation_url: "https://developer.github.com/v3"
    message: "Not Found"
    __proto__: Object
meta: Object
   X-Accepted-OAuth-Scopes: "repo"
   X-GitHub-Media-Type: "github.v3"
   X-OAuth-Scopes: "gist, repo, user"
   X-RateLimit-Limit: "5000"
   X-RateLimit-Remaining: "4992"
   X-RateLimit-Reset: "1401550358"
   status: 404
   __proto__: Object
__proto__: Object

The response shows in the meta object, that I have asked requested the correct OAuth scopes. I can also successfully GET any data using the GitHub api and ajax - such as a list of the users repositories.

I suspect I may have something incorrect with my POST request, but I have no idea where I've gone wrong so any help or advice would be much appreciated!

Thank you,

Danielle.

1 Answer 1

3

You can't use JSONP to make non-GET requests.

However, the good news is that you don't need to use JSONP since the API supports CORS.

Give this a try:

var uploadURL ="https://api.github.com/repos/daniellevass/web-quiz/git/blobs" + accessToken;

console.log(uploadURL);

$.ajax({
  type: "POST",
  url: uploadURL,
  contentType: "application/json",
  dataType: "json",
  data: JSON.stringify({
      "content": "aGVsbG8=",
      "encoding": "utf-8"
    })
})
  .done(function( data ) {
    console.log( data );
  });
Sign up to request clarification or add additional context in comments.

1 Comment

Knew it must have been something silly I was doing - thank you so much for your answer!

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.