Forums/Community/Zendesk Apps

Bug: Updating Ticket's comment via Lotus App's Ajax call fails

Jeff Tanner
posted this on September 14, 2012 13:37

Reference:

http://developer.zendesk.com/documentation/rest_api/tickets.html#updating-tickets

Hi

I am wanting to update a ticket's comments through the Lotus App using an Ajax call by following the aforementioned reference.

1. In providing within request data = "comment: { public: " fails JSHint

Upload Error

         JSHint error(s): L619: Expected an identifier and instead saw 'public' (a reserved word).

2. Request: Maybe rename comment's public: to either public_reply: or internal_note: so upload will pass JSHint.

3. In making the request (without public attribute in comment JSON body) it fails

Here is the function making the PUT request to update the ticket:

putTicketComment: function(data) {
  var currentAccount = this.currentAccount();
  var ticket = this.ticket();
  var subdomain = currentAccount.subdomain();
  var id = ticket.id();
  var url = 'https://%@.zendesk.com/api/v2/tickets/%@.json'.fmt(subdomain, id)
  return {
    url: url,
    type: 'PUT',
    dataType: 'JSON',
    data: data
  };
}

And here is the code calling putTicketComment with defined data (notice that I commented out public: to pass JSHint at upload:

var data = {
  ticket: {
    status: ticket.status(),
    comment: {
      // public : true,
      value: 'Hello, World!!!'
    }
  }
};
this.ajax('putTicketComment', data);

The failure response to 'putTicketComment.fail' was as follows:

Put ticket comment failed:

    jqXHR = {    status: 200,    statusText: OK,    responseText: Invalid URL parameter    },

    textStatus = parsererror

So, error is with the provided data, because my built url looks okay:

  url = https://jeff00tangocard.zendesk.com/api/v2/tickets/5.json

Thanks for your assistance,

- Jeff

 

Comments

User photo
Shajith Chacko
Zendesk

1. Put "public" in quotes to hint that you are using it as a string. JSHint should allow that.

2. When making AJAX calls to your own zendesk, you should use relative URLs. This is a deficiency in the way we determine whether to proxy your AJAX request or not, but you can get around that for now by using relative URLs.

September 14, 2012 14:40
User photo
Jeff Tanner
tangocard

Hi

For this problem, please provide example "using relative URLs".

Are you requesting that instead of using:

 url = https://jeff00tangocard.zendesk.com/api/v2/tickets/5.json

I should be using:

 url = api/v2/tickets/5.json

Thx

- Jeff

September 15, 2012 12:14
User photo
Jeff Tanner
tangocard

In addition, putting quotes around keys within JSON defined data may pass JSHint, but that would be inconsistent with Lotus App documentation:

http://developer.zendesk.com/documentation/apps/requests.html#more-in-depth

I would request that to rename "public:' to a non-reserved name so that other developers run into the same issue.

Thx

- Jeff

September 15, 2012 12:29
User photo
Jeff Tanner
tangocard

Hi

Tried with quoted 'public' in data:

var data = {   ticket: {     status: ticket.status(),     comment: {       'public' : true,       value: 'Hello, World!!!'     }   } };

And relative url:

var url = api/v2/tickets/5.json

But it still errors

jqXHR = { status: 405, statusText: Not Allowed, responseText: 405 Not Allowed nginx/1.0.15 },

textStatus = error

I appreciate your assistance,

- Jeff

September 15, 2012 12:54
User photo
Jeff Tanner
tangocard

Tried same data (with quoted 'public') but with full url:

var  url = https://jeff00tangocard.zendesk.com/api/v2/tickets/5.json

and got same initial error:

    jqXHR = {    status: 200,    statusText: OK,    responseText: Invalid URL parameter    },

    textStatus = parsererror

September 15, 2012 13:42
User photo
James Rosen
Zendesk

The problem with AJAX requests using full help desk URLs is a known issue.

September 15, 2012 20:52
User photo
Jeff Tanner
tangocard

1. By "full help desk URLs" , do you mean "https://jeff00tangocard.zendesk.com/api/v2/tickets/5.json" versus using "relative URLs", like "api/v2/tickets/5.json"

2. Thanks for the known issue link, but this was a known issue in May. When will this be addressed?

Thanks

- Jeff

September 15, 2012 22:35
User photo
James Rosen
Zendesk

1. That's correct.

2. The errata document was originally authored in May, but we update it regularly. I believe I added the item about AJAX requests on Wednesday.

September 15, 2012 22:38
User photo
Jeff Tanner
tangocard

Thx

- Jeff

September 16, 2012 07:39
User photo
Jeff Tanner
tangocard

Hi James

Thx for the "Root-relative" info, and I tried the following:

     var ticket = this.ticket();

     var id = ticket.id();

     var url = '/api/v2/tickets/%@.json'.fmt(id);

(which its product is url = /api/v2/tickets/5.json)

But this errors as well:

jqXHR = { status: 403, statusText: Forbidden, responseText: { "error": { "title": "Forbidden", "message": "" } } } textStatus = error

Sorry, but what is the next step???

Respectfully

- Jeff

September 16, 2012 09:37
User photo
James Rosen
Zendesk

I would suggest trying going to the (full) URL in your browser. If that also returns a 403, it's likely that your current user doesn't have access to that ticket. If it doesn't, I'd try again as an AJAX call from the console: jQuery.ajax({ url: '/api/v2/tickets/5.json' }). If that returns a 403, then I'll investigate why AJAX calls don't have access to that URL. If that returns a 200, though, then the problem is in the app and you should submit a ticket and attach the app source.

September 16, 2012 09:45
User photo
Jeff Tanner
tangocard

Hi again

I tried both suggested tests, and I had experienced no 403 problems.

Using Chrome, I logged into my Zendesk desktop

  1. Was able to view ticket's JSON object using full-path
  2. ran jQuery.ajax({ url: '/api/v2/tickets/5.json' }) from Chrome console using root-path, was able to see JSON object

Thx for your assistance

- Jeff

 

/api/v2/tickets/5.json

September 16, 2012 10:18