I’m in the process of building an application which requires strong integration with the Amazon API. I needed to submit product feeds, update inventory and prices, as well as downloading reports and couple other things. When I first was given the project, of course the first I did was a quick google search to see what kind of documentation is out there on the API. There was some info out there (links below), but I had to do a lot playing around first with bits of google searches to get what I needed.
In hopes of making this easier for other Amazon API developers, I’ll outline the basic process for a feed submission and some methods that I’ve ended up integrating into my application using the Amazon Feeds API.
Here’s a few FeedTypes I’ve used.
- _POST_INVENTORY_AVAILABILITY_DATA_ – update inventory.
- _POST_PRODUCT_PRICING_DATA_ – update pricing.
- _POST_PRODUCT_DATA_ – add products to listing.
- _POST_PRODUCT_OVERRIDES_DATA_ – override info, such as shipping costs.
To get started, you’ll need your Amazon MarketPlaceId, Merchant, Access Key and Secret Access Key, and of course the actual Feeds API.
Note, in the examples posted below, there’s a method called GetClient() which is used. It returns a MarketplaceWebserviceClient object. Looks like this:
private MarketplaceWebServiceClient GetClient() { MarketplaceWebServiceConfig mwsConfig = new MarketplaceWebServiceConfig(); mwsConfig.ServiceURL = "https://mws.amazonservices.com"; mwsConfig.SetUserAgentHeader("YourCompany", "1.0", "C#", new string[] { }); return new MarketplaceWebServiceClient(AccessKey, SecretAccessKey, mwsConfig); }
I’ve created a generic method to submit all feeds, which goes like this:
public SubmitFeedResult SubmitFeed(FileInfo file, FeedType feedType) { SubmitFeedResponse response = new SubmitFeedResponse(); SubmitFeedRequest sfrequest = new SubmitFeedRequest(); sfrequest.Merchant = Merchant; sfrequest.MarketplaceIdList = MarketPlaceID; using (FileStream stream = new FileStream(file.FullName, FileMode.Open, FileAccess.ReadWrite)) { sfrequest.FeedContent = stream; sfrequest.ContentMD5 = MarketplaceWebServiceClient.CalculateContentMD5(sfrequest.FeedContent); sfrequest.FeedContent.Position = 0; sfrequest.FeedType = feedType.ToString(); response = GetClient().SubmitFeed(sfrequest); } return response.SubmitFeedResult; }
I pass in the file which contains the XML to submit, along with an FeedType enum I’ve declared, which contains my FeedTypes listed above.
Once you submit a feed, you’d want to see the status. Did it go through, were there any errors/warnings etc.
There’s a FeedSubmissionInfo object that returns info for a specific submission. I use this method to return a list of feed submissions.
public List<FeedSubmissionInfo> GetFeedSubmissionList() { GetFeedSubmissionListRequest request = new GetFeedSubmissionListRequest(); request.Merchant = Merchant; GetFeedSubmissionListResponse response = GetClient().GetFeedSubmissionList(request); return response.GetFeedSubmissionListResult.FeedSubmissionInfo; }
You can now get one FeedSubmissionID from one of the FeedSubmissionInfo objects returned, and pass it in to the following method, which will create and return a FileInfo containing the response. You can further modify this to parse out the XML and reformat the text so it’s readable. Change the path to your preferred location for the file to be created to.
public FileInfo GetFeedSubmissionResultFile(string feedSubmissionID) { GetFeedSubmissionResultRequest request = new GetFeedSubmissionResultRequest(); request.FeedSubmissionId = feedSubmissionID; request.Merchant = Merchant; GetFeedSubmissionResultResponse response; string path = HttpContext.Current.Server.MapPath("~/Files/SubmissionResult-" + feedSubmissionID + ".txt); using (FileStream stream = new FileStream(path, FileMode.OpenOrCreate, FileAccess.ReadWrite)) { request.FeedSubmissionResult = stream; response = GetClient().GetFeedSubmissionResult(request); } return new FileInfo(path); }
That’s the basic process of a feed submission using the Amazon Feed API. You can do plenty more with the Amazon APIs, like managing orders, prices, inventory, and shipping.
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· [AI/GPT/综述] AI Agent的设计模式综述