Zendesk API invalid response



Publicado 18 dic 2021

I use standard example from Zendesk API documentation:

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

it added a ticket, but I error part is called. textStatus has "error" value, jqXHR.status is 0, errorThrown is empty string. What is wrong?

 

 

 


0

2

2 comentarios

      It looks like you're using subject and body as variables so it would be `${subject}` and `${body}`. 

      Hope this helps!

      0


      I think you just need quotes around your subject line, and body content. so this instead: 

      data: JSON.stringify({ "ticket": { "subject": "subject", "comment": { "body": "body" } } }),



      1


      Iniciar sesión para dejar un comentario.

      ¿No encontró lo que buscaba?

      Nueva publicación