LangLion Developer Wiki

⚠️ APIv2 is legacy

APIv2 is considered legacy and is no longer recommended for new integrations.

We strongly encourage you to use APIv4 for all new integrations and to migrate existing integrations where possible.

Please refer to our latest APIv4 documentation for up-to-date information and integration guidelines:

Click here to view the APIv4 example documentation - your own documentation is at https://[your-instance].langlion.com/api/v4/docs

API Authentication and Authorization - /api/v2/authorize

Authentication to the LangLion API is performed with HTTP Basic Authentication 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

Request

1$ curl --location --request POST 'https://test.langlion.com/api/v2/authorize' \
2-u client_id:client_secret \
3--form 'grant_type="client_credentials"'

Response

1{
2    "access_token": "ecc1fb62a7d0cb0c639da11d927bcfffeca6e63bf7e769bcfe445cb462ea096e49e5c58ed7698e80679cbd6152f095d38fba8e542f12a44e01b7c31fcb4aac7242f71ce0aeefa238306ffc735192508c8d50f78cccface0c2dae1b410dc0a1a5e6fbfe4a924f61f30c5790d469d0a83009977a061fd3cbdfefbda0bb26bdeaad2ff90797759d22220abcbc01e2124f199ad4d2493e9a13fe8d6e3f2f1ba5568cb56c8ba462047789834c1c9532e6a7d08ba279edec21201c80922933ee54ffe01ee98e76f513339f951af694504dee4b91f13bb4306d1c571d8c5f43dd8fcf5432e60056b029acaa4174e3d3a49fa43197f45b815c229efed10de376b79497",
3    "expires_in": 2592000,
4    "token_type": "Bearer",
5    "scope": "administrator"
6}

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.

Sample code

JavaScript - Fetch

 1var username = 'client_id';
 2var password = 'client_secret';
 3
 4var Headers = new Headers();
 5headers.set('Authorization', 'Basic ' + Buffer.from(username + ":" + password).toString('base64'));
 6
 7var formdata = new FormData();
 8formdata.append("grant_type", "client_credentials");
 9
10var requestOptions = {
11  method: 'POST',
12  headers: headers,
13  body: formdata,
14  redirect: 'follow'
15};
16
17fetch("https://test.langlion.com/api/v2/authorize", requestOptions)
18  .then(response => response.text())
19  .then(result => console.log(result))
20  .catch(error => console.log('error', error));

NodeJS - Axios

 1var axios = require('axios');
 2var FormData = require('form-data');
 3var data = new FormData();
 4data.append('grant_type', 'client_credentials');
 5
 6var username = 'client_id';
 7var password = 'client_secret';
 8
 9var config = {
10  method: 'post',
11  url: 'https://test.langlion.com/api/v2/authorize',
12  auth: {
13    username,
14    password
15  },
16  data
17};
18
19axios(config)
20.then(function (response) {
21  console.log(JSON.stringify(response.data));
22})
23.catch(function (error) {
24  console.log(error);
25});

PHP - cURL

 1 <?php
 2
 3$username = 'client_id';
 4$password = 'client_secret';
 5
 6$curl = curl_init();
 7
 8curl_setopt_array($curl, array(
 9  CURLOPT_URL => 'https://test.langlion.com/api/v2/authorize',
10  CURLOPT_RETURNTRANSFER => true,
11  CURLOPT_ENCODING => '',
12  CURLOPT_MAXREDIRS => 10,
13  CURLOPT_TIMEOUT => 0,
14  CURLOPT_FOLLOWLOCATION => true,
15  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
16  CURLOPT_CUSTOMREQUEST => 'POST',
17  CURLOPT_POSTFIELDS => array('grant_type' => 'client_credentials'),
18  CURLOPT_HTTPAUTH => CURLAUTH_BASIC,
19  CURLOPT_USERPWD => "$username:$password" 
20));
21
22$response = curl_exec($curl);
23
24curl_close($curl);
25echo $response;