McD
McD

Reputation: 173

GitHub API AJAX POST returning 422

I'm trying to post an issue via the GitHub API and keep getting a 422 error. I've tried various approaches over the past few days with no luck - I'm hoping this is a simple mistake that someone can spot quickly?

My call is below - I'm using my Personal Access Token for authorization.

$.ajax({
      type: "POST",
      url: `https://api.github.com/repos/MYUSERNAME/MYREPONAME/issues?access_token=MYACCESSTOKEN`,
      contentType: "application/json",
      dataType: "json",
      data: JSON.stringify({
        "title": "Found a bug",
        "body": "I'm having a problem with this."
      })
    }).done(function( data ) {
        console.log( data );
      });

Thanks in advance.

Upvotes: 1

Views: 268

Answers (1)

McD
McD

Reputation: 173

FYI finally got this to work with the code below to POST to the GitHub API (creating an issue):

$.ajax({
      url: 'https://api.github.com/repos/USERNAME/REPONAME/issues',
      type: 'POST',
      dataType: 'json',
      headers: {
        Authorization: 'token MY_PERSONAL_TOKEN'
      },
      data: JSON.stringify({
        "title": "Found a bug",
        "description": "Bug description"
      }),
      success: function (response) {
        console.log(response);
      }
    });

Upvotes: 2

Related Questions