Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

start migration XML to JSON feed #820

Merged
merged 1 commit into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 53 additions & 7 deletions Source/FikaAmazonAPI.SampleCode/FeedsSample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public void AddOfferMessageMessage()
GetFeedDetails(feedID);
}

public void SubmitFeedPRICING(double PRICE, string SKU)
public void SubmitFeedPRICING(decimal PRICE, string SKU)
{

ConstructFeedService createDocument = new ConstructFeedService(amazonConnection.GetCurrentSellerID, "1.02");
Expand All @@ -167,7 +167,7 @@ public void SubmitFeedPRICING(double PRICE, string SKU)
StandardPrice = new StandardPrice()
{
currency = amazonConnection.GetCurrentMarketplace.CurrencyCode.ToString(),
Value = (PRICE).ToString("0.00")
Value = decimal.Round(PRICE, 2)
}
});
createDocument.AddPriceMessage(list);
Expand All @@ -180,6 +180,52 @@ public void SubmitFeedPRICING(double PRICE, string SKU)

}

public async Task SubmitFeedPRICING_JSONAsync(string SKU, decimal PRICE, decimal? minPrice = null, decimal? maxPrice = null)
{
ConstructJSONFeedService createDocument = new ConstructJSONFeedService(amazonConnection.GetCurrentSellerID);

var list = new List<PriceMessage>();
var msg = new PriceMessage()
{
SKU = SKU,
StandardPrice = new StandardPrice()
{
currency = amazonConnection.GetCurrentMarketplace.CurrencyCode.ToString(),
Value = decimal.Round(PRICE, 2)
}
};

if (maxPrice != null)
{
msg.MaximumSellerAllowedPrice = new StandardPrice()
{
currency = amazonConnection.GetCurrentMarketplace.CurrencyCode.ToString(),
Value = decimal.Round(maxPrice.Value, 2)
};
}

if (minPrice != null)
{
msg.MinimumSellerAllowedPrice = new StandardPrice()
{
currency = amazonConnection.GetCurrentMarketplace.CurrencyCode.ToString(),
Value = decimal.Round(minPrice.Value, 2)
};
}


list.Add(msg);
createDocument.AddPriceMessage(list);

var jsonString = createDocument.GetJSON();

string feedID = await amazonConnection.Feed.SubmitFeedAsync(jsonString, FeedType.JSON_LISTINGS_FEED, null, null, ContentType.JSON);


await GetJsonFeedDetails(feedID);

}

public async Task SubmitFeedPricingWithSalePrice(string sku, decimal price, decimal salePrice, DateTime startDate, DateTime endDate)
{
var currencyCode = amazonConnection.GetCurrentMarketplace.CurrencyCode.ToString();
Expand All @@ -193,14 +239,14 @@ public async Task SubmitFeedPricingWithSalePrice(string sku, decimal price, deci
StandardPrice = new StandardPrice
{
currency = currencyCode,
Value = price.ToString("0.00")
Value = decimal.Round(price, 2)
},
Sale = new Sale
{
SalePrice = new StandardPrice
{
currency = currencyCode,
Value = salePrice.ToString("0.00")
Value = decimal.Round(salePrice, 2)
},
StartDate = startDate.ToUniversalTime().ToString("yyyy-MM-dd'T'HH:mm:ss.fffK"),
EndDate = endDate.ToUniversalTime().ToString("yyyy-MM-dd'T'HH:mm:ss.fffK")
Expand Down Expand Up @@ -260,7 +306,7 @@ public async Task SubmitJsonFeedPricing(string sku, decimal price)
}


public void SubmitFeedSale(double PRICE, string SKU)
public void SubmitFeedSale(decimal PRICE, string SKU)
{

ConstructFeedService createDocument = new ConstructFeedService("A3J37AJU4O9RHK", "1.02");
Expand All @@ -272,7 +318,7 @@ public void SubmitFeedSale(double PRICE, string SKU)
StandardPrice = new StandardPrice()
{
currency = amazonConnection.GetCurrentMarketplace.CurrencyCode.ToString(),
Value = (PRICE).ToString("0.00")
Value = decimal.Round(PRICE, 2) //(PRICE).ToString("0.00")
},
Sale = new Sale()
{
Expand All @@ -281,7 +327,7 @@ public void SubmitFeedSale(double PRICE, string SKU)
SalePrice = new StandardPrice()
{
currency = amazonConnection.GetCurrentMarketplace.CurrencyCode.ToString(),
Value = (PRICE - 10).ToString("0.00")
Value = decimal.Round(PRICE, 2) - 10
}
}
});
Expand Down
10 changes: 2 additions & 8 deletions Source/FikaAmazonAPI.SampleCode/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,9 @@ static async Task Main(string[] args)
IsDebugMode = true
}, loggerFactory: factory);

FeedsSample feedsSample = new FeedsSample(amazonConnection);
feedsSample.SubmitFeedPRICING_JSONAsync("B087YHP3HQ.151", 131.77M, 67.70M, 131.77M);

ReportManagerSample reportManagerSample = new ReportManagerSample(amazonConnection);
reportManagerSample.CallReport();
//var error = amazonConnection.Reports.CreateReportAndDownloadFile(Utils.Constants.ReportTypes.GET_STRANDED_INVENTORY_UI_DATA);
//var dddd = amazonConnection.Reports.CreateReportAndDownloadFile(Utils.Constants.ReportTypes.GET_FBA_MYI_ALL_INVENTORY_DATA);
//var dddd = amazonConnection.Reports.CreateReportAndDownloadFile(Utils.Constants.ReportTypes.GET_FBA_MYI_UNSUPPRESSED_INVENTORY_DATA);
//ReportManager reportManager = new ReportManager(amazonConnection);

