使用AJAX Chrome Extension更新ZenDesk票证

时间:2017-05-03 16:56:20

标签: ajax google-chrome zendesk-api

从zendesk的代理视图中我想注入代码来更新zendesk票证,但我不确定这是否可以在没有身份验证的情况下进行?现在我正在尝试这个但是得到了一个禁止回应'

不确定是否有人对此有所了解?

"request": {
    "comment": {
        "body": "Submitting a test comment"
    }
}
});
var apiURL = 'https://[subdomain].zendesk.com/api/v2/requests/[id].json';
$.ajax({
    url: "/api/v2/requests/" + id+ ".json",
     type: 'PUT',
     data: JSON.stringify(request),
     contentType: "application/json",
     success: function(data, textStatus, jqXHR) {
         alert("Success")
     },
     error: function(XMLHttpRequest, textStatus, errorThrown) {
         alert(errorThrown);
     }
});

1 个答案:

答案 0 :(得分:0)

能够用这个想出来。

"request": {
    "comment": {
        "body": "Submitting a test comment"
    }
}
});
var token = document.getElementsByName("csrf-token")[0].content;
var apiURL = 'https://[subdomain].zendesk.com/api/v2/requests/[id].json';
$.ajax({
    url: "/api/v2/requests/" + id+ ".json",
     type: 'PUT',
     data: JSON.stringify(request),
     contentType: "application/json",
     headers: {
         "X-CSRF-Token": token
     }
     success: function(data, textStatus, jqXHR) {
         alert("Success")
     },
     error: function(XMLHttpRequest, textStatus, errorThrown) {
         alert(errorThrown);
     }
});