2

Hi I'm trying to get data from an api that ONLY returns JSON rather than JSONP. Every time I try to get the data connecting as JSONP it doesn't work because I am not expecting JSON. So, I guess I have to use a PHP proxy to get past the cross-domain issue so I can interpret the JSON request. [Simple PHP Proxy][1] is one that I'm trying to use but I am having a hell of a time trying to get the most basic functionality to work. When I type the url I want to query into his example on the example page, it works. When I do it, it doesn't, sometimes I get a "Missing Command" (the API's way of telling me that there are too many or too little arguements) or a httpcode/jsoncode 404.

Expensify is the API I am querying. I am first trying the Authenticate command. IF you type this URL in your browser, you get the results I want: https://api.expensify.com?command=Authenticate&partnerName=applicant&partnerPassword=d7c3119c6cdab02d68d9&partnerUserID=expensifytest%40mailinator.com&partnerUserSecret=hire_me

Using the Simple PHP Proxy my request URL turns out to be: http://people.rit.edu/~cjs6948/exp/ba-simple-proxy.php?url=https://api.expensify.com?command=Authenticate&partnerName=applicant&partnerPassword=d7c3119c6cdab02d68d9&partnerUserID=expensifytest%40mailinator.com&partnerUserSecret=hire_me

Here is my very simple jQuery code:

var proxy = 'ba-simple-proxy.php';
url = proxy + '?' + "url=" + "https://api.expensify.com?    command=Authenticate&partnerName=applicant&partnerPassword=d7c3119c6cdab02d68d9&partnerUserID=expensifytest%40mailinator.com&partnerUserSecret=hire_me";
$.getJSON( url, function(data){});

"ba-simple-proxy.php" can be found [here][3]. Does anyone have any experience trying to connect to a cross-domain API via a proxy? Maybe even this one? Have any better ideas? Any help is appreciated, thanks.

mc5
  • 93
  • 1
  • 5
  • Since I couldn't add more than two links, here are the rest... Simple PHP Proxy: http://benalman.com/projects/php-simple-proxy/ ba-simple-proxy.php: https://raw.github.com/cowboy/php-simple-proxy/master/ba-simple-proxy.php Expensify API: https://www.expensify.com/api-services.html – mc5 May 20 '12 at 16:38
  • You're really going into overkill mode here. You don't need a proxy library, you just need to use CURL to make one request. – Mahmoud Al-Qudsi May 20 '12 at 17:02
  • I don't have too much experience with CURL, could you be any more specific with an example or something? I'm going to start looking into it now, though. – mc5 May 20 '12 at 18:20

1 Answers1

0

You need to encode the URL as the parameter "partnerName" will be passed to your ba-simple-proxy.php script and not the api.expensify.com website. I do believe the function you're looking for is: encodeURI(uri)

Recognizer
  • 746
  • 1
  • 7
  • 17
  • Hmmm, I tried wrapping everything after "url=" in encodeURI() and still get the missing command error. – mc5 May 20 '12 at 18:20