To authorize, use this code:
<?php require('RestClient.php'); //You can download this file from here https://cdn.dataforapps.com/v3/examples/php/php_RestClient.zip try { //Instead of 'login' and 'password' use your credentials from https://app.dataforapps.com/api-dashboard $client = new RestClient('https://api.dataforapps.com/', null, 'login', 'password'); //do something } catch (RestClientException $e) { echo "\n"; print "HTTP code: {$e->getHttpCode()}\n"; print "Error code: {$e->getCode()}\n"; print "Message: {$e->getMessage()}\n"; print $e->getTraceAsString(); echo "\n"; exit(); } ?>
Instead of ‘login’ and ‘password’ use your credentials from https://app.dataforapps.com/api-dashboard
Create an account with DataForApps and then use the credentials from your account dashboard to access DataForApps APIs. Note that the API password is generated automatically by DataForApps and is different from your account password.
DataForApps is using the Basic Authentication, which makes it possible to call our APIs with almost any programming language, Postman app, REST API platforms, and all major frameworks.
Regardless of the programming language, your unique API token should be passed in the ‘Authorization’ header within the request in the following format:
Authorization: Basic login:password
Instead of “login” and “password”, use your API credentials encoded in Base64.
For instance, the Base64-encoded ‘login:password’ value will have the following format:
bG9naW46cGFzc3dvcmQ=
So the whole string will look as follows:
Authorization: Basic bG9naW46cGFzc3dvcmQ=
Check the examples for PHP, Python, and C# on the right to see how it works with a particular programming language.
Note that it is not possible to pass the login and password in URL parameters. Also, you do not have to make a separate authentication call to obtain API credentials. Basic authentication is the only way to access DataForApps API; credentials should always be passed in the header of the request.