0

我使用 Zendesk API 文档中的标准示例:

    $(document).ready(function () {
        var subject = "Test ticket #ABC";
        var body = "This is test ticket #ABC";
        $.ajax({
            url: 'https://tmstest.zendesk.com/api/v2/tickets.json',
            contentType: 'application/json',
            type: 'POST',
            beforeSend: function (xhr) {
                var auth = "Basic " + $.base64.encode("email@gmail.com/token:XXXX");
                xhr.setRequestHeader("Authorization", auth);
            },
            data: JSON.stringify({ "ticket": { "subject": subject, "comment": { "body": body } } }),
            error: function (jqXHR, textStatus, errorThrown) {
                if (jqXHR.status == 500) {
                    alert('Internal error: ' + jqXHR.responseText);
                } else {
                    alert('Unexpected error.');
                }
            }
        })
            .done(function (data) {
                console.log(data.ticket);
            })
            ;
    });

它添加了一张票,但我调用了错误部分。textStatus具有“错误”值,jqXHR.status为 0,errorThrown为空字符串。怎么了?

4

1 回答 1

0

如果请求是从 Zendesk 域外部发起的,您必须对客户端请求使用基于 Oauth 的身份验证。有关更多详细信息,请参见此处 - https://developer.zendesk.com/rest_api/docs/support/introduction#security-and-authentication

于 2018-12-19T04:35:11.007 回答