asp.net 使用API更新Amazon上的商品数量时出错

cgh8pdjw  于 2023-02-26  发布在  .NET
关注(0)|答案(1)|浏览(130)

我已经阅读了很多关于Amazon API的文档,仍然不清楚我收到的错误,文档没有提供有帮助的示例。
我正在使用此更新我的inventoy:
我读过不同的文档,每个文档都说明了一个新的服务URL,我对此真的很困惑。

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";

我的代码来启动进程和发送请求是:

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);

GenerateInventoryDocument()函数为:

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;

当我使用此URL时:

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

我收到以下错误响应:

<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>

当我使用这个服务URL时,我在另一个文档中读到:

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

我收到以下错误响应:

<BusinessLogicError>CUSTOMER_UNAUTHORIZED</BusinessLogicError>

请让我知道,如果有什么错误的代码,因为我完全按照文件。
这些都是些小问题,我想不通。

c0vxltue

c0vxltue1#

你的代码有一些错误。我假设你想更新库存,你正在履行自己(而不是FBA)。我还假设你是一个专业商家,这是亚马逊要求使用任何MWS API。
适用于英国的正确serviceUrlhttps://mws.amazonservices.co.uk。适用于更新/添加库存的正确feedType_POST_FLAT_FILE_LISTINGS_DATA_。您还可以使用其他源类型。请参阅Feeds API reference的“源类型枚举”部分。此源类型是制表符分隔的文件,您可以找到模板(s)here。也有XML类型的提要,但您必须有正确的帐户才能使用此类型的提要提交。这些类型的帐户只能通过邀请。
假设你已经下载了C# Feeds API,你应该看一下MarketplaceWebServiceSamples.cs文件,它包含在MarketplaceWebServiceSamples.cs项目中。这个文件有很多部分已经被注解掉了。找到一个处理Submit Feed动作的文件,用它来学习如何提交feed。
您应该花更多的时间阅读Feeds API documentation,尤其是Feed Type Enumeration部分,因为还有其他类型的提要可以使用(仅限制表符分隔)。

相关问题