GitHub API AJAX POST返回422 [英] GitHub API AJAX POST returning 422

查看:547
本文介绍了GitHub API AJAX POST返回422的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过GitHub API发布问题,并不断收到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 );
      });

谢谢.

推荐答案

FYI最终将其与下面的代码一起使用,以发布到GitHub API(创建问题):

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

这篇关于GitHub API AJAX POST返回422的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