Use Mustangserver with PHP

1. Log in on https://api.usegroup.de/devportal/ , select the latest Mustangserver API and download the OpenAPI (=Swagger) definition of the API

Screenshot 1


2. Open the file in a text editor, select all and copy
3. Download, run and access a Swagger Editor Docker image, i.e. by using

docker run -d -p 80:8080 docker.swagger.io/swaggerapi/swagger-editor

to run locally via port 8080. Paste the copied Swagger file.

4. use Generate Client|PHP to download a zip file, extract.

Screenshot 2

5. edit the extracted composer.json, change the name of the project in the composer.json file to lowercaps/lowercaps

6. Upgrade the version number of php-cs-fixer to ^2.0. Then run “composer install” in that directory.

Screenshot 3

7. Copy the example from the “Getting started” section of the readme.md to a new file, called index.php

Screenshot 4

8. Now we allow client credentials. Click on Applications (8.), Default Application

9. click Production Keys/OAuth2 Token. Alternatively you can create API keys. Please note that all old API keys will continue to work if you create new API keys. Please also note that unlike OAuth tokens, API keys may have to be refreshed for future versions because they are bound to the currently existing subscriptions.
10. As preparation for authentication: Check Client Credentials and click the Update button on the bottom of the page.

11. Now we get a access token: For this part we will use a token which will expire shortly. Click Generate Access Token (11.), Generate and copy the resulting token. Paste it in

Screenshot 5

12. index.php (12.), in the same file

13. change ErrorController to Mustangcontroller (13.) and
14. handle() to ping() (14.). Please note that usual PHP editors will give you code completion. Now you can open resulting index.php via your server and PHP processort in your browser, it should now look like Screenshot 6:

Screenshot 6

OAuth2 Authentication

Back to Screenshot 4:

In index.php paste the following code

$client = new GuzzleHttp\Client();
$res = $client->request('POST', 'https://gw.usegroup.de:9443/oauth2/token', [
    'auth' => ['<15.>', '<16.>'],
    'form_params' => [
        'grant_type' => 'client_credentials',
    ]
]);

$json = json_decode($res->getBody(), true);
Screenshot 7

15. copy Consumer Key (15., from screen 4) to the beginning of index.php (16.),

17. reveal and copy Consumer Secret (18.).

19 replace the static access token which will become invalid by $json[“access_token”]

20 Create or download a invoice to be validated, e.g. https://www.mustangproject.org/files/MustangGnuaccountingBeispielRE-20201121_508.pdf and save it as factur-x.pdf

21 Change the method to validateFile and

22 html escape the validation result, so that the result in the browser looks like screenshot 8:

PHP Client tutorial
Screenshot 8


That’s it. Instead of displaying the XML you can now parse it 🙂