HTTP Requests

this.requests

The requests attribute contains named HTTP requests. Each definition can be any of

  • a String, which will be interpreted as a URL for a GET request
  • an Object that is compatible with jQuery.ajax.
  • a Function that returns either of the above

If the URL is relative to the current help desk (e.g. /api/v2/tickets), the request definition will passed directly to jQuery.ajax. If it is a fully-qualified URL (e.g. http://example.com/widget), the request will be proxied through Zendesk's servers.

this.ajax(name, *args)

Performs a named HTTP request.

Arguments

  • name the name of a defined HTTP request
  • *args any additional arguments, which will be passed to the named request if it is a Function.

Returns

A jQuery Promise that will be resolved when the request does. Any done, fail, or always callbacks will be passed the same arguments that the corresponding callbacks for calls to jQuery.ajax. For successful requests, this means they will receive the response body after it has been modified by any jQuery dataFilters.

Triggers

When the request returns, the [request name].always and either the [request name].done or [request name].fail events will be triggered. Any event handlers will also be passed the same arguments as the promise callbacks.

Example

{
   requests: {
     getWidget: function(name) {
       return {
         url: 'http://example.com/widgets/' + name,
         dataType: 'json'
       };
     }
   },

   showWidget(name) {
     this.ajax('getWidget', name)
         .done(function(data) {
           /// render the JSON data
         });
   }
}