API Authentication
If you want to use Deepser API you must authenticate before using it.
The authentication supported by Deepser are currently of 2 types: the Basic Authentication and the Authentication with Token. We strongly suggest to use Token Authentication for improved security.
AUTHENTICATION WITH TOKEN
This can be done, before any request to the API, with some simple lines of code to add the Authentication parameters to the HTTP Headers.
In addition to the Basic Authentication, you have also to enable the Token for the user you want to authenticate.
To do that, you have to login into Deepser as a System Admin.
Go to the Configuration for the User you want to enable to token Authentication through API.
The menu in Deepser is System > Permissions > Users and then select the user you need to enable for token authentication.
PLEASE NOTE: If the “API Token” field isn’t visible, expose it by pressing the edit form button.
Then expose the field by using drag and drop.
You can use the three buttons to perform automatic actions on the Token: generate, delete or copy to clipboard.
From a developer’s perspective, once enabled the Token for the User, you need to set the header of the HTTP Request with the token.
In the following example, we see how to add the authentication parameter to a CURL request in PHP language:
$host = 'http://deepserhost';
$process = curl_init($host);
$token="DEMO_TOKEN";
$headers = array(
'Authorization: Bearer '. $token,
'Accept: application/json'
);
curl_setopt($process, CURLOPT_HTTPHEADER, $headers);
// other lines to set the API request
…
// call the API using CURL
$return = curl_exec($process);
curl_close($process);
Where http://deepdeskhost is the address of your Deepser and token is the token generated for the user.
BASIC AUTHENTICATION
This can be done, before any request to the API, with some simple lines of code to add the Authentication parameters to the HTTP Headers.
To achieve that we need to set the header with the string ‘username’:’password’ encoded in base64 format.
In the following example, we see how to add the authentication parameter to a CURL request in PHP language:
$host = 'http://deepserhost';
$process = curl_init($host);
$headers = array(
'Authorization: Basic '. base64_encode("user:password")
);
curl_setopt($process, CURLOPT_HTTPHEADER, $headers);
// other lines to set the API request
…
// call the API using CURL
$return = curl_exec($process);
curl_close($process);
Where http://deepserhost is the address of your Deepser and user:password is your username/password.
Of course, if you prefer to use other languages, the REST technology is language-independent.
We see how to use Java to make such a call:
String encoding = Base64Encoder.encode ("user:password");
HttpPost httppost = new HttpPost("http://deepserhost");
httppost.setHeader("Authorization", "Basic " + encoding);
// other lines to set the API request
…
// call the API using Java HttpRespnse
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
Now that you know how to authenticate to Deepser API, go to the next lesson to see the advanced documentation of the API.
We assume you have already read the API introduction and you have learnt all the basic concepts stated in that guide.