Friday, July 30, 2010

Amazon - Product Advertising API

A few things to keep in mind while using Amazon Services for a typical data synchronization case are as follow:

  1. You must know the exact nature of services offered by Amazon. Also know about the seller central api’s for add/edit/delete inventory on amazon as well as idea of which service to use for downward synchronization.

  2. You must have an idea of what does it mean by
    Amazon Fulfillment API,
    Amazon Product Advertising API,
    Amazon e-Commerce Services,
    Amazon Associates Web Service
    and never get confused with several services offered by amazon including its cloud computing and storage services.

  3. My typical seller's listing solution was Found in Product Advertising API and started experimenting its BrowseNodes first which got successful and I got a number of nodes with default seller: Amazon.

  4. easiest way to find out sellerid is to access the path: http://www.amazon.com/seller/[YourShopName] as soon as you hit this, amazon will take you to a page with shop’s info: look for the url now. url will have a sellerid for sure provided by amazon in the url to access right shop.

  5. Be aware of locale: you must be very sure which international amazon website hold the products of your shop. If you are accessing amazon.com for your uk based shop, you are on way to endless fatigue.

  6. knowing the correct API procedure to call. Know what exactly you require and what are the meaning for several required & optional parameters of API Request calls. Start with only minimal required parameters and build correct signatures to be sent with the request.

  7. Must know the ResponseGroups and Search Indices. Correct RG will ease your life in getting exact data from amazon.

  8. Know the error messages returned by amazon and try solutions to them. Normally they can be logical and require a little attention towards right combination of request parameters. Again knowing the exact nature & combination of request parameters of any call is must.

  9. Last but not least: Know your response XML. You must understand the XML structure for sure. If you can get a parser for xml returned by amazon, well & good. Otherwise you must be very good at logic and parse the xml on you own writing some class for it.

A good solution must post proper-correct request parameter and will be handling the response to transform it correctly to your desired form i.e. database, csv etc. Hourly, Daily or Weekly synchronization must be accomplished with appropriate request parameters to get updated/latest data only thus improving the communication time.

Thursday, January 21, 2010

Types of Mobile Website: Mobile Web Applications with PHP & .Net

There are two types of Mobile Websites:

1. Built for Symbian and other Mobiles OS (Nokia/Sony Ericson/Motorolla or any other) they are not rich in Graphics and they mostly have textual information with few images. Please see examples at this website for these mobile websites which run in any mobile: http://winksite.com. Please click on any icon in the bottom to see website in nokia simulator. We are developing this version of mobile website for one of our client .

2. Second type of mobile website is built for IPhones. Please visit http://mobify.me/gallery/wd/ for few examples. They are XHTML Based websites
?xml version="1.0" encoding="UTF-8"?>
!DOCTYPE html PUBLIC "
//WAPFORUM//DTD XHTML Mobile 1.2 //EN"
"http://www.openmobilealliance.org/tech/DTD/xhtml-mobile12.dtd"

which have rich graphics which are normally visible to only IPhones and their graphics are not visible in normal mobiles.

Although you can create the dynamic html on your own but a better experience would be to use some library that generates code for you with PHP or .Net. An Available Good Library For Generating Code is HAWHAW:

This library can be used with php or .net and it create wap code

http://Hawhaw.de

with the help of this library, We were able to create wap output of our choice which otherwise seems to have no help on html effects for wap and many other html attributes. Now you just have to create one object of page, form or any html element and nest/place them accordingly. This library not only generate code for symbian browsers but also create XHTML output for IPhones.

Emulators

When we talk about working with such limited functionality websites, we certainly needs simulators as well which output like real mobile. You can use Microsoft Mobile Explorer 3.0 Emulator for this purpose.

If you working for IPhone's rich graphics web application, I would advise you to use this simulator: MobiOne (http://www.genuitec.com/mobile/download.html). This is IPhone and Palm Pre emulator and has just updated to the Milestone 6 version, which includes a new drag-n-drop mobile Web visual designer for mockups, updated OSS components, screen capture, multi-touch and gesture support and improved PhoneGap support for hybrid applications!

I hope all this information will help you getting quick start your mobile application today. Feel free to ask me any question regarding Mobile web applications and custom IPhone Application Development. I could be reached at Analyst.Net@gmail.com

Monday, November 16, 2009

Amazon Seller Central API Integration with Shopping Cart

We had a task with a German client Integrate her online shop with Amazon API so she can update inventory of her two websites on Amazon through Amazon API, which took three days with sleepless nights but at last we succeeded Integrating OSCommerce & XTCommerce shopping carts with Amazon Seller Central API. It took a lot of our time in reading development API manuals, forums and articles on internet but of no use. Most of the people were found complaining of insufficient help material and non-availability of example source code in many development languages in practice today.

Each step moving forward working on it, you will find a new way of doing it and you will simply be revolving around in the dark amazon. Sending request to amazon through SOAP attachment having xml data of all the products to be updated, or using the API URLs to send flat file attachment to. You will just mess up everything.

First of all, I would like to share my experience with SOAP attachments with Action for amazon defined in XML as _POST_INVENTORY_AVAILABILITY_DATA_ (and others using Posting Data guidlines)

$messageType = '_POST_INVENTORY_AVAILABILITY_DATA_';
$document = 'http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="amzn-envelope.xsd">1.01' . $merchantid . '
Inventory';
//loop through quantity
$document .='
1
Update
10009334
25
';
$document .='';

Then submit the above Document string to thie following function which will send it to appropriate amazon url:

postDocument($messageType, $document)

function postDocument($messageType, $document) {
$this->error = null;
// create the attachment to add to the SOAP call
$attachment = new SOAP_Attachment('doc', 'application/binary', null, $document);
$attachment->options['attachment']['encoding'] = '8bit';
$params = array('merchant' => $this->merchant,
'messageType' => $messageType,
'doc' => $attachment);
$options = array('trace' => true, 'timeout' => '10', 'attachments' => 'Mime');
$result = $this->client->call('postDocument', $params, $options);
if(PEAR::isError($result)) {
echo $this->error = "Error: " . $result->getMessage();
return false;
}
return $result;
}

And what you get at last is an error in all the ways you do it:
Error: Unable to retrieve WSDL https://merchant-api.amazon.de/gateway/merchant-interface-mime,

If you access this url directly, It will prompt for seller central user id and password but it complained that wsdl cannot be found even I tried saving this wsdl to local directory …
Then on the second attempt we tried Amazon AIM Document and used URL based amazon functions which works with tab delimited file formats. At first, we tried sending the simplest Price/Quantity Update flat file through CURL as attachment and spends whole day find solution to this particular error:

Feed Processing Summary:
Number of records processed 0
Number of records successful 0
original-record-number sku error-code error-type error-message
0 6000 Error Column "sku" is missing and is required.
0 6000 Warning The following columns are not recognized and will be ignored:

WoAH !!! SKU is present in the file and it is still complaining its missing? Oh man!!! Curl is not sending the flt file as attachment. After realizing this we login to the seller central account and uploaded the same file for Price/Quantity Updated … Oh Its Working.

Finally!

$user = '';
$pass = '';
$id = ''; // Merchant ID
$name = ''; // Merchant store name
$authentication = base64_encode($user . ":" . $pass);
$itemsFeedURL = "https://secure.amazon.de/exec/panama/seller-admin/catalog-upload/add-modify-delete";
// TAKE BATCH FILE PATH WHICH INCLUDE RECORDS TO BE UPDATED
$root = "http://".$_SERVER['HTTP_HOST'];
$root .= str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']);
$file = $root."PriceInventory.txt";
$authentication = base64_encode($user . ":" . $pass);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $itemsFeedURL);
curl_setopt($ch, CURLOPT_PUT, true);
curl_setopt($ch, CURLOPT_INFILE, $file);
curl_setopt($ch, CURLOPT_INFILESIZE, strlen($file_string));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_FAILONERROR, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Authorization: Basic ' . $authentication ,
'Content-Type: text/xml;charset=UTF-8',
'BatchID: Y'
));
echo $result = curl_exec($ch);
curl_close($ch);

So you can populate your products quantity/Price against their SKU from any shopping cart DB in an inventory batch file template (get it from your Seller Central Account Products Update Area), attach it wil Curl Request and submit to amazon API.

The API do not promise to do it for you instantly, so you have to wait for a few minutes to see the results of this batch file. I have mentioned ‘BatchID:Y’ in Curl header request, which means API will return your BatchID being processed, you can view status of this BatchID in a separate request or you can login Seller Central Account to see the result of Your file Batches being processed.


Wednesday, November 11, 2009

Consuming Amazon API Web Services to enhance your website

Now everybody heard of Amazon.com. What not everybody knows that Amazon released an API to access its huge catalogs. What this basically means is that each developer can access the information from Amazon following some simple protocols and every site owner can enhance his own website with content and features from Amazon.

The Amazon API comes as a simple Webservice. Here are the first Web services that they have exposed:
  • Product Display : The ability to search for and retrieve product information from the Amazon.com catalog.
  • Shopping Cart : The ability to add Amazon.com products to shopping carts, wish lists, and registries from third party locations.

No matter of your intentions, you will first need to register and obtain a valid developer token. You can get your token here at this address: http://www.amazon.com/webservices

The current listed implementation of Amazon webservices uses Keyword searches. It has basically the same results as searching the books catalog online. As any developer/webmaster can see in the "Amazon.com Web Services Developers Kit v 1.0" document, a lot of other Amazon features are exposed. This would imply extending the base structure I present here.

There are multiple approaches from a developer's point of view. The simplest one deals with SOAP and web services classes already implemented in PHP. You could also extend the PEAR's XMLParser object to parse Amazon results. The reason I did not choose these directions is because they require additional extensions installed with PHP. What I currently use is the XML parsing package that comes embedded in PHP, so it is slightly more general.

What basically happens in this implementation is that the search word entered by the used is embedded into a XML url that is then retrieved from Amazon.com. Then PHP builds a nice display for the information received.

A class collection in the extensive package provided by Manuel Lemos:
http://www.phpclasses.org/browse.html/package/642.html