Forums/Community/Zendesk Apps

Http Requests

Chad Pickerell
posted this on August 07, 2012 15:45

Hi,

I am in the early stages of creating an App to display additional information on users who have submitted tickets.  To do this I have created a REST web service using WCF which serves up data from our local customer database.

I've made my app as close as possible to the example Bookmarks app but I cannot get the HTTP requests to work.  Here is my app.js code:

 

function() {
  return {
    requests: {
      fetchUserData: function() {
        return {
          url: 'http://testing.policyworks.com/MaxDataService/APIs/MaxDataRetriever.svc/UserData/chad.pickerell@policyworks.com',
          type: 'GET'
        };
      }
    },
    events: {
      'app.activated' : 'requestUserData',
      'fetchUserData.always': function(e, data) {
        this.renderUserData((data || {}).userInfo);
      },
    },
    requestUserData: function() {
      this.ajax('fetchUserData');
    },
    renderUserData: function(userInfo) {
      this.userInfo = userInfo;
      this.switchTo('list', { userInfo: this.userInfo});
    }
  };
}());

I am pretty sure all of my method calls are working as my 'list' template is showing up properly but my web service is not getting hit.  I feel like I am missing something small but significant.  Any help or suggestions would be much appreciated.

 

Comments

User photo
Adam
Zendesk

@chad that link doesn't seem to work for me. Is the service still running?

One other thing to try is using console.log() for your calls. For example: 

 

console.log(data);

 

will give you the data object and let you see what's being returned. 

August 07, 2012 16:00
User photo
Chad Pickerell
policyworks

@Adam, sorry I was hosting the service on my local machine.  You should now be able to reach it at:

http://dev.policyworks.com/MaxDataService/APIs/MaxDataRetriever.svc/userdata/helloworld 

This will return some test data in json.

August 07, 2012 16:38
User photo
Adam
Zendesk

@Chad I'm not getting anything back when I hit that URL. 

August 07, 2012 17:20
User photo
Chad Pickerell
policyworks

@Adam, this one should work now:

http://testing.policyworks.com/MaxDataService/APIs/MaxDataRetriever.svc/UserData/blah

I've tested it from outside our local network and was able to get some data back.

August 07, 2012 20:04
User photo
Chad Pickerell
policyworks

@Adam, I should also mention that the default return type is json but I've seen some browsers (ie. Chrome) return it as xml.  It depends on the value of the 'Content-Type:' header in the request.  Do http requests in the zendesk apps support the addition/modification of the http request headers?

August 07, 2012 20:20
User photo
James Rosen
Zendesk

App AJAX requests take all of the options that jQuery.ajax does, so if you want to set the Accept header to "application/json", set dataType to "json":

fetchUserData: function() {
  return {
    url: 'http://...',
    type: 'GET',
    dataType: 'json'
  };
}
August 07, 2012 21:08