diff --git a/README.md b/README.md index 509b4791..2ad16bc9 100644 --- a/README.md +++ b/README.md @@ -473,6 +473,64 @@ var processingReport = amazonConnection.Feed.GetFeedDocumentProcessingReport(out ``` +#### JSON_LISTINGS_FEED Submit for change price +```CSharp +string sellerId = "SellerId"; +string sku = "SKU"; +decimal price = 19.99m; + +string jsonString = $@" +{{ + ""header"": {{ + ""sellerId"": ""{sellerId}"", + ""version"": ""2.0"", + ""issueLocale"": ""en_US"" + }}, + ""messages"": [ + {{ + ""messageId"": 1, + ""sku"": ""{sku}"", + ""operationType"": ""PATCH"", + ""productType"": ""PRODUCT"", + ""patches"": [ + {{ + ""op"": ""replace"", + ""path"": ""/attributes/purchasable_offer"", + ""value"": [ + {{ + ""currency"": ""USD"", + ""our_price"": [ + {{ + ""schedule"": [ + {{ + ""value_with_tax"": {price} + }} + ] + }} + ] + }} + ] + }} + ] + }} + ] +}}"; + +string feedID = await amazonConnection.Feed.SubmitFeedAsync(jsonString, FeedType.JSON_LISTINGS_FEED, new List() { MarketPlace.UnitedArabEmirates.ID }, null, ContentType.JSON); + +Thread.Sleep(1000*60); + +var feedOutput = amazonConnection.Feed.GetFeed(feedID); + +var outPut = amazonConnection.Feed.GetFeedDocument(feedOutput.ResultFeedDocumentId); + +var reportOutpit = outPut.Url; + +var processingReport = await amazonConnection.Feed.GetJsonFeedDocumentProcessingReportAsync(output); + +``` + + #### Feed Submit for change Quantity ```CSharp ConstructFeedService createDocument = new ConstructFeedService("{SellerID}", "1.02"); diff --git a/Source/FikaAmazonAPI.SampleCode/FeedsSample.cs b/Source/FikaAmazonAPI.SampleCode/FeedsSample.cs index ce37a18a..94e8dc22 100644 --- a/Source/FikaAmazonAPI.SampleCode/FeedsSample.cs +++ b/Source/FikaAmazonAPI.SampleCode/FeedsSample.cs @@ -215,6 +215,50 @@ public async Task SubmitFeedPricingWithSalePrice(string sku, decimal price, deci GetFeedDetails(feedId); } + public async Task SubmitJsonFeedPricing(string sellerId, string sku, decimal price) + { + string jsonString = $@" + {{ + ""header"": {{ + ""sellerId"": ""{sellerId}"", + ""version"": ""2.0"", + ""issueLocale"": ""en_US"" + }}, + ""messages"": [ + {{ + ""messageId"": 1, + ""sku"": ""{sku}"", + ""operationType"": ""PATCH"", + ""productType"": ""PRODUCT"", + ""patches"": [ + {{ + ""op"": ""replace"", + ""path"": ""/attributes/purchasable_offer"", + ""value"": [ + {{ + ""currency"": ""USD"", + ""our_price"": [ + {{ + ""schedule"": [ + {{ + ""value_with_tax"": {price} + }} + ] + }} + ] + }} + ] + }} + ] + }} + ] + }}"; + + string feedID = await amazonConnection.Feed.SubmitFeedAsync(jsonString, FeedType.JSON_LISTINGS_FEED, new List() { MarketPlace.UnitedArabEmirates.ID }, null, ContentType.JSON); + + await GetJsonFeedDetails(feedID); + } + public void SubmitFeedSale(double PRICE, string SKU) { @@ -423,6 +467,33 @@ public void GetFeedDetails(string feedID) else Thread.Sleep(10000); } } + + private async Task GetJsonFeedDetails(string feedID) + { + string resultFeedDocumentId = string.Empty; + string reportResult = string.Empty; + while (string.IsNullOrEmpty(resultFeedDocumentId)) + { + Feed feedOutput = amazonConnection.Feed.GetFeed(feedID); + if (feedOutput.ProcessingStatus == Feed.ProcessingStatusEnum.DONE) + { + FeedDocument output = amazonConnection.Feed.GetFeedDocument(feedOutput.ResultFeedDocumentId); + reportResult = await amazonConnection.Feed.GetJsonFeedDocumentProcessingReportAsync(output); + Console.WriteLine(reportResult); + } + + if (!(feedOutput.ProcessingStatus == Feed.ProcessingStatusEnum.INPROGRESS || + feedOutput.ProcessingStatus == Feed.ProcessingStatusEnum.INQUEUE)) + { + break; + } + else + { + Thread.Sleep(1000); + } + } + } + private void DisplayProcessingReportMessage(ProcessingReportMessage processingReport) { Console.WriteLine("MessagesProcessed=" + processingReport.ProcessingSummary.MessagesProcessed); diff --git a/Source/FikaAmazonAPI/Services/FeedService.cs b/Source/FikaAmazonAPI/Services/FeedService.cs index f2a87a42..59bcd8cf 100644 --- a/Source/FikaAmazonAPI/Services/FeedService.cs +++ b/Source/FikaAmazonAPI/Services/FeedService.cs @@ -8,6 +8,7 @@ using System.Collections.Generic; using System.ComponentModel; using System.IO; +using System.IO.Compression; using System.Net; using System.Threading; using System.Threading.Tasks; @@ -180,6 +181,27 @@ public async Task GetFeedDocumentProcessingReportAsync( return processingReport; } + public async Task GetJsonFeedDocumentProcessingReportAsync(FeedDocument feedDocument, CancellationToken cancellationToken = default(CancellationToken)) + { + try + { + Stream stream = await GetStreamFromUrlAsync(feedDocument.Url, cancellationToken); + if (feedDocument.CompressionAlgorithm.HasValue && feedDocument.CompressionAlgorithm.Value == FeedDocument.CompressionAlgorithmEnum.GZIP) + { + stream = new GZipStream(stream, CompressionMode.Decompress); + } + + using var reader = new StreamReader(stream); + string jsonContent = await reader.ReadToEndAsync(); + + return jsonContent; + } + catch (AmazonProcessingReportDeserializeException) + { + throw; + } + } + public CreateFeedDocumentResult CreateFeedDocument(ContentType contentType) => Task.Run(() => CreateFeedDocumentAsync(contentType)).ConfigureAwait(false).GetAwaiter().GetResult();