SDK for PHP to access leanIX REST API

2.1.1 2017-03-13 12:43 UTC


LeanIX API version v1, https://developer.leanix.net


This SDK contains wrapper code used to call the LeanIX REST API using PHP.

The SDK also contains two simple examples. The code in samples/ServicesTest.php demonstrates the basic use of the SDK to read Applications from the LeanIX Inventory. The code in samples/ProjectsTest.php demonstrates the basic use of the SDK for Projects in LeanIX.


API token

In order to use the code in this SDK, you need an API token to access a workspace. As a workspace administrator, you can generate it yourself in the LeanIX application under Administration.

The API token acts as credentials to access a LeanIX workspace as the user who generated the token. Hence you should take care to keep it private, for example by using a password safe application.

The LeanIX REST API uses OAuth2 access tokens to protect its resources. The SDK transparently uses the API token that is set in the ApiClient to obtain such an access token from the token provider. The host name of the token provider is normally "svc.leanix.net".

Swagger documentation

You can find the LeanIX REST API documentation here https://app.leanix.net/demo/api/v1/. The documentation is interactive - if you are logged in to your workspace and the REST API is activated, you can try out every function directly from the documentation.

Including the SDK in your project

Installing SDK using Composer

Using Composer is one of the options to install the LeanIX SDK for PHP.

  1. Add "leanix/leanix-sdk-php" as dependency in your project's composer.json file.

        "require": {
            "leanix/leanix-sdk-php": "2.1.*"
  2. Download and install Composer.

    curl -s "http://getcomposer.org/installer" | php

  3. Install your dependencies.

    php composer.phar install

  4. Require Composer's autoloader by adding the following line to your code's bootstrap process.

    require '/path/to/sdk/vendor/autoload.php';


In order to use the SDK in your PHP application, you can use the autoloader which automatically loads required classes from the LeanIX SDK.


You need to instantiate a LeanIX API Client. Here you define the URL to the REST API of your workspace. Please replace demo with the name of your workspace. Also here you need to provide the API token.

$apiClient = new LeanIX\Api\ApiClient();
$apiClient->setApiToken('SvP6eADtbyC6PzLpSK9CmsxQcxnWEcXQxaEkxvan', 'https://app.leanix.net/services/mtm/v1/oauth2/token');

You can then use the API class to execute functions. For each Fact Sheet type in leanIX there is one API class, e.g. for the Fact Sheet type "Application" the API class is called ServicesApi. To print the names of all applications which match the full-text search of "design", you could do the following:

$servicesApi = new LeanIX\Api\ServicesApi($apiClient);
$services = $servicesApi->getServices(false, "design");
foreach ($services as $service)
	echo $service->name."\r\n";

Instructions for SDK developers

Update SDK

Generate from swagger.json

To generate the SDK from the latest REST API go into the codegen folder and use the following maven commands:

cd codegen
mvn clean package

Update the pom.xml properties section so specify the host where the swagger doc-api is pulled from.

Thank You

This API made use of the swagger-* libraries which help you to describe REST APIs in an elegant way. See here for more details: https://github.com/wordnik/swagger-codegen

Copyright and license

Copyright 2015, 2016, 2017 LeanIX GmbH under the MIT license.