PHP code example of kruegge82 / dhl-authentication-oauth-api

1. Go to this page and download the library: Download kruegge82/dhl-authentication-oauth-api library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

kruegge82 / dhl-authentication-oauth-api example snippets





d=false;

$config = Configuration::getDefaultConfiguration();
$config->setHost($config->getHostString($config->getHostSettings(), $prod)); //0=Sandbox 1=Productive

$apiInstance = new kruegge82\DHLAuth\Api\AuthenticationApi(
    // If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`.
    // This is optional, `GuzzleHttp\Client` will be used as default.
    new GuzzleHttp\Client(),
    $config
);
$grant_type = 'grant_type_example'; // string
$username = 'username_example'; // string | GKP user name. Required for grant_type=password.
$password = 'password_example'; // string | GKP password. Required for grant_type=password.
$client_id = 'client_id_example'; // string
$client_secret = 'client_secret_example'; // string

try {
    $result = $apiInstance->dispenseToken($grant_type, $username, $password, $client_id, $client_secret);
    print_r($result);
} catch (Exception $e) {
    echo 'Exception when calling AuthenticationApi->dispenseToken: ', $e->getMessage(), PHP_EOL;
}