Page 1 of 1

Making calls to API via proxy

Posted: Thu Feb 14, 2013 10:00 pm
by Yarden Gur

Hey,

I found out I can not make any calls to api server via Javascript due to browser limitations.
I was told I can do that via simple php code. So I set up a PHP page who make the call to the API server.

Now I have this code on a page that invokes the serivce:

precode
var myAPI = new Tiggr.RestService({
'url': 'http://api.server.com/ads/apisearch',
'dataType': 'xml',
'type': 'get',
});
/code/pre

I chagned the url to 'myProxy.php?page=http://api.server.com/ads/apisearch'

How do I pass the data (requested parameters)? Where can I find the JS code for that?

Thanks,


Making calls to API via proxy

Posted: Thu Feb 14, 2013 10:04 pm
by maxkatz

If you are making a jQuery calls from a PHP page, you shouldn't be using any Tiggzi functions.. only use jQuery directly. Also, making calls to a service from PHP -- it outside the scope of our support.


Making calls to API via proxy

Posted: Thu Feb 14, 2013 10:10 pm
by Yarden Gur

Thanks Max.

So basically the only two ways I can make cross domain call for API is JSONP & CORS ?


Making calls to API via proxy

Posted: Thu Feb 14, 2013 10:11 pm
by maxkatz

Yes, I'd recommend enabling CORS.


Making calls to API via proxy

Posted: Fri Feb 15, 2013 6:58 pm
by Yarden Gur

Hi Max,

What if I want to publish my app with using tiggzi proxy, is that possible?


Making calls to API via proxy

Posted: Fri Feb 15, 2013 7:36 pm
by Kateryna Grynko

Hi Yarden,

If you publish the app, Tiggzi Proxy automatically turns off (if it was ticked) for all Rest services.

Tiggzi Proxy works for apps only on *.tiggzi.com. Apps from other domains can't use Tiggzi Proxy due to security settings.


Making calls to API via proxy

Posted: Fri Feb 15, 2013 9:27 pm
by Yarden Gur

Hi Katya,

eventually I've found a solution, If application hosted on private server then uploading the application just need to create php page with this code:

precode
<?php
define ('HOSTNAME', 'http:&#47;&#47;apiserver&#46;com?q='&#46;$_GET["q"]&#46;'');

$path = ($POST['ws_path']) ? $POST['ws_path'] : $_GET['ws_path'];
$url = HOSTNAME&#46;$path;

&#47;&#47; Open the Curl session
$session = curl_init($url);

if ($POST['ws_path']) {
$postvars = '';
while ($element = current($POST)) {
$postvars &#46;= key($POST)&#46;'='&#46;$element&#46;'&';
next($POST);
}
curl_setopt ($session, CURLOPT_POST, true);
curl_setopt ($session, CURLOPT_POSTFIELDS, $postvars);
}

&#47;&#47; Return the call not the headers
curl_setopt($session, CURLOPT_HEADER, false);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);

&#47;&#47; call the data
$xml = curl_exec($session);

header("Content-Type: text&#47;xml");

echo $xml;
curl_close($session);
?>
/code/pre

This will give an XML output page.
When creating a service just use this page as the service URL.

Hope it would help you in future incase anybody asks.


Making calls to API via proxy

Posted: Fri Feb 15, 2013 9:49 pm
by Kateryna Grynko

I'm sorry, a small typo in my previous reply. The proxy doesn't work for *.tiggzi.net domains either