Examples / How To
Account Management
Retrieve Klevu Account Details
6min
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 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 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 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 // 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 exception\api\ badrequestexception exception\api\ badresponseexception exception\ validationexception model\ account model\account\ accountfeatures model\ accountcredentials service\account\ accountfeaturesservice service\account\ accountlookupservice