XML to JSON API Proxy for Quick Mash-ups
While building our company dashboard, which was mentioned in our previous blog post on SVG with Raphael, I came across a problem with the project management tool we use, Pivotal Tracker.
The Pivotal Tracker API is only in XML, which means you can't do cross-domain requests and access the API via javascript. This meant that, if I wanted to extract data about the status of our user stories, I would have to do it on the server side. As everything so far had been done with javascript on the client side, I was reluctant to start making things more complicated. I contacted Pivotal, who said they might think about adding JSON at some point, but I didn't want to wait for them to sort it out. Instead, I built a quick API proxy that allows you to make a request to a XML API and get back JSON. So, now, I can do this in my javascript: It will proxy the GET request to the API and convert the XML response into JSON, via http://xml2json.heroku.com (supports JSONP). I've put the code on GitHub http://github.com/bitzesty/xml2jsonp in case anyone else needs to do the same thing.6 comments
Aug 25, 2010
Marcos Zanona said...
It seems it ignores additional parameters started with &num_posts=2 for example.
Apr 27, 2011
Aaron Layton said...
Yeah I get the same problem... I need to send multiple data values
Sep 25, 2011
proxy said...
Wow! What a mash up of great ideas. The information have just sifted on my mind and ego.
Oct 19, 2011
Matt said...
Yea I have noticed the same thing... can't do much if you can't pass params
Oct 19, 2011
Matt said...
Actually... You have to use object syntax for the data param when passing additional parameters to $.ajax ... example $.ajax({
type: "GET",
url: 'http://xml2json.heroku.com',
data: {url : 'https://www.pivotaltracker.com/services/v3/projects/'+projectId+'/iterations/current?token='+trackerToken+'&limit=50'},
dataType: 'jsonp',
success: function(data) {
console.log(data);
}
});
This is because their code only grabs the url params and the callback param