//var dddddd = reportManager.GetAFNInventoryQtyAsync().ConfigureAwait(false).GetAwaiter().GetResult();

Console.ReadLine();

Expand Down
83 changes: 83 additions & 0 deletions Source/FikaAmazonAPI/ConstructFeed/ConstructJSONFeedService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
using FikaAmazonAPI.ConstructFeed.JsonMessages;
using FikaAmazonAPI.ConstructFeed.Messages;
using Newtonsoft.Json;
using System.Collections.Generic;

namespace FikaAmazonAPI.ConstructFeed
{
public class ConstructJSONFeedService
{
JsonMessagesData jsonMessagesData = new JsonMessagesData();
public ConstructJSONFeedService(string sellerId, string version = "2.0", string issueLocale = "en_US")
{
jsonMessagesData.header = new HeaderData()
{
issueLocale = issueLocale,
sellerId = sellerId,
version = version
};

}


public void AddPriceMessage(IList<PriceMessage> messages)
{
int index = jsonMessagesData.messages.Count;
foreach (var itm in messages)
{
var patcheValueData = new PatcheValueData()
{
currency = itm.StandardPrice.currency,
our_price = new List<PriceData>()
{
new PriceData(){ schedule = new List<SchedulePriceData>(){ new SchedulePriceData() { value_with_tax= itm.StandardPrice.Value } } }
},
};

if (itm.MinimumSellerAllowedPrice != null)
{
patcheValueData.minimum_seller_allowed_price = new List<PriceData>()
{
new PriceData(){ schedule = new List<SchedulePriceData>(){ new SchedulePriceData() { value_with_tax= itm.MinimumSellerAllowedPrice.Value } } }
};
}

if (itm.MaximumSellerAllowedPrice != null)
{
patcheValueData.maximum_seller_allowed_price = new List<PriceData>()
{
new PriceData(){ schedule = new List<SchedulePriceData>(){ new SchedulePriceData() { value_with_tax= itm.MaximumSellerAllowedPrice.Value } } }
};
}

var msg = new MessagesData()
{
messageId = ++index,
sku = itm.SKU,
operationType = "PATCH",
productType = "PRODUCT",
patches = new List<PatcheData>{
new PatcheData()
{
op = "replace",
path = "/attributes/purchasable_offer",
value =new List<PatcheValueData>{ patcheValueData }
}
}
};

jsonMessagesData.messages.Add(msg);
}
}

public string GetJSON()
{
string jsonString = JsonConvert.SerializeObject(jsonMessagesData, Formatting.Indented, new JsonSerializerSettings
{
NullValueHandling = NullValueHandling.Ignore
});

return jsonString;
}
}
}
10 changes: 10 additions & 0 deletions Source/FikaAmazonAPI/ConstructFeed/JsonMessages/HeaderData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace FikaAmazonAPI.ConstructFeed.JsonMessages
{
public class HeaderData
{
public string sellerId { get; set; }
public string version { get; set; }
public string issueLocale { get; set; }

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System.Collections.Generic;

namespace FikaAmazonAPI.ConstructFeed.JsonMessages
{
public class JsonMessagesData
{
public HeaderData header { get; set; }
public IList<MessagesData> messages { get; set; } = new List<MessagesData>();
}
}
15 changes: 15 additions & 0 deletions Source/FikaAmazonAPI/ConstructFeed/JsonMessages/MessagesData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System.Collections.Generic;

namespace FikaAmazonAPI.ConstructFeed.JsonMessages
{
public class MessagesData
{
public int messageId { get; set; }
public string sku { get; set; }
public string operationType { get; set; }
public string productType { get; set; }
public IList<PatcheData> patches { get; set; }
//public IList<attributes> attributes { get; set; }

}
}
11 changes: 11 additions & 0 deletions Source/FikaAmazonAPI/ConstructFeed/JsonMessages/PatcheData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System.Collections.Generic;

namespace FikaAmazonAPI.ConstructFeed.JsonMessages
{
public class PatcheData
{
public string op { get; set; }
public string path { get; set; }
public IList<PatcheValueData> value { get; set; }
}
}
18 changes: 18 additions & 0 deletions Source/FikaAmazonAPI/ConstructFeed/JsonMessages/PatcheValueData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System.Collections.Generic;

namespace FikaAmazonAPI.ConstructFeed.JsonMessages
{
public class PatcheValueData
{
public string value { get; set; }
public string language_tag { get; set; }
public string marketplace_id { get; set; }
public string fulfillment_channel_code { get; set; }
public int? quantity { get; set; }
public int? lead_time_to_ship_max_days { get; set; }
public string currency { get; set; }
public IList<PriceData> our_price { get; set; }
public IList<PriceData> minimum_seller_allowed_price { get; set; }
public IList<PriceData> maximum_seller_allowed_price { get; set; }
}
}
13 changes: 13 additions & 0 deletions Source/FikaAmazonAPI/ConstructFeed/JsonMessages/PriceData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System.Collections.Generic;

namespace FikaAmazonAPI.ConstructFeed.JsonMessages
{
public class PriceData
{
public IList<SchedulePriceData> schedule { get; set; }
}
public class SchedulePriceData
{
public decimal value_with_tax { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace FikaAmazonAPI.ConstructFeed.Messages
public class StandardPrice
{
[XmlText]
public string Value { get; set; }
public decimal Value { get; set; }
[XmlAttribute]
public string currency { get; set; }
}
Expand Down
Loading