GitHub API AJAX POST returning 422

隐身守侯 提交于 2019-12-24 05:45:58

问题


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.


回答1:


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);
      }
    });


来源:https://stackoverflow.com/questions/38574326/github-api-ajax-post-returning-422

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!