3

Tip: fetch missing data via the HTTP API

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.

22 comments

  • 0

    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?

  • 0

    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."

  • 0

    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.

  • 0

    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.

  • 0

    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

  • 0

    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.

  • 0

    @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.

  • 0

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

  • 0

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

    Any chance we'll see phone  phone  as well?

  • 0

    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.

  • 0

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

  • 0

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

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

  • 0

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

  • 0

    How would I use this technique to get the requestors organization name from the ticket view? I was previously able to do this in widgets with: {{ticket.organization.name}} but I can't figure out the way to get this information in the new zendesk apps interface.

  • 0

    Hi Nick

    There isn't a way to get that via the apps framework just yet but you should be able to get those values within a Zendesk App by leveraging the REST API.

    You can find an example here.

    Hope this helps

    Thanks

    Maxime

  • 0

    As indicated by Sebastiaan we also need the users phone for our App.  Using this fullUserData API call workqround is providing this and was easy to implement.  However, we also need to get the user's phone if it gets changed.  It there an event we can register when this happens so we can retrieve the new   phone ?

  • 0

    @Steve: Since the phone number isn't available except via the REST API, there is no event that will fire in an app when a phone number is updated.

  • 0

    @Steve

    Having dealt with this before I'd recommend listening for the app.activated event and then checking the phone number via HTTP call. It is a bit heavy-handed but should achieve what you're looking for, because if the current Agent moves to the user profile page and back it will fire the app.activated event when they return to the ticket. Just make sure nothing else important is waiting on that request to avoid slowing the Agent down.

    I'd also suggest you submit a request for this in our Product Feedback forum  to make it known that you'd like this feature in the apps framework. I'd do it myself because I'd like to see it too, but potential customers like yourself tend to pull more weight :) 

  • 0

    Joe,

    Thanks, your recommendation is exactly what we are currently doing.  It is just annoying that the agent needs to go out and back into the user for our App to update. The simple solution is a fire an event when "any" user data changes then the App would be able to decide what it wants to do about it.

  • 0

    @Steve

    Thanks for the explanation. I assumed too much. I would agree that this isn't a good solution for apps that live on the user profile page. I had used it for an app on the ticket page that used information about the user. The concern there was that the Agent might switch to the user profile, update the info, and switch back to the ticket leaving the app on the ticket with outdated user info.

    What you suggest does sound like the optimal solution, but is likely further out. This is because the Apps Data API that is available currently is actually pulling the current value of the field for the current Agent (client-side). The way user profiles in Zendesk work at present would mean that providing an Apps Data API for users still wouldn't solve your problem, because the loaded user profile doesn't automatically update when background changes are made (i.e. changes not made by the current Agent on the currently loaded profile page). Being able to detect/push changes from the REST API level is something we don't have (yet) for users, unfortunately.

    This may sound crazily convoluted, but there is one other option given the framework:

    Build a server-side application that will poll the REST API for the user's profile and send a notification to your app if/when it changes. So your client-side app, when loaded, would have to make a request to your server-side app including the user's ID. Then your server-side app can check for changes  to that user (via REST API) every x seconds and if it finds any  send them via our notify API to the client side app, which can then detect the notification. The notification could include the updated user properties, too, to save your client-side app from having to GET them itself. Then use app.willDestroy to detect when the client-side app is closed, and tell your server-side app to stop polling the REST API for changes.

    All of this to say: yes, this could definitely be much simpler. Thank you for highlighting the need for it.

  • 0

    @Steve Or are you only looking to detect changes on the currently-loaded user profile? Maybe I assumed too much again.

  • 0

    Joe,

    Thanks for your input. I want to be careful about what I ask for since I am new to Zendesk, the API and the Apps capability.  My preference is to try to use what you provide and see if I can make it work and maybe learn to make it work better as I fully understand your capabilities.  That said, I already have a fully functioning Telephony interface (to Asterisk) for inbound call ticket creation and an App with full outbound dialing capability. You are close in describing what I am trying to do now.  When the ticket is open and the agent clicks on the User tab and makes edits I want to be able to synchronize the user edits back into the ticket and reflect the edits in the App.  It would be nice for this to be seamless.  I refuse to poll the REST API because polling is very bad from my perspective. The direction I am heading now is to have some clickable buttons in the App that make ajax calls to my own backend services.  Those will query the REST API, make REST API updates where necessary and report back to the App so it has current information.

Please sign in to leave a comment.