Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem when creating a gist #337

Closed
raed667 opened this issue May 22, 2016 · 7 comments
Closed

Problem when creating a gist #337

raed667 opened this issue May 22, 2016 · 7 comments

Comments

@raed667
Copy link

raed667 commented May 22, 2016

Following the documentation, when I try to create a gist in the browser using the following code:

       var gh = new GitHub();
        var gist = gh.getGist(); // not a gist yet
        gist.create({
            public: true,
            description: 'TEST',
            files: {
                "file1.txt": {
                    contents: "Aren't gists great!"
                }
            }
        }).then(function (httpResponse) {
            // Promises!
            var gist = httpResponse.data;
            gist.read(function (err, gist, xhr) {
                // if no error occurred then err == null

                // gist == httpResponse.data

                // xhr == httpResponse
            });
        });

This returns an error POST https://api.github.com/gists 422 (Unprocessable Entity)

Can you reproduce? Any idea why?

@clayreimann
Copy link
Member

clayreimann commented May 23, 2016

I can see two issues with the snippet you posted:

  1. Unautenticated users cannot create gists
  2. You redefine gist in your promise handler so gist.read won't work

Other than that you appear to be doing the same thing we do in the tests to create a gist, so it should work.

@clayreimann
Copy link
Member

@RaedsLab Any more thoughts here?

@guumaster
Copy link

I'm also getting an error, but it seems a 404 error:

Here the code:

var gh = new GitHub({ token: MY_TOKEN });

var gist = gh.getGist();

gist.create({
   public: true,
   description: 'My first gist',
   files: {
      "file1.txt": {
         contents: "Aren't gists great!"
      }
   }
})

The lib is posting this:

  method: 'POST',
  url: 'https://api.github.com/gists',

  headers: 
     authorization: 'token e77..........VALID_TOKEN......0c',
     'content-type': 'application/json'

  body: 
     description: 'the description for this gist',
     public: true,
     files: { 'file1.txt': { content: 'String file contents' } } },

  json: true 

And the response is:


{
  "message": "Not Found",
  "documentation_url": "https://developer.github.com/v3/gists/#create-a-gist"
}

@clayreimann
Copy link
Member

@guumaster Are you sure your token has the gist permission? Our tests indicate that we can successfully create gists using code almost identical to yours.

@guumaster
Copy link

sure, I'm using it with raw ajax calls and it works.

@clayreimann
Copy link
Member

clayreimann commented Sep 1, 2016

@guumaster @RaedsLab This is probably due to a mistake in the example from the readme reported in #374. Can you try with:

{
   public: true,
   description: 'My first gist',
   files: {
      "file1.txt": {
         content: "Aren't gists great!"
      }
   }
}

@AurelioDeRosa
Copy link
Member

This issue has been fixed, so I'm closing it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants