Archive for March, 2009

Travel map – countries visited

Sunday, March 22nd, 2009

I’ve been looking for a good countries visited map for quite some time. There’s something satisfying about painting the world red (or in this case, orange), and something humbling about seeing massive chunks of the planet untouched. So since we’re approaching April and I’m getting the inevitable itchy feet again, I’ve gone hunting.

Up until now, World66 had seemed my only option. But in the Age of Google, posting images for this sort of thing seems a bit of a letdown. Fortunately 29travels have just the thing with their Google Map version.

Pretty cool but it’s a shame there doesn’t seem to be an option to edit the map. But, a quick look at the iframe source, and you can see it’s pretty easy to hack in any new countries as you visit. Providing you know the right country codes of course.

http://www.29travels.com/getmap.php?j=ALATBACYCZDEESFRGBHRISITMKMTMENLPLSITRUSVAVN&c=cc41c9f2&w=575&h=300

That query string is a long list of 2-digit country codes. So, if you know the code for the country you want to add, just adding it to the string will provide all the highlighting you need. For example Australia = AU

http://www.29travels.com/getmap.php?j=ALATBACYCZDEESFRGBHRISITMKMTMENLPLSITRUSVAVNAU&c=cc41c9f2&w=575&h=300

Who wants to package this up into a Wordpress plugin for me? :)

Getting document reports from Amazon Seller Central SOAP services (C#)

Sunday, March 22nd, 2009

Developing against the Amazon API becomes a lot more straightforward with being able to get at the errors with your XML documents. Validating against the XSDs is only part of the solution, but even downloading reports can be tricky. Trouble is, the documentation from Amazon is a very closed & private sort of affair – sometimes out of date and sometimes very sparse. Perhaps they should think about a wiki :)

Getting at your reports consists of two parts, firstly – use the Document ID (long) you got from posting the XML in the first place.

public DocumentProcessingInfo DocumentStatus(long DocumentID)
    {
        //Setup the service interface, set the URL of the service
        //and add our credentials.
        merchantinterfacedime myAmazon =
            new merchantinterfacedime();
        myAmazon.Url = ConfigurationManager.AppSettings["URL"];
        myAmazon.Credentials =
            new NetworkCredential(
                ConfigurationManager.AppSettings["UserName"],
                ConfigurationManager.AppSettings["Password"]);
        //Setup our merchant details.
        Merchant myMerchant = new Merchant();
        myMerchant.merchantIdentifier =
            ConfigurationManager.AppSettings["MerchantIdentifier"];
        myMerchant.merchantName =
            ConfigurationManager.AppSettings["MerchantName"];
        //Send it all off to Amazon.
        DocumentProcessingInfo myStatus =
            myAmazon.getDocumentProcessingStatus(
            myMerchant, DocumentID);
        //Return the status of the document.
        return myStatus;
    }

This will give you the status of your upload, as well as whether it’s complete or not. It also gives you another document ID, which you can use to get at your much-needed reports.

public string GetDocument(string id) {
        StringBuilder report = new StringBuilder();
        merchantinterfacedime myAmazon =
            new merchantinterfacedime();
        myAmazon.Url = ConfigurationManager.AppSettings["URL"];
        myAmazon.Credentials =
            new NetworkCredential(
                ConfigurationManager.AppSettings["UserName"],
                ConfigurationManager.AppSettings["Password"]);
        //Setup our merchant details.
        Merchant myMerchant = new Merchant();
        myMerchant.merchantIdentifier =
            ConfigurationManager.AppSettings["MerchantIdentifier"];
        myMerchant.merchantName =
            ConfigurationManager.AppSettings["MerchantName"];
        ReferencedBinary incomingDoc = new ReferencedBinary();
        // the seven-digit string is the document ID number
        myAmazon.getDocument(myMerchant, id, out incomingDoc);
        IEnumerator enumer = myAmazon.ResponseSoapContext.Attachments.GetEnumerator();
        while (enumer.MoveNext())
        {
            // Print the document to standard out
            Attachment downloadedDoc = enumer.Current as Attachment;
            StreamReader r = new StreamReader(downloadedDoc.Stream);
            report.Append(r.ReadToEnd());
        }
        return report.ToString();
}

And tying it all together:

long amazonId = #######
string report = GetDocument(DocumentStatus(amazonId).processingReport.documentID);

Your report will be in XML, and give you any validation errors that might be preventing your feed from working properly, as well as some very helpful status on the number of items processed. How did you ever live without it?