Archives page

Posts Tagged ‘amazon’

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.

[codesyntax lang=”csharp”]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;
}[/codesyntax]

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.

[codesyntax lang=”csharp”]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();
}[/codesyntax]

And tying it all together:

[codesyntax lang=”csharp”]long amazonId = #######
string report = GetDocument(DocumentStatus(amazonId).processingReport.documentID);[/codesyntax]

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?