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

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.

Code block    
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.

Code block    
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:

Code block    
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?

Tags: , , , , , , ,

7 Comments

    • Arif
    • July 30, 2009
    • Reply

    Hi Kevin,
    I liked your writing. Can you help me out a little more ?
    I need complete code to upload changes in items, and download orders etc.
    I’ll be very gr8ful if you kindly help me out.I’m so stuck and don know how to advance :S

    • Hi Arif,

      I’ll make a few more posts on the Amazon services, shortly. How have you been getting on?

    • Rolf Herbert
    • September 16, 2009
    • Reply

    Hi there,

    I’m just embarking on trying to integrate with the Amazon API using vb.net but I have to admit Im thoroughly confused! The documentation is sparse and contradictory with different information on .com to .co.uk versions which is sometimes at cross purposes. Its not even clear if this is still the preferred method of talking to Seller Central as I have seen some other newer version of an API.

    I would be very grateful if you could post some more of your experiences and code, Im looking to upload inventory and dispatch files and download order files.

    Thanks
    Rolf

    • Hi Rolf,

      Seems like your experiences have been very similar to mine. I had a lot of trial an error, emails to our account manager on the Amazon side, and mixing / matching samples from around the web to get where I could successfully upload. I’ll get a post up shortly about uploading inventory items – although I didn’t write anything for dispatch or order files. We found a third-party solution that integrated with the existing order management software for that.

    • Behrad Moeinzadeh
    • May 10, 2010
    • Reply

    Hi Kevin,

    thanks a lot for this post, I do not know how would I figure this out without this post, I tried Amazon documents for few days and did not find anything.

    I have just started working with Amazon API and using your post I am able to get the orders.

    Thanks again,

    Behrad.

    • I’m glad to hear it was useful – thanks for the feedback! ๐Ÿ™‚

  1. Hi Guys,
    I’m going now through the same hassle like everyone here, I was assigned to integrate with Amazon Order API in C#, using a web form. I did read the whole documentation provided by amazon but I’m just confused. Basically I need first to retrieve all orders from amazon and display them in a Order Gridview, and then by clicking on any order, I have to be able to show the order detail in a second Gridview. If someone can help me, I will be more than thankful, please I need an urgent help.

    Thanks a lot

Leave a Reply?