Forums/Community/Zendesk Apps

Tip: fetch missing data via the HTTP API

James Rosen
posted this on September 13, 2012 13:19

If you find yourself trying to get some data about a Zendesk object that isn't available from the Apps data API, you can use the HTTP API to fetch it. For example, in a ticket_sidebar app, you can get the requester's external_id as follows:

(function() {
  return {
    requests: {
      fullUserData: function(userID) {
        return {
          url: '/api/v2/users/' + userID + '.json',
          dataType: 'json'
        }
      }
    },

    events: {
      'app.activated': function() {
        this.ajax( 'fullUserData', this.ticket().requester().id() );
      },

      'fullUserData.done': function(data) {
        this.switchTo('someTemplate', { external_user_id: data.user.external_id });
      }
    }
  };
}());

There are no corresponding data events for "non-native" data.

 

Comments

User photo
Sebastiaan Wijchers
mediacompetence

Thanks, this was very helpful for me.

I was wondering if we should consider this as a temporary workaround, or that the missing data will be added at a later stage?

September 18, 2012 01:36
User photo
James Rosen
Zendesk

If you find something is missing, please let us know. There's no guarantee that any particular piece of data will make it into the framework, but we want apps to be as powerful as possible, so we'll try to include as much as "fits."

September 18, 2012 08:15
User photo
Sebastiaan Wijchers
mediacompetence

There might be more as I've just started on our integration, but so far I only needed this workaround to fetch the user's external_id. We use this to link the Zendesk User to a Customer in our CRM.

I could as well do a reverse lookup, but in  this case I could save myself a webservice call if I can instantly check if the external_id has been set.

September 19, 2012 00:21
User photo
Sebastiaan Wijchers
mediacompetence

The second one I'm missing in this Data User API besides external_id is phone which holds the phone number. The e-mail address is available as email, but whenever someone calls we need to fetch the missing data.

I think both external_id as  phone should be added, as this information seems quite vital when integrating systems.

September 25, 2012 03:09
User photo
Jeff Tanner
tangocard

Correct me, but this appear for finding missing user (ticket's requester) information, but what about missing ticket's assignee information?

I am looking for assignee's organization (as assigned within profile's "Org." field).

Thanks

Jeff

October 04, 2012 09:56
User photo
Phillip Haines
zestiadev

Hi James, We're working with the new widget api and it appears that `this.ticket().requester().name()` is returning just the users first name rather than the full name that has been supplied on the ticket. Additional information like organisation, phone number, twitter address would be useful also but I think getting the full name working is key for us.

October 31, 2012 02:40
User photo
James Rosen
Zendesk

@Phillip I can't reproduce that. Could you submit a ticket with the name of the app and your account subdomain? I'll gladly check it out.

October 31, 2012 09:05
User photo
Phillip Haines
zestiadev

@James; thanks we were able to get that sorted in the end.

November 13, 2012 07:07
User photo
Sebastiaan Wijchers
mediacompetence

I see external_id as has been added now, thanks for that!

Any chance we'll see phone phone as well?

November 21, 2012 06:48
User photo
James Rosen
Zendesk

We definitely want to add phone, but it's trickier than others because it can come from a variety of sources. A user can edit her profile and set a phone number, but she could also have a phone number because she called the help desk.

December 06, 2012 11:57
User photo
Thomas Johnson
mailroute

Any chance ticket.requester.organization info (name, data, details, etc) will be added to the apps data API?

January 22, 2013 17:27
User photo
Bart Roodnat
Elmar

Is there also a way to access all the previous comments of a ticket?.

this.comment() is only for the active comment, right?

February 26, 2013 04:58
User photo
James Rosen
Zendesk

Correct. this.comment() is the comment the user is editing. You'll need to use the HTTP API to get comment history.

February 26, 2013 09:38