Authentication
While all services require you to provide a valid API key for interaction, some require the added step of actually authenticating with the system. This extra layer of security is used for services which manage records associated with your application & API key.
A good example where authentication is necessary would be when interacting with the cache service. Since this service is used for modifying records associated with your application, it makes sense to ensure whoever is accessing it is allowed to.
All authentication is handled via standard HTTP authentication using your api key, email and password associated with your API account. It is recommended that all communication with secure services is done over HTTPS. However, as we are currently in the beta stage of development, HTTPS is not supported. SSL support is on the roadmap, though.
Examples
Here are a few examples of how you would access the secure meter service.
Browser
You can easily access all API features directly from your
browser. For secure services, you can add email and
password parameters to your URL query string. This
will authenticate your browser session:
http://rest.snag.gr/images/get.meters.xml?key=API_KEY&email=ACCOUNT_EMAIL&password=ACCOUNT_PASSWORD
PHP
This example makes use of PHP's cURL library. If your server
does not come with cURL support, you can try using PHP's intrinsic
file access functions as an alternative.
$values = array
(
'key' => 'API_KEY',
);
$curl = curl_init('http://rest.snag.gr/images/get.meters.xml');
curl_setopt($curl, CURLOPT_USERPWD, 'ACCOUNT_EMAIL:ACCOUNT_PASSWORD');
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $values);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec($curl);
curl_close($curl);