Search code examples
c#asp.netvisual-studio-2010

Error in updating item quantity on Amazon using API


I have read much documentation on the Amazon API and am still not clear on the error I am receiving, the documentation does not provide helpful examples.

I am using this to update my inventoy:

I have read different documents, each stating a new service url, and I am really confused about that..

config.ServiceURL = "https://mws.amazonservices.co.uk/FulfillmentInventory/2011-10-01";
config.ServiceURL = "https://secure.amazon.co.uk/exec/panama/seller-admin/catalog-upload/modify-only";

My code to start the process and send request is:

String accessKeyId = "#";
String secretAccessKey = "#";
String merchantId = "#";
String marketplaceId = "#";

MemoryStream stream = new MemoryStream();
stream = GenerateInventoryDocument(txtxSku.Text, merchantId, txtQuantity.Text);
   
const string applicationName = "C#";
const string applicationVersion = "4";

MarketplaceWebServiceConfig config = new MarketplaceWebServiceConfig();

MarketplaceWebService.MarketplaceWebService service = new MarketplaceWebServiceClient(accessKeyId, secretAccessKey, applicationName, applicationVersion, config);
MarketplaceWebService.Model.SubmitFeedResponse response = new MarketplaceWebService.Model.SubmitFeedResponse();

MarketplaceWebService.Model.SubmitFeedRequest request = new MarketplaceWebService.Model.SubmitFeedRequest();
request.Merchant = merchantId;
request.MarketplaceIdList = new MarketplaceWebService.Model.IdList();
request.MarketplaceIdList.Id = new List<string>(new string[] { marketplaceId });

request.FeedContent = stream;
request.ContentMD5 = MarketplaceWebServiceClient.CalculateContentMD5(request.FeedContent);
request.FeedContent.Position = 0;
    
request.FeedType = "_POST_INVENTORY_AVAILABILITY_DATA_";

SubmitFeedSample.InvokeSubmitFeed(service, request);

The GenerateInventoryDocument() function is :

MemoryStream myDocument = new MemoryStream();
string myString;

//Add the document header.
myString = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>";
this.AddStringToStream(ref myString, myDocument);

myString = "<AmazonEnvelope xsi:noNamespaceSchemaLocation=\"amzn-envelope.xsd\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">";
this.AddStringToStream(ref myString, myDocument);

myString = "<Header>";
this.AddStringToStream(ref myString, myDocument);

myString = "<DocumentVersion>1.01</DocumentVersion>";
this.AddStringToStream(ref myString, myDocument);

myString = "<MerchantIdentifier>" + merchantID + "</MerchantIdentifier>";
this.AddStringToStream(ref myString, myDocument);

myString = "</Header>";
this.AddStringToStream(ref myString, myDocument);

myString = "<MessageType>Inventory</MessageType>";
this.AddStringToStream(ref myString, myDocument);

myString = "<Message>";
this.AddStringToStream(ref myString, myDocument);

myString = "<MessageID>1</MessageID>";
this.AddStringToStream(ref myString, myDocument);

myString = "<OperationType>Update</OperationType>";
this.AddStringToStream(ref myString, myDocument);

myString = "<Inventory>";
this.AddStringToStream(ref myString, myDocument);

myString = "<SKU>" + sku + "</SKU>";
this.AddStringToStream(ref myString, myDocument);

myString = "<FulfillmentLatency>1</FulfillmentLatency>";
this.AddStringToStream(ref myString, myDocument);

myString = "<Quantity>" + quantity + "</Quantity>";
this.AddStringToStream(ref myString, myDocument);

myString = "</Inventory>";
this.AddStringToStream(ref myString, myDocument);

myString = "</Message>";
this.AddStringToStream(ref myString, myDocument);

myString = "</AmazonEnvelope>";
this.AddStringToStream(ref myString, myDocument);

return myDocument;

When I use this URL:

config.ServiceURL = "https://mws.amazonservices.co.uk/FulfillmentInventory/2011-10-01";

I get the following error response:

<ErrorResponse xmlns="http://mws.amazonaws.com/FulfillmentInventory/2011-10-01/"> 
    <Error>
       <Type>Sender</Type>
       <Code>NoSuchVersion</Code>
       <Message>The requested version ( 2010-01-01 ) is not valid.</Message>
       <Detail/>
    </Error>
    <RequestID>f35d1eb0-b8e7-40c0-8394-027619fb0762</RequestID>
</ErrorResponse>

And when I use this service URL that I read on another doc:

config.ServiceURL = "https://secure.amazon.co.uk/exec/panama/seller-admin/catalog-upload/modify-only";

I get the following error response:

<BusinessLogicError>CUSTOMER_UNAUTHORIZED</BusinessLogicError>

Please let me know if there is something wrong in this code, as I am totally following the documents.

These are small issues and I can't figure them out.


Solution

  • There are a few things wrong with your code. I'm assuming that you want to update inventory that you are fulfilling yourself (as opposed to FBA). I'm also assuming that you are a Pro Merchant which is required by Amazon to use any MWS APIs.

    The correct serviceUrl for the UK is https://mws.amazonservices.co.uk. The correct feedType for updating/adding inventory is _POST_FLAT_FILE_LISTINGS_DATA_. There are other feed types you can use. See the Feed Type Enumeration section of the Feeds API reference. This type of feed is a tab delimited file and you can find the template(s) here. There is also an XML type of feed but you must have the proper account to use this type of feed submission. These types of accounts are by invitation only.

    Assuming that you've downloaded the C# Feeds API you should have a look at the MarketplaceWebServiceSamples.cs file that is included in MarketplaceWebService.Samples project inside the solution. This file has a bunch of sections that have been commented out. Find the one that deals with the Submit Feed action and use it to learn how to submit a feed.

    You should spend some more time reading the Feeds API documentation especially the Feed Type Enumeration section as there are other types of feeds that you can use (tab delimited only).