Introduction
In this tutorial, we will learn about updating the price for a product on Amazon using the Feeds API in C#. Amazon allows us to upload inventory and order data using the Feeds API. The Feeds API provided by Amazon is very easy to use as we have to upload the XML file in the Feed and proper FeedType for the action we have to do.
Prerequisites
- Knowledge of C#
- You must have Amazon credentials like SellerId, Access Key, etc.
We should have DLL files should be installed using the Nuget package manager.
Now let’s get started…
First, create a view model for the repricer.
- public class AmazonRepricerViewModel
- {
- public string Sku { get; set; }
- public decimal Price { get; set; }
- public bool isLive { get; set; }
- }
Now create a method as RepriceParticularAmazonProducts() or name it as you like.
As you can see we have created a CustomErrorRepricer method for catching the exception if it occurs while creating the folder.
- public static void CustomErrorRepricer(string message)
- {
- string lines = "Error occured at " + DateTime.Now.ToString("MM/dd/yyyy h:mm tt") + "\r\n";
- lines += "****************************************************************** \r\n";
- lines += "ErrorMessage: " + message + " \r\n";
- string path = AppDomain.CurrentDomain.BaseDirectory + "\\RepricerLogs\\Error Logs";
- if (!Directory.Exists(path))
- {
- Directory.CreateDirectory(path);
- }
- string filePath = AppDomain.CurrentDomain.BaseDirectory + "\\Reports\\Logs\\" + "ReportLog_" + DateTime.Now.Date.ToShortDateString().Replace('/', '_') + ".txt";
- if (!System.IO.File.Exists(filePath))
- {
- using (StreamWriter sw = System.IO.File.CreateText(filePath))
- {
- sw.WriteLine(lines);
- }
- }
- else
- {
- using (StreamWriter sw = System.IO.File.AppendText(filePath))
- {
- sw.WriteLine(lines);
- }
- }
- }
Now that we have successfully created the XML file for the product, we have to update the price on Amazon. And we have got the path for the file in a path2 variable.
Now the function which will actually perform the operation for the updated price on Amazon:
- public string AmazonPriceUpdate(string Path)
- {
- SubmitFeedRequest feedRequest = new SubmitFeedRequest();
- feedRequest.Merchant = _accountId;
- feedRequest.FeedContent = File.Open(Path, FileMode.Open, FileAccess.Read);
- feedRequest.ContentMD5 = MarketplaceWebServiceClient.CalculateContentMD5(feedRequest.FeedContent);
- MarketplaceWebServiceConfig config = new MarketplaceWebServiceConfig();
- config.ServiceURL = _domain;
- config.SetUserAgentHeader(_appName, _version, "C Sharp");
- feedRequest.FeedContent.Position = 0;
- feedRequest.FeedType = "_POST_PRODUCT_PRICING_DATA_";
- MarketplaceWebServiceClient client = new MarketplaceWebServiceClient(_accessKey, _secretKey, config);
- SubmitFeedResponse feedResponse = client.SubmitFeed(feedRequest);
- FeedSubmissionInfo feedInfo = feedResponse.SubmitFeedResult.FeedSubmissionInfo;
- return feedInfo.FeedSubmissionId;
- }
The SubmitFeedRequest is used while making the API call as we have previously discussed.
When the call is a success we will get the FeedSubmissionId from it and we can check the result on Amazon Scratchpad by submitting the GetFeedSubmissionResult request from the Scratchpad and passing the Feed number as we got from the previous method.
You can also refer the Blog for updating the quantity for product using Amazon MWS API
here.
Please give your valuable feedback/comments/questions about this
article. Please let me know how you like and understand this article and
how I could improve it.