gpt4 book ai didi

c# - 使用 API 在亚马逊上更新商品数量时出错

转载 作者:太空狗 更新时间:2023-10-30 01:24:39 25 4
gpt4 key购买 nike

我已经阅读了很多关于 Amazon API 的文档,但仍然不清楚我收到的错误,文档没有提供有用的示例。

我正在使用它来更新我的库存:

我阅读了不同的文档,每个文档都说明了一个新的服务 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>

请让我知道这段代码是否有问题,因为我完全按照文档进行操作,这已经是我花在这上面的第 3 天了。也许我疯了:D

这些都是小问题,我想不通。

最佳答案

您的代码有一些问题。我假设您想更新您自己完成的库存(而不是 FBA )。我还假设您是亚马逊要求使用任何 MWS API 的 Pro Merchant。

英国的正确 serviceUrlhttps://mws.amazonservices.co.uk。更新/添加库存的正确 feedType_POST_FLAT_FILE_LISTINGS_DATA_。您还可以使用其他提要类型。请参阅 Feeds API reference 的 Feed Type Enumeration 部分。这种类型的提要是制表符分隔的文件,您可以找到模板 here 。还有一种 XML 类型的提要,但您必须拥有适当的帐户才能使用这种类型的提要提交。这些类型的帐户仅限受邀者。

假设您已经下载了 C# Feeds API,您应该查看解决方案内的 MarketplaceWebService.Samples 项目中包含的 MarketplaceWebServiceSamples.cs 文件。该文件有一堆已被注释掉的部分。找到处理 Submit Feed 操作的那个,并用它来学习如何提交 Feed。

您应该花更多时间阅读 Feeds API documentation,尤其是 Feed Type Enumeration 部分,因为您可以使用其他类型的 feed(仅限制表符分隔)。

关于c# - 使用 API 在亚马逊上更新商品数量时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8752759/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com