Skip to content

Commit

Permalink
Merge pull request #782 from huntmj01/JSON_LISTINGS_FEED
Browse files Browse the repository at this point in the history
Add method to process JSON_LISTINGS_FEEDS result
  • Loading branch information
abuzuhri authored Oct 18, 2024
2 parents 54c5066 + cc992d0 commit 891689b
Show file tree
Hide file tree
Showing 3 changed files with 151 additions and 0 deletions.
58 changes: 58 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>() { 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");
Expand Down
71 changes: 71 additions & 0 deletions Source/FikaAmazonAPI.SampleCode/FeedsSample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>() { MarketPlace.UnitedArabEmirates.ID }, null, ContentType.JSON);

await GetJsonFeedDetails(feedID);
}


public void SubmitFeedSale(double PRICE, string SKU)
{
Expand Down Expand Up @@ -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);
Expand Down
22 changes: 22 additions & 0 deletions Source/FikaAmazonAPI/Services/FeedService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -180,6 +181,27 @@ public async Task<ProcessingReportMessage> GetFeedDocumentProcessingReportAsync(
return processingReport;
}

public async Task<string> 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();

Expand Down

0 comments on commit 891689b

Please sign in to comment.