Yarden Gur
Posts: 0
Joined: Sat Feb 02, 2013 3:26 pm

Making calls to API via proxy

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,

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

Making calls to API via proxy

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.

Yarden Gur
Posts: 0
Joined: Sat Feb 02, 2013 3:26 pm

Making calls to API via proxy

Thanks Max.

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

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

Making calls to API via proxy

Yes, I'd recommend enabling CORS.

Yarden Gur
Posts: 0
Joined: Sat Feb 02, 2013 3:26 pm

Making calls to API via proxy

Hi Max,

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

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

Making calls to API via proxy

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.

Yarden Gur
Posts: 0
Joined: Sat Feb 02, 2013 3:26 pm

Making calls to API via proxy

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.

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

Making calls to API via proxy

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

Return to “Issues”