4

I am having issues using the import.io API.

Despite my app being used and deployed in the UK it will return (for certain stores) incorrect currencies and price data due toe Import.IO's servers being deployed in the US. I spoke with the support team there who helpfully informed me that I could host a proxy server to the Import API.

I managed to get an AWS instance running and have installed Squid as a proxy server. I changed my Firefox connection settings and have successfully managed to browse the web via this proxy server (also verified that my ip was the IP of my server)

However I am not entirely sure how exactly I am meant to call the Import library from within my application.

The application is built in PHP and a current example of how I would generate a URL to call would be:

public function generateCall( $import_key, $url )
{
    return sprintf(
        'https://api.import.io/store/data/%s/_query?input/webpage/url=%s&_user=XXXX&_apikey=%s',
        $import_key, urlencode( $url ), self::$apikey
    );
}

I am calling the api.import.io server directly.

Daniel Benzie
  • 479
  • 1
  • 5
  • 27
  • I found this article on the import IO site: http://support.import.io/knowledgebase/articles/255254-cross-domain-issues-in-browsers It advises me how to set up the proxy on nginx however I already have apache up and running. – Daniel Benzie Mar 06 '15 at 16:29

2 Answers2

4

You can use CURL and fetch the API. Then, You can find a proxy from certain country to fetch the API data by country.

$user = 'User';
$key = 'key';
$url = 'https://api.import.io/store/data/%s/_query?input/webpage/url=%s&_user=XXXX&_apikey=%s';
$proxy = '127.0.0.1:8888';
//$proxyauth = 'user:password';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_PROXY, $proxy);
//curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxyauth);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
$curl_scraped_page = curl_exec($ch);
curl_close($ch);

echo $curl_scraped_page;
Rex Adrivan
  • 993
  • 1
  • 10
  • 23
1

If i understand your problem correctly, you are trying to access the import.io resource via your squid proxy. There are several options of doing that

  1. setting the system proxy to squid.
  2. setting PHP's http proxy to squid.
Community
  • 1
  • 1
Shimon Tolts
  • 1,602
  • 14
  • 15
  • Hi Shimon, Looking @ the import help document I dont think option 2 would help me because I would simply be calling the same import URL - I need to actually host a proxy server to the API's as per "If CNAME is not an option for you, you could host a proxy server to the APIs." I have set up squid as a proxy server - the recommended set up for hosting a proxy server to the APIS is in the attached article on the original post however I am using ubuntu and cant seem to find a way to set this up. – Daniel Benzie Mar 11 '15 at 09:32