Authentication to the LangLion API is performed with HTTP Basic Authenticaton and client_credentials grant type which will allow you to obtain long-lived OAuth2 access tokens for further API authorization of requests. To obtain your API credentials (username/password) please contact with our support who will guide you throughout the process of generating client id (username) and client secret (password).
Your API credentials provide many privileges, so be sure to keep them secure. Don't share it in publicly accessible areas such as GitHub, client-side code, and so forth.
Always make all API calls over HTTPS
$ curl --location --request POST 'https://test.langlion.com/api/v2/authorize' \
-u client_id:client_secret \
--form 'grant_type="client_credentials"'
{
"access_token": "ecc1fb62a7d0cb0c639da11d927bcfffeca6e63bf7e769bcfe445cb462ea096e49e5c58ed7698e80679cbd6152f095d38fba8e542f12a44e01b7c31fcb4aac7242f71ce0aeefa238306ffc735192508c8d50f78cccface0c2dae1b410dc0a1a5e6fbfe4a924f61f30c5790d469d0a83009977a061fd3cbdfefbda0bb26bdeaad2ff90797759d22220abcbc01e2124f199ad4d2493e9a13fe8d6e3f2f1ba5568cb56c8ba462047789834c1c9532e6a7d08ba279edec21201c80922933ee54ffe01ee98e76f513339f951af694504dee4b91f13bb4306d1c571d8c5f43dd8fcf5432e60056b029acaa4174e3d3a49fa43197f45b815c229efed10de376b79497",
"expires_in": 2592000,
"token_type": "Bearer",
"scope": "administrator"
}
Access token from response could be used as Bearer token to authorize most requests to the LangLion API. Examples of token usage in requests is provided in documentation of API endpoints.
var username = 'client_id';
var password = 'client_secret';
var Headers = new Headers();
headers.set('Authorization', 'Basic ' + Buffer.from(username + ":" + password).toString('base64'));
var formdata = new FormData();
formdata.append("grant_type", "client_credentials");
var requestOptions = {
method: 'POST',
headers: headers,
body: formdata,
redirect: 'follow'
};
fetch("https://test.langlion.com/api/v2/authorize", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
var axios = require('axios');
var FormData = require('form-data');
var data = new FormData();
data.append('grant_type', 'client_credentials');
var username = 'client_id';
var password = 'client_secret';
var config = {
method: 'post',
url: 'https://test.langlion.com/api/v2/authorize',
auth: {
username,
password
},
data
};
axios(config)
.then(function (response) {
console.log(JSON.stringify(response.data));
})
.catch(function (error) {
console.log(error);
});
<?php
$username = 'client_id';
$password = 'client_secret';
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://test.langlion.com/api/v2/authorize',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => array('grant_type' => 'client_credentials'),
CURLOPT_HTTPAUTH => CURLAUTH_BASIC,
CURLOPT_USERPWD => "$username:$password"
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;