List Existing Attributes
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.
To retrieve attributes used by Klevu's XML Feed Monitoring service, first locate your Klevu API and REST AUTH keys and create an AccountCredentials object (see Quickstart for steps).
Next, instantiate an Indexing\AttributeService object and call the get method to return a collection of all attributes registered in Klevu indexing. The get method will throw exceptions if any issues arise, so you should catch and handle these appropriately.
At this point, you will have an AttributeIterator object containing Attribute models for all registered attributes, which can be filtered and used in subsequent operations.
If you need to filter the return value of get, for example to remove immutable attributes or to identify attributes of a specific data type, you can call the filter method with your callback.
Note: filtering an iterator in this way will return a copy, and will not modify the data contained within the original return object.
To retrieve a registered attribute by name, first locate your Klevu API and REST AUTH keys and create an AccountCredentials object (see Quickstart for steps).
Next, instantiate an Indexing\AttributeService object and call the getByName method with your credentials and the name of the attribute being search for. The getByName method will throw exceptions if any issues arise, so you should catch and handle these appropriately.
At this point, you will have either an Attribute object or null.
Note: this method does not map to a discrete API endpoint. Its purpose is essentially syntactic sugar, wrapping get and filter calls described above.
The attributeName value is not case sensitive in Klevu's indexer and, therefore, is not case sensitive in name lookups in the PHP-SDK. For example, a request for example_attribute may return EXAMPLE_ATTRIBUTE or other cased variations; though only one attribute (at most) will ever be returned from the API.
The attributeName property will reflect the case used at time of registration.