---
title: Retrieve Klevu Account Details
slug: php-sdk/retrieving-klevu-account-details
docTags: 
createdAt: 2023-03-22T17:14:21.000Z
---

:::hint{type="info"}
*This guide assumes you have installed the latest version of `klevu/php-sdk` , either via composer or from source, and autoloading is functioning as expected.*
:::

:::hint{type="info"}
Examples in this guide are for vanilla PHP and, as such, will use `new` to instantiate objects. If you are using a modern framework such as Magento or Symfony, you should utilise your object manager for dependency injection and preferencing of interfaces where possible.
:::

## Retrieving Klevu Account Information

To retrieve information about your Klevu account, first locate your Klevu API and REST AUTH keys and create an `AccountCredentials` object (see Quickstart for steps).

Next, instantiate an `AccountLookupService` object and call the `execute` method to create an Account model containing your account details.
The `execute` method will throw exceptions if any issues arise, so you should catch and handle these appropriately.

At this point, you will have an Account object containing your KMC information, including endpoints which can be used for subsequent operations (such as indexing or analytics)

```php
<?php

declare(strict_types=1);

use Klevu\PhpSDK\Exception\AccountNotFoundException;
use Klevu\PhpSDK\Exception\Api\BadRequestException;
use Klevu\PhpSDK\Exception\Api\BadResponseException;
use Klevu\PhpSDK\Exception\ValidationException;
use Klevu\PhpSDK\Model\AccountCredentials;
use Klevu\PhpSDK\Service\Account\AccountLookupService;

$accountCredentials = new AccountCredentials(
    jsApiKey: "klevu-123456780",
    restAuthKey: "ABCDE1234567890",
);
$accountLookupService = new AccountLookupService(
    // Inject any relevant dependencies, such as HTTP Client; Logger; or User Agent provider
);

$account = null;
try {
    $account = $accountLookupService->execute($accountCredentials);
} catch (ValidationException $exception) {
    // Account credentials are empty or invalid
} catch (AccountNotFoundException $exception) {
    // No account exists for JS API Key / REST AUTH Key combination
} catch (BadRequestException $exception) {
    // Klevu API rejected the request as invalid
} catch (BadResponseException $exception) {
    // Klevu API responded in an unexpected manner
}
```

## Retrieving Enabled Klevu Feature Flags

To retrieve information about your Klevu account, first locate your Klevu API and REST AUTH keys and create an `AccountCredentials` object (see Quickstart for steps).

Next, instantiate an `AccountFeaturesService` object and call the `execute` method to create an `AccountFeatures` model containing Klevu feature flags.
The `execute` method will throw exceptions if any issues arise, so you should catch and handle these appropriately.

At this point, you will have an Account Features object which can be used to determine which solutions should be supported in your application.

```php
<?php

declare(strict_types=1);

use Klevu\PhpSDK\Exception\Api\BadRequestException;
use Klevu\PhpSDK\Exception\Api\BadResponseException;
use Klevu\PhpSDK\Exception\ValidationException;
use Klevu\PhpSDK\Model\AccountCredentials;
use Klevu\PhpSDK\Service\Account\AccountFeaturesService;

$accountCredentials = new AccountCredentials(
    jsApiKey: "klevu-123456780",
    restAuthKey: "ABCDE1234567890",
);
$accountFeaturesService = new AccountFeaturesService(
    // Inject any relevant dependencies, such as HTTP Client; Logger; or User Agent provider
);

$account = null;
try {
    $accountFeatures = $accountFeaturesService->execute($accountCredentials);
} catch (ValidationException $exception) {
    // Account credentials are empty or invalid
} catch (BadRequestException $exception) {
    // Klevu API rejected the request as invalid
} catch (BadResponseException $exception) {
    // Klevu API responded in an unexpected manner
}
```

For ease in use in your application, you can also attach the Account Features object to an existing Account model for ease of reference in your application

```php
<?php

// snip

$account = null;
try {
    $account = $accountLookupService->execute($accountCredentials);
    $account->setAccountFeatures(
        $accountFeaturesService->execute($accountCredentials),
    );
} catch (ValidationException $exception) {
    // Account credentials are empty or invalid
} catch (AccountNotFoundException $exception) {
    // No account exists for JS API Key / REST AUTH Key combination
} catch (BadRequestException $exception) {
    // Klevu API rejected the request as invalid
} catch (BadResponseException $exception) {
    // Klevu API responded in an unexpected manner
}

// Get feature flags
$categoryMerchandisingEnabled = $account->getAccountFeatures()->smartCategoryMerchandising;
```

***

## Source Code Reference

- Exception\\[AccountNotFoundException](https://github.com/klevu/php-sdk/blob/master/src/Exception/AccountNotFoundException.php)
- Exception\Api\\[BadRequestException](https://github.com/klevu/php-sdk/blob/master/src/Exception/Api/BadRequestException.php)
- Exception\Api\\[BadResponseException](https://github.com/klevu/php-sdk/blob/master/src/Exception/Api/BadResponseException.php)
- Exception\\[ValidationException](https://github.com/klevu/php-sdk/blob/master/src/Exception/ValidationException.php)
- Model\\[Account](https://github.com/klevu/php-sdk/blob/master/src/Model/Account.php)
- Model\Account\\[AccountFeatures](https://github.com/klevu/php-sdk/blob/master/src/Model/Account/AccountFeatures.php)
- Model\\[AccountCredentials](https://github.com/klevu/php-sdk/blob/master/src/Model/AccountCredentials.php)
- Service\Account\\[AccountFeaturesService](https://github.com/klevu/php-sdk/blob/master/src/Service/Account/AccountFeaturesService.php)
- Service\Account\\[AccountLookupService](https://github.com/klevu/php-sdk/blob/master/src/Service/Account/AccountLookupService.php)

