This Service provides a complete cloud based catalogue management. An app can keep all its items based on category on the Cloud. This service provides several utility methods to manage catalogue on the cloud. One can add items with its related information in a particular category. And there can be several categories in a catalogue. The App developer can create several catalogues if needed. The Cart service can be used along with Catalogue service to create an end to end Shopping feature for a Mobile and Web App
In order to use the various functions available under a particular API, a developer will have to create an instance of ServiceAPI by passing the apiKey and the secretKey which has been received while creating an app.
ServiceAPI api = new ServiceAPI("<API_KEY>","<SECRET_KEY>");
After initialization, developer needs to call the buildXXXService method on ServiceAPI instance to get the instance of the particular API that you wish to build. For example, To build an instance of CatalogueService, buildCatalogueService() method needs to be called.
CatalogueService catalogueService = api.buildCatalogueService();
Once the API instance has been retrieved, You are ready to use the functions available for that particular API.
The methods available under a particular API will return the domain object (like Catalogue in this case) as a response which will have the accessor / mutator to access the available properties for that object. You can get the response in the form of JSON as well. We have provided the JSON response with every function detail which can be retrieved by calling the toString() on the returned object.
String catalogueName = "CatalogueName";
String catalogueDescription = "CatalogueName";
Catalogue catalogue = catalogueService.createCatalogue(catalogueName,catalogueDescription); /* returns the Catalogue object. */
System.out.println("name is " + catalogue.getName());
System.out.println("description is " + catalogue.getDescription());
String jsonResponse = catalogue.toString(); /* returns the response in JSON format. */
The functions available under Catalogue API can throw some exceptions in abnormal conditions. Example of the same has been given below.
E.g. If App developer is creating a category under the catalogue which is not in database, the function will throw the App42Exception (as shown below) with message as "Not Found" and the appErrorCode as "3401" and the details as "Catalogue by the name '<catalogueName>' does not exist".
String catalogueName = "CatalogueName01";
String categoryName = "CategoryName01";
String categoryDescription = "CategoryDescription";
try
{
Catalogue catalogue = catalogueService.createCategory(catalogueName,categoryName,categoryDescription);
}
catch( App42Exception ex )
{
int appErrorCode = ex.getAppErrorCode();
int httpErrorCode = ex.getHttpErrorCode();
if(appErrorCode == 3401)
{
// Handle here for Not Found (Catalogue by the name '<catalogueName>' does not exist.)
}
else if(appErrorCode == 3402)
{
// Handle here for Bad Request (The request parameters are invalid. Category by the name '<categoryName>' for the Catalogue by the name '<categoryName>' already exists.)
}
else if(appErrorCode == 1401)
{
// handle here for Client is not authorized
}
else if(appErrorCode == 1500)
{
// handle here for Internal Server Error
}
String jsonText = ex.getMessage(); /* returns the Exception text in JSON format. (as shown below)*/
}
{
"app42Fault": {
"httpErrorCode": 404,
"appErrorCode": 3401,
"message": "Not Found",
"details": "Catalogue by the name 'CatalogueName01' does not exist"
}
}
Below are the HTTP Error Codes and their description, the function under the Catalogue API can throw.
/* 1400 - BAD REQUEST - The Request parameters are invalid 1401 - UNAUTHORIZED - Client is not authorized 1500 - INTERNAL SERVER ERROR - Internal Server Error. Please try again */
Below are the Application Error Codes and their description, the function under the Catalogue API can throw.
/* 3400 - BAD REQUEST - The request parameters are invalid. Catalogue by the name '<catalogueName>' already exists. 3401 - NOT FOUND - Catalogue by the name '<catalogueName>' does not exist. 3402 - BAD REQUEST - The request parameters are invalid. Category by the name '<categoryName>' for the Catalogue by the name '<catalogueName>' already exists. 3403 - NOT FOUND - Category by the name '<categoryName>' for the Catalogue by the name '<catalogueName>' does not exist. 3404 - BAD REQUEST - The request parameters are invalid. Item with the id '<itemId>' for the Category by the name '<categoryName>' and Catalogue by the name '<catalogueName>' already exists. 3405 - NOT FOUND - Item with the id '<itemId>' for the Category by the name '<categoryName>' and Catalogue by the name '<catalogueName>' does not exist. 3406 - NOT FOUND - Item with the id '<itemId>' does not exist. 3407 - NOT FOUND - The number of items for category by the name '<categoryName>' for Catalogue by the name '<catalogueName>' are less than the specified offset : <offset>. */
Various functions available under Catalogue API has been explained below.
Creates a Catalogue for a particular App. Categories can be added to the Catalogue.
Parameters:
Returns:
Response: Catalogue Object
Exception:
/*
3400 - BAD REQUEST - The request parameters are invalid. Catalogue by the name '<catalogueName>' already exists.
*/
String catalogueName = "CatalogueName01";
String catalogueDescription = "CatalogueName";
Catalogue catalogue = catalogueService.createCatalogue(catalogueName,catalogueDescription); /* returns the Catalogue object. */
System.out.println("name is " + catalogue.getName());
System.out.println("description is " + catalogue.getDescription());
String jsonResponse = catalogue.toString(); /* returns the response in JSON format. (as shown below)*/
{
"app42": {
"response": {
"success": true,
"catalogues": {
"catalogue": {
"name": "CatalogueName01",
"description": "CatalogueName"
}
}
}
}
}
Creates a Category for a particular Catalogue e.g. Books, Music etc.
Parameters:
Returns:
Response: Catalogue Object
Exception:
/* 3401 - NOT FOUND - Catalogue by the name '<catalogueName>' does not exist. 3402 - BAD REQUEST - The request parameters are invalid. Category by the name '<categoryName>' for the Catalogue by the name '<catalogueName>' already exists. */
String catalogueName = "CatalogueName01";
String categoryName = "CategoryName01";
String categoryDescription = "CategoryDescription";
Catalogue catalogue = catalogueService.createCategory(catalogueName, categoryName, categoryDescription); /* returns the Catalogue object. */
System.out.println("catalogueName is " + catalogue.getName());
ArrayList<Catalogue.Category> categoryList = catalogue.getCategoryList();
for(Catalogue.Category category :categoryList)
{
System.out.println("name is " + category.getName());
System.out.println("description is " + category.getDescription());
}
String jsonResponse = catalogue.toString(); /* returns the response in JSON format. (as shown below)*/
{
"app42": {
"response": {
"success": true,
"catalogues": {
"catalogue": {
"name": "CatalogueName01",
"categories": {
"category": {
"name": "CategoryName01",
"description": "CategoryDescription"
}
}
}
}
}
}
}
Creates a Item in a Category for a particular Catelogue.
Parameters:
Returns:
Response: Catalogue Object
Exception:
/* 3401 - NOT FOUND - Catalogue by the name '<catalogueName>' does not exist. 3403 - NOT FOUND - Category by the name '<categoryName>' for the Catalogue by the name '<catalogueName>' does not exist. 3404 - BAD REQUEST - The request parameters are invalid. Item with the id '<itemId>' for the Category by the name '<categoryName>' and Catalogue by the name '<catalogueName>' already exists. */
String catalogueName = "CatalogueName01";
String categoryName = "CategoryName01";
ItemData itemData = new ItemData();
itemData.setDescription("Pic");
itemData.setImage("C:/Flowers.jpg");
itemData.setItemId("abc1234007");
itemData.setName("Item");
itemData.setPrice(20.0);
Catalogue catalogue = catalogueService.addItem(catalogueName,categoryName,itemData); /* returns the Catalogue object. */
System.out.println("name is " + catalogue.getName());
ArrayList<Catalogue.Category> categoryList = catalogue.getCategoryList();
for(Catalogue.Category category : categoryList)
{
System.out.println("name is " + category.getName());
System.out.println("description is " + category.getDescription());
ArrayList<Catalogue.Category.Item> itemList = category.getItemList();
for (Catalogue.Category.Item item : itemList)
{
System.out.println("price is " + item.getPrice());
System.out.println("itemId is " + item.getItemId());
System.out.println("name is " + item.getName());
}
}
String jsonResponse = catalogue.toString(); /* returns the response in JSON format. (as shown below)*
{
"app42": {
"response": {
"success": true,
"catalogues": {
"catalogue": {
"name": "CatalogueName01",
"categories": {
"category": {
"name": "CategoryName01",
"items": {
"item": {
"itemId": "ItemId01",
"name": "ItemName01",
"description": "ItemDescription01",
"url": "http://XXXX.jpg",
"tinyUrl": "http://tinyurl.com/XXXX",
"price": 200
}
}
}
}
}
}
}
}
}
Fetches all items for a Catalogue.
Parameters:
Returns:
Response: Catalogue Object
Exception:
/* 3401 - NOT FOUND - Catalogue by the name '<catalogueName>' does not exist. */
String catalogueName = "CatalogueName01";
String catalogueName = "CatalogueName01";
Catalogue catalogue = catalogueService.getItems(catalogueName); /* returns the Catalogue object. */
System.out.println("name is " + catalogue.getName());
ArrayList<Catalogue.Category> categoryList = catalogue.getCategoryList();
for(Catalogue.Category category : categoryList)
{
System.out.println("name is " + category.getName());
System.out.println("description is " + category.getDescription());
ArrayList<Catalogue.Category.Item> itemList = category.getItemList();
for (Catalogue.Category.Item item : itemList)
{
System.out.println("price is " + item.getPrice());
System.out.println("itemId is " + item.getItemId());
System.out.println("name is " + item.getName());
}
}
String jsonResponse = catalogue.toString(); /* returns the response in JSON format. (as shown below)*/
{
"app42": {
"response": {
"success": true,
"catalogues": {
"catalogue": {
"name": "CatalogueName01",
"categories": {
"category": {
"name": "CategoryName01",
"items": {
"item": [
{
"itemId": "ItemId01",
"name": "ItemName01",
"description": "ItemDescription01",
"url": "http://XXXX.jpg",
"tinyUrl": "http://tinyurl.com/XXXX",
"price": 200
},
{
"itemId": "Item4",
"name": "ItemName02",
"description": "Description",
"url": "http://XXXX.jpg",
"tinyUrl": "http://tinyurl.com/XXXX",
"price": 20
}
]
}
}
}
}
}
}
}
}
Fetches all items for a Catalogue and Category.
Parameters:
Returns:
Response: Catalogue Object
Exception:
/* 3401 - NOT FOUND - Catalogue by the name '<catalogueName>' does not exist. 3403 - NOT FOUND - Category by the name '<categoryName>' for the Catalogue by the name '<catalogueName>' does not exist. */
String catalogueName = "CatalogueName01";
String categoryName = "CategoryName01";
Catalogue catalogue = catalogueService.getItemsByCategory(catalogueName,categoryName); /* returns the Catalogue object. */
System.out.println("name is " + catalogue.getName());
ArrayList<Catalogue.Category> categoryList = catalogue.getCategoryList();
for(Catalogue.Category category : categoryList)
{
System.out.println("name is " + category.getName());
System.out.println("description is " + category.getDescription());
ArrayList<Catalogue.Category.Item> itemList = category.getItemList();
for (Catalogue.Category.Item item : itemList)
{
System.out.println("price is " + item.getPrice());
System.out.println("itemId is " + item.getItemId());
System.out.println("name is " + item.getName());
}
}
String jsonResponse = catalogue.toString(); /* returns the response in JSON format. (as shown below)*/
{
"app42": {
"response": {
"success": true,
"catalogues": {
"catalogue": {
"name": "CatalogueName01",
"categories": {
"category": {
"name": "CategoryName01",
"items": {
"item": [
{
"itemId": "ItemId01",
"name": "ItemName01",
"description": "ItemDescription01",
"url": "http://XXXX.jpg",
"tinyUrl": "http://tinyurl.com/XXXX",
"price": 200
},
{
"itemId": "Item4",
"name": "ItemName02",
"description": "Description",
"url": "http://XXXX.jpg",
"tinyUrl": "http://tinyurl.com/XXXX",
"price": 20
}
]
}
}
}
}
}
}
}
}
Fetches count of all items for a Catalogue and Category
Parameters:
Returns:
Response: App42Response Object
Exception:
/* 3401 - NOT FOUND - Catalogue by the name '<catalogueName>' does not exist. 3403 - NOT FOUND - Category by the name '<categoryName>' for the Catalogue by the name '<catalogueName>' does not exist. */
String catalogueName = "CatalogueName01"; String categoryName = "CategoryName01"; App42Response response = catalogueService.getItemsCountByCategory(catalogueName,categoryName); /* returns the App42Response objects. */ boolean success = response.isResponseSuccess(); int totalRecords = response.getTotalRecords(); String jsonResponse = response.toString(); /* returns the response in JSON format. (as shown below)*/
{
"app42": {
"response": {
"success": true,
"totalRecords": 3
}
}
}
Fetches all items for a Catalogue and Category by paging.
Parameters:
Returns:
Response: Catalogue Object
Exception:
/* 3401 - NOT FOUND - Catalogue by the name '<catalogueName>' does not exist. 3403 - NOT FOUND - Category by the name '<categoryName>' for the Catalogue by the name '<catalogueName>' does not exist. 3407 - NOT FOUND - The number of items for category by the name '<categoryName>' for Catalogue by the name '<catalogueName>' are less than the specified offset : <offset>. */
String catalogueName = "CatalogueName01";
String categoryName = "CategoryName01";
int max = 1;
int offset = 0;
Catalogue catalogue = catalogueService.getItemsByCategory(catalogueName,categoryName,max,offset); /* returns the Catalogue object. */
System.out.println("name is " + catalogue.getName());
ArrayList<Catalogue.Category> categoryList = catalogue.getCategoryList();
for(Catalogue.Category category : categoryList)
{
System.out.println("name is " + category.getName());
System.out.println("description is " + category.getDescription());
ArrayList<Catalogue.Category.Item> itemList = category.getItemList();
for (Catalogue.Category.Item item : itemList)
{
System.out.println("price is " + item.getPrice());
System.out.println("itemId is " + item.getItemId());
System.out.println("name is " + item.getName());
}
}
String jsonResponse = catalogue.toString(); /* returns the response in JSON format. (as shown below)*/
{
"app42": {
"response": {
"success": true,
"catalogues": {
"catalogue": {
"name": "CatalogueName01",
"categories": {
"category": {
"name": "CategoryName01",
"items": {
"item": {
"itemId": "iiiiiiiii",
"name": "Item",
"description": "Description 1",
"url": "http://XXXX.jpg",
"tinyUrl": "http://tinyurl.com/XXXX",
"price": 20
}
}
}
}
}
}
}
}
}
Fetches Item by id for a Catalogue and Category.
Parameters:
Returns:
Response: Catalogue Object
Exception:
/* 3401 - NOT FOUND - Catalogue by the name '<catalogueName>' does not exist. 3403 - NOT FOUND - Category by the name '<categoryName>' for the Catalogue by the name '<catalogueName>' does not exist. 3405 - NOT FOUND - Item with the id '<itemId>' for the Category by the name '<categoryName>' and Catalogue by the name '<catalogueName>' does not exist. */
String catalogueName = "CatalogueName01";
String categoryName = "CategoryName01";
String itemId = "ItemId01";
Catalogue catalogue = catalogueService.getItemById(catalogueName,categoryName,itemId); /* returns the Catalogue object. */
System.out.println("name is " + catalogue.getName());
ArrayList<Catalogue.Category> categoryList = catalogue.getCategoryList();
for(Catalogue.Category category : categoryList)
{
System.out.println("name is " + category.getName());
System.out.println("description is " + category.getDescription());
ArrayList<Catalogue.Category.Item>itemList = category.getItemList();
for (Catalogue.Category.Item item : itemList)
{
System.out.println("price is " + item.getPrice());
System.out.println("itemId is " + item.getItemId());
System.out.println("name is " + item.getName());
}
}
String jsonResponse = catalogue.toString(); /* returns the response in JSON format. (as shown below)*/
{
"app42": {
"response": {
"success": true,
"catalogues": {
"catalogue": {
"name": "CatalogueName01",
"categories": {
"category": {
"name": "CategoryName01",
"items": {
"item": {
"itemId": "ItemId01",
"name": "ItemName01",
"description": "ItemDescription01",
"url": "http://XXXX.jpg",
"tinyUrl": "http://tinyurl.com/XXXX",
"price": 200
}
}
}
}
}
}
}
}
}
Removes all Items in a Catalogue.
Parameters:
Returns:
Response: App42Response Object
Exception:
/* 3401 - NOT FOUND - Catalogue by the name '<catalogueName>' does not exist. */
String catalogueName = "CatalogueName01"; App42Response response = catalogueService.removeAllItems(catalogueName); /* returns the App42Response object. */ boolean success = response.isResponseSuccess(); String jsonResponse = response.toString(); /* returns the response in JSON format. (as shown below)*/
{
"app42": {
"response": {
"success": true,
"catalogues": {
"catalogue": {
"name": "CatalogueName01",
"description": "CatalogueName"
}
}
}
}
}
Removes all Items from a Catalogue and Category.
Parameters:
Returns:
Response: App42Response Object
Exception:
/* 3401 - NOT FOUND - Catalogue by the name '<catalogueName>' does not exist. 3403 - NOT FOUND - Category by the name '<categoryName>' for the Catalogue by the name '<catalogueName>' does not exist. */
String catalogueName = "CatalogueName01"; String categoryName = "CategoryName01"; App42Response response = catalogueService.removeItemsByCategory(catalogueName,categoryName); /* returns the App42Response object. */ boolean success = response.isResponseSuccess(); String jsonResponse = response.toString(); /* returns the response in JSON format. (as shown below)*/
{
"app42": {
"response": {
"success": true,
"catalogues": {
"catalogue": {
"name": "CatalogueName01",
"categories": {
"category": {
"name": "CategoryName01",
"items": {
"item": {
"itemId": "Item4",
"name": "ItemName02",
"description": "Description",
"url": "http://XXXX.jpg",
"tinyUrl": "http://tinyurl.com/XXXX",
"price": 20
}
}
}
}
}
}
}
}
}
Removes Item by Id.
Parameters:
Returns:
Response: App42Response Object
Exception:
/* 3401 - NOT FOUND - Catalogue by the name '<catalogueName>' does not exist. 3403 - NOT FOUND - Category by the name '<categoryName>' for the Catalogue by the name '<catalogueName>' does not exist. 3406 - NOT FOUND - Item with the id '<itemId>' does not exist. */
String catalogueName = "CatalogueName01"; String categoryName = "CategoryName01"; String itemId = "ItemId01"; App42Response response = catalogueService.removeItemById(catalogueName,categoryName,itemId); /* returns the App42Response object. */ boolean success = response.isResponseSuccess(); String jsonResponse = response.toString(); /* returns the response in JSON format. (as shown below)*/
{
"app42": {
"response": {
"success": true,
"catalogues": {
"catalogue": {
"name": "CatalogueName01",
"categories": {
"category": {
"name": "CategoryName01",
"items": {
"item": {
"itemId": "ItemId01",
"name": "ItemName01",
"description": "ItemDescription01",
"url": "http://XXXX.jpg",
"tinyUrl": "http://tinyurl.com/XXXX",
"price": 200
}
}
}
}
}
}
}
}
}