• Welcome to KonaKart Community Forum. Please login or sign up.
 

Admin API searchProducts question

Started by ReLLiK75, November 18, 2008, 04:25:18 am

Previous topic - Next topic

ReLLiK75

Hi There...

Looks like I'm providing a good bit of activity in the forums, so hopefully my questions will help others who are looking to do or will be looking to do something similar.  :)

Anyway...I'm trying to use the admin version of the searchProducts api (vs the server version).  One of the parameters for the searchProducts API is an AdminProductSearch object.  The examples all show doing a search to return all products belonging to a certain manufacturer or within a certain category, but I need to find a single product belonging to a category and with a specific name.  I tried the following code, however the search results come back empty:

           AdminDataDescriptor adminDataDescriptor = new AdminDataDescriptor ();
            AdminProductSearch adminProductSearch = new AdminProductSearch ();

            adminProductSearch.searchText = "Beloved";   //Beloved is the name of an existing DVD within the sample KK data
            adminProductSearch.categoryId = categoryID;  //categoryID is a passed in value
            adminProductSearch.whereToSearch = -100;   //According to the javaDoc, -100 means "search within all fields"

            adminDataDescriptor.limit = 5;

            if (adminSessionID == null)
                adminSessionID = kkAdminApi.login ( adminUserName, adminPassword );

            AdminProducts adminProducts = kkAdminApi.searchForProducts ( adminSessionID, adminDataDescriptor, adminProductSearch, -1);
            if (adminProducts != null && adminProducts.productArray.Length > 0)
                return true;
            else
                return false;

What am I doing wrong that would cause the search to fail?  The reason I'm trying to implement this code is that I'm dynamically creating products in the KK database.  I only want to create a product if it doesn't already exist.  The only things I have to test against are the categoryID to which the product will belong and the product's name. 

Thanks!
Wayne

ReLLiK75

I'm having the same problem just using the regular server API call searchForProducts.  The demo KK site successfully returns a search, so I know I must be doing something wrong in the way I'm creating my ProductSearch/AdminProductSearch Objects.  What is the correct syntax to search for a product by name?

Thanks!
Wayne

ReLLiK75

Finally figured it out. 

In case anyone else is using SOAP and trying to search for a specific product, you must set ALL of the AdminProductSearch attributes like such:

            AdminProductSearch adminProductSearch = new AdminProductSearch ();

            adminProductSearch.searchText = mySearchText;
            adminProductSearch.categoryId = -100;  // Because there are no enumerations in the SOAP API,  -100 = ProductSearch.SEARCH_ALL
            adminProductSearch.manufacturerId = -100;
            adminProductSearch.promotionId = -100;
            adminProductSearch.productType = -100;
            adminProductSearch.whereToSearch = 0;  //When set to 0, the text search is done only on the product name

Similiarly, when searching on the Server side of the house you must set the following attributes on the ProductSearch object:

            ProductSearch productSearch = new ProductSearch ();
            productSearch.searchInSubCats = true;
            productSearch.searchText = mySearchText;
            productSearch.whereToSearch = 0;
            productSearch.manufacturerId = -100;
            productSearch.categoryId = -100;


Hopefully the hours I wasted trying to figure this out will help someone else.

Wayne