diff --git a/README.md b/README.md index 4a82c6da..cddf3c52 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,7 @@ Install-Package CSharpAmazonSpAPI - [x] [Feeds](https://github.com/amzn/selling-partner-api-docs/blob/main/references/feeds-api/feeds_2021-06-30.md) for [feedType](https://github.com/amzn/selling-partner-api-docs/blob/main/references/feeds-api/feedtype-values.md) for step to call feed read [doc](https://github.com/amzn/selling-partner-api-docs/blob/main/guides/en-US/use-case-guides/feeds-api-use-case-guide/feeds-api-use-case-guide_2021-06-30.md) - [x] [ListingsItems](https://github.com/amzn/selling-partner-api-docs/blob/main/references/listings-items-api/listingsItems_2021-08-01.md) - [x] [Restrictions](https://developer-docs.amazon.com/sp-api/docs/listings-restrictions-api-v2021-08-01-reference) -- [ ] [ProductTypes](https://developer-docs.amazon.com/sp-api/docs/product-type-definitions-api-v2020-09-01-reference) +- [x] [ProductTypes](https://developer-docs.amazon.com/sp-api/docs/product-type-definitions-api-v2020-09-01-reference) - [x] [Uploads](https://github.com/amzn/selling-partner-api-docs/blob/main/references/uploads-api/uploads_2020-11-01.md) - [x] [shipmentInvoicingV0](https://github.com/amzn/selling-partner-api-docs/blob/main/references/shipment-invoicing-api/shipmentInvoicingV0.md) - [x] [Shippings](https://github.com/amzn/selling-partner-api-docs/blob/main/references/shipping-api/shipping.md) @@ -452,6 +452,27 @@ var shipmentRequest = new CreateShipmentRequest( var shipmentResponse = amazonConnection.MerchantFulfillment.CreateShipment(shipmentRequest); ``` +## ProductTypes SearchDefinitions + +```CSharp +var list = amazonConnection.ProductType.SearchDefinitionsProductTypes( + new Parameter.ProductTypes.SearchDefinitionsProductTypesParameter() + { + keywords = new List { String.Empty }, + }); +``` + +## ProductTypes GetDefinitions + +```CSharp +var def = amazonConnection.ProductType.GetDefinitionsProductType( + new Parameter.ProductTypes.GetDefinitionsProductTypeParameter() + { + productType = "PRODUCT", + requirements = RequirementsEnum.LISTING, + locale = AmazonSpApiSDK.Models.ProductTypes.LocaleEnum.en_US + }); +``` --- ## Q & A diff --git a/Source/FikaAmazonAPI.SampleCode/ProductTypeSample.cs b/Source/FikaAmazonAPI.SampleCode/ProductTypeSample.cs new file mode 100644 index 00000000..d35a3d84 --- /dev/null +++ b/Source/FikaAmazonAPI.SampleCode/ProductTypeSample.cs @@ -0,0 +1,37 @@ +using static FikaAmazonAPI.AmazonSpApiSDK.Models.ListingsItems.ListingsItemPutRequest; + +namespace FikaAmazonAPI.SampleCode +{ + internal class ProductTypeSample + { + + AmazonConnection amazonConnection; + public ProductTypeSample(AmazonConnection amazonConnection) + { + this.amazonConnection = amazonConnection; + } + + + private void SearchDefinitionsProductTypes() + { + var list = amazonConnection.ProductType.SearchDefinitionsProductTypes( + new Parameter.ProductTypes.SearchDefinitionsProductTypesParameter() + { + keywords = new List { String.Empty }, + }); + + } + private void GetDefinitionsProductType() + { + var def = amazonConnection.ProductType.GetDefinitionsProductType( + new Parameter.ProductTypes.GetDefinitionsProductTypeParameter() + { + productType = "PRODUCT", + requirements = RequirementsEnum.LISTING, + locale = AmazonSpApiSDK.Models.ProductTypes.LocaleEnum.en_US + }); + } + + + } +} diff --git a/Source/FikaAmazonAPI.SampleCode/Program.cs b/Source/FikaAmazonAPI.SampleCode/Program.cs index 571cf75a..633cfe23 100644 --- a/Source/FikaAmazonAPI.SampleCode/Program.cs +++ b/Source/FikaAmazonAPI.SampleCode/Program.cs @@ -7,6 +7,7 @@ using FikaAmazonAPI.ReportGeneration; using FikaAmazonAPI.Utils; using Microsoft.Extensions.Configuration; +using static FikaAmazonAPI.AmazonSpApiSDK.Models.ListingsItems.ListingsItemPutRequest; using static FikaAmazonAPI.Utils.Constants; namespace FikaAmazonAPI.SampleCode @@ -34,6 +35,18 @@ static async Task Main(string[] args) IsActiveLimitRate = true }); + var aha = amazonConnection.ProductType.SearchDefinitionsProductTypes(new Parameter.ProductTypes.SearchDefinitionsProductTypesParameter() + { + keywords = new List { String.Empty }, + }); + + var def = amazonConnection.ProductType.GetDefinitionsProductType(new Parameter.ProductTypes.GetDefinitionsProductTypeParameter() + { + productType = "PRODUCT", + requirements = RequirementsEnum.LISTING, + locale = AmazonSpApiSDK.Models.ProductTypes.LocaleEnum.en_US + }); + var result = amazonConnection.Restrictions.GetListingsRestrictions(new Parameter.Restrictions.ParameterGetListingsRestrictions { asin = "B07GY3J99B", @@ -50,7 +63,7 @@ static async Task Main(string[] args) sku = SKU, listingsItemPutRequest = new ListingsItemPutRequest() { - productType = "LUGGAGE", + productType = "PRODUCT", requirements = Requirements.LISTING, //Example from https://developer-docs.amazon.com/sp-api/docs/listings-items-api-v2020-09-01-use-case-guide diff --git a/Source/FikaAmazonAPI/AmazonConnection.cs b/Source/FikaAmazonAPI/AmazonConnection.cs index 648a460d..611fb24e 100644 --- a/Source/FikaAmazonAPI/AmazonConnection.cs +++ b/Source/FikaAmazonAPI/AmazonConnection.cs @@ -27,6 +27,7 @@ public class AmazonConnection public MessagingService Messaging => this._Messaging ?? throw _NoCredentials; public NotificationService Notification => this._Notification ?? throw _NoCredentials; public ProductFeeService ProductFee => this._ProductFee ?? throw _NoCredentials; + public ProductTypeService ProductType => this._ProductType ?? throw _NoCredentials; public SalesService Sales => this._Sales ?? throw _NoCredentials; public SellerService Seller => this._Seller ?? throw _NoCredentials; public ServicesService Services => this._Services ?? throw _NoCredentials; @@ -60,6 +61,7 @@ public class AmazonConnection private MessagingService _Messaging { get; set; } private NotificationService _Notification { get; set; } private ProductFeeService _ProductFee { get; set; } + private ProductTypeService _ProductType { get; set; } private SalesService _Sales { get; set; } private SellerService _Seller { get; set; } private ServicesService _Services { get; set; } @@ -114,6 +116,7 @@ private void Init(AmazonCredential Credentials) this._Messaging = new MessagingService(this.Credentials); this._Notification = new NotificationService(this.Credentials); this._ProductFee = new ProductFeeService(this.Credentials); + this._ProductType = new ProductTypeService(this.Credentials); this._Sales = new SalesService(this.Credentials); this._Seller = new SellerService(this.Credentials); this._Services = new ServicesService(this.Credentials); diff --git a/Source/FikaAmazonAPI/AmazonSpApiSDK/Models/ProductTypes/LocaleEnum.cs b/Source/FikaAmazonAPI/AmazonSpApiSDK/Models/ProductTypes/LocaleEnum.cs new file mode 100644 index 00000000..e5ca4e7a --- /dev/null +++ b/Source/FikaAmazonAPI/AmazonSpApiSDK/Models/ProductTypes/LocaleEnum.cs @@ -0,0 +1,158 @@ +using System.Runtime.Serialization; + +namespace FikaAmazonAPI.AmazonSpApiSDK.Models.ProductTypes +{ + public enum LocaleEnum + { + /// + /// Arabic + /// + [EnumMember(Value = "ar")] + ar, + /// + /// Arabic (U.A.E.) + /// + [EnumMember(Value = "ar_AE")] ar_AE, + /// + /// German + /// + [EnumMember(Value = "de")] de, + /// + /// German (Germany) + /// + [EnumMember(Value = "de_DE")] de_DE, + /// + /// English + /// + [EnumMember(Value = "en")] en, + /// + /// English (U.A.E.) + /// + [EnumMember(Value = "en_AE")] en_AE, + /// + /// English (Australia) + /// + [EnumMember(Value = "en_AU")] en_AU, + /// + /// English (Canada) + /// + [EnumMember(Value = "en_CA")] en_CA, + /// + /// English (United Kingdom) + /// + [EnumMember(Value = "en_GB")] en_GB, + /// + /// English (India) + /// + [EnumMember(Value = "en_IN")] en_IN, + /// + /// English (Singapore) + /// + [EnumMember(Value = "en_SG")] en_SG, + /// + /// English (United States) + /// + [EnumMember(Value = "en_US")] en_US, + /// + /// Spanish + /// + [EnumMember(Value = "es")] es, + /// + /// Spanish (Spain) + /// + [EnumMember(Value = "es_ES")] es_ES, + /// + /// Spanish (Mexico) + /// + [EnumMember(Value = "es_MX")] es_MX, + /// + /// Spanish (United States) + /// + [EnumMember(Value = "es_US")] es_US, + /// + /// French + /// + [EnumMember(Value = "fr")] fr, + /// + /// French (Canada) + /// + [EnumMember(Value = "fr_CA")] fr_CA, + /// + /// French (France) + /// + [EnumMember(Value = "fr_FR")] fr_FR, + /// + /// Italian + /// + [EnumMember(Value = "it")] it, + /// + /// Italian (Italy) + /// + [EnumMember(Value = "it_IT")] it_IT, + /// + /// Japanese + /// + [EnumMember(Value = "ja")] ja, + /// + /// Japanese (Japan) + /// + [EnumMember(Value = "ja_JP")] ja_JP, + /// + /// Dutch + /// + [EnumMember(Value = "nl")] nl, + /// + /// Dutch (Netherlands) + /// + [EnumMember(Value = "nl_NL")] nl_NL, + /// + /// Polish + /// + [EnumMember(Value = "pl")] pl, + /// + /// Polish (Poland) + /// + [EnumMember(Value = "pl_PL")] pl_PL, + /// + /// Portuguese + /// + [EnumMember(Value = "pt")] pt, + /// + /// Portuguese (Brazil) + /// + [EnumMember(Value = "pt_BR")] pt_BR, + /// + /// Portuguese (Portugal) + /// + [EnumMember(Value = "pt_PT")] pt_PT, + /// + /// Swedish + /// + [EnumMember(Value = "sv")] sv, + /// + /// Swedish (Sweden) + /// + [EnumMember(Value = "sv_SE")] sv_SE, + /// + /// Turkish + /// + [EnumMember(Value = "tr")] tr, + /// + /// Turkish (Turkey) + /// + [EnumMember(Value = "tr_TR")] tr_TR, + /// + /// Chinese + /// + [EnumMember(Value = "zh")] zh, + /// + /// Chinese (Simplified) + /// + [EnumMember(Value = "zh_CN")] zh_CN, + /// + /// Chinese (Traditional) + /// + [EnumMember(Value = "zh_TW")] zh_TW, + + } +} diff --git a/Source/FikaAmazonAPI/AmazonSpApiSDK/Models/ProductTypes/ProductType.cs b/Source/FikaAmazonAPI/AmazonSpApiSDK/Models/ProductTypes/ProductType.cs new file mode 100644 index 00000000..7d8c9902 --- /dev/null +++ b/Source/FikaAmazonAPI/AmazonSpApiSDK/Models/ProductTypes/ProductType.cs @@ -0,0 +1,56 @@ +using Newtonsoft.Json; +using System.Collections.Generic; +using System.Runtime.Serialization; +using System.Text; + +namespace FikaAmazonAPI.AmazonSpApiSDK.Models.ProductTypes +{ + + /// + /// An Amazon product type with a definition available. + /// + [DataContract] + public class ProductType + { + /// + /// The name of the Amazon product type. + /// + /// The name of the Amazon product type. + [DataMember(Name = "name", EmitDefaultValue = false)] + [JsonProperty(PropertyName = "name")] + public string Name { get; set; } + + /// + /// The Amazon marketplace identifiers for which the product type definition is available. + /// + /// The Amazon marketplace identifiers for which the product type definition is available. + [DataMember(Name = "marketplaceIds", EmitDefaultValue = false)] + [JsonProperty(PropertyName = "marketplaceIds")] + public List MarketplaceIds { get; set; } + + + /// + /// Get the string presentation of the object + /// + /// String presentation of the object + public override string ToString() + { + var sb = new StringBuilder(); + sb.Append("class ProductType {\n"); + sb.Append(" Name: ").Append(Name).Append("\n"); + sb.Append(" MarketplaceIds: ").Append(MarketplaceIds).Append("\n"); + sb.Append("}\n"); + return sb.ToString(); + } + + /// + /// Get the JSON string presentation of the object + /// + /// JSON string presentation of the object + public string ToJson() + { + return JsonConvert.SerializeObject(this, Formatting.Indented); + } + + } +} diff --git a/Source/FikaAmazonAPI/AmazonSpApiSDK/Models/ProductTypes/ProductTypeDefinition.cs b/Source/FikaAmazonAPI/AmazonSpApiSDK/Models/ProductTypes/ProductTypeDefinition.cs new file mode 100644 index 00000000..59c25fb8 --- /dev/null +++ b/Source/FikaAmazonAPI/AmazonSpApiSDK/Models/ProductTypes/ProductTypeDefinition.cs @@ -0,0 +1,119 @@ +using Newtonsoft.Json; +using System.Collections.Generic; +using System.Runtime.Serialization; +using System.Text; + +namespace FikaAmazonAPI.AmazonSpApiSDK.Models.ProductTypes +{ + + /// + /// A product type definition represents the attributes and data requirements for a product type in the Amazon catalog. Product type definitions are used interchangeably between the Selling Partner API for Listings Items, Selling Partner API for Catalog Items, and JSON-based listings feeds in the Selling Partner API for Feeds. + /// + [DataContract] + public class ProductTypeDefinition + { + /// + /// Link to meta-schema describing the vocabulary used by the product type schema. + /// + /// Link to meta-schema describing the vocabulary used by the product type schema. + [DataMember(Name = "metaSchema", EmitDefaultValue = false)] + [JsonProperty(PropertyName = "metaSchema")] + public SchemaLink MetaSchema { get; set; } + + /// + /// Link to schema describing the attributes and requirements for the product type. + /// + /// Link to schema describing the attributes and requirements for the product type. + [DataMember(Name = "schema", EmitDefaultValue = false)] + [JsonProperty(PropertyName = "schema")] + public SchemaLink Schema { get; set; } + + /// + /// Name of the requirements set represented in this product type definition. + /// + /// Name of the requirements set represented in this product type definition. + [DataMember(Name = "requirements", EmitDefaultValue = false)] + [JsonProperty(PropertyName = "requirements")] + public string Requirements { get; set; } + + /// + /// Identifies if the required attributes for a requirements set are enforced by the product type definition schema. Non-enforced requirements enable structural validation of individual attributes without all of the required attributes being present (such as for partial updates). + /// + /// Identifies if the required attributes for a requirements set are enforced by the product type definition schema. Non-enforced requirements enable structural validation of individual attributes without all of the required attributes being present (such as for partial updates). + [DataMember(Name = "requirementsEnforced", EmitDefaultValue = false)] + [JsonProperty(PropertyName = "requirementsEnforced")] + public string RequirementsEnforced { get; set; } + + /// + /// Mapping of property group names to property groups. Property groups represent logical groupings of schema properties that can be used for display or informational purposes. + /// + /// Mapping of property group names to property groups. Property groups represent logical groupings of schema properties that can be used for display or informational purposes. + [DataMember(Name = "propertyGroups", EmitDefaultValue = false)] + [JsonProperty(PropertyName = "propertyGroups")] + public Dictionary PropertyGroups { get; set; } + + /// + /// Locale of the display elements contained in the product type definition. + /// + /// Locale of the display elements contained in the product type definition. + [DataMember(Name = "locale", EmitDefaultValue = false)] + [JsonProperty(PropertyName = "locale")] + public string Locale { get; set; } + + /// + /// Amazon marketplace identifiers for which the product type definition is applicable. + /// + /// Amazon marketplace identifiers for which the product type definition is applicable. + [DataMember(Name = "marketplaceIds", EmitDefaultValue = false)] + [JsonProperty(PropertyName = "marketplaceIds")] + public List MarketplaceIds { get; set; } + + /// + /// The name of the Amazon product type that this product type definition applies to. + /// + /// The name of the Amazon product type that this product type definition applies to. + [DataMember(Name = "productType", EmitDefaultValue = false)] + [JsonProperty(PropertyName = "productType")] + public string ProductType { get; set; } + + /// + /// The version details for the Amazon product type. + /// + /// The version details for the Amazon product type. + [DataMember(Name = "productTypeVersion", EmitDefaultValue = false)] + [JsonProperty(PropertyName = "productTypeVersion")] + public ProductTypeVersion ProductTypeVersion { get; set; } + + + /// + /// Get the string presentation of the object + /// + /// String presentation of the object + public override string ToString() + { + var sb = new StringBuilder(); + sb.Append("class ProductTypeDefinition {\n"); + sb.Append(" MetaSchema: ").Append(MetaSchema).Append("\n"); + sb.Append(" Schema: ").Append(Schema).Append("\n"); + sb.Append(" Requirements: ").Append(Requirements).Append("\n"); + sb.Append(" RequirementsEnforced: ").Append(RequirementsEnforced).Append("\n"); + sb.Append(" PropertyGroups: ").Append(PropertyGroups).Append("\n"); + sb.Append(" Locale: ").Append(Locale).Append("\n"); + sb.Append(" MarketplaceIds: ").Append(MarketplaceIds).Append("\n"); + sb.Append(" ProductType: ").Append(ProductType).Append("\n"); + sb.Append(" ProductTypeVersion: ").Append(ProductTypeVersion).Append("\n"); + sb.Append("}\n"); + return sb.ToString(); + } + + /// + /// Get the JSON string presentation of the object + /// + /// JSON string presentation of the object + public string ToJson() + { + return JsonConvert.SerializeObject(this, Formatting.Indented); + } + + } +} diff --git a/Source/FikaAmazonAPI/AmazonSpApiSDK/Models/ProductTypes/ProductTypeList.cs b/Source/FikaAmazonAPI/AmazonSpApiSDK/Models/ProductTypes/ProductTypeList.cs new file mode 100644 index 00000000..84db2bf8 --- /dev/null +++ b/Source/FikaAmazonAPI/AmazonSpApiSDK/Models/ProductTypes/ProductTypeList.cs @@ -0,0 +1,46 @@ +using Newtonsoft.Json; +using System.Collections.Generic; +using System.Runtime.Serialization; +using System.Text; + +namespace FikaAmazonAPI.AmazonSpApiSDK.Models.ProductTypes +{ + + /// + /// A list of Amazon product types with definitions available. + /// + [DataContract] + public class ProductTypeList + { + /// + /// Gets or Sets ProductTypes + /// + [DataMember(Name = "productTypes", EmitDefaultValue = false)] + [JsonProperty(PropertyName = "productTypes")] + public List ProductTypes { get; set; } + + + /// + /// Get the string presentation of the object + /// + /// String presentation of the object + public override string ToString() + { + var sb = new StringBuilder(); + sb.Append("class ProductTypeList {\n"); + sb.Append(" ProductTypes: ").Append(ProductTypes).Append("\n"); + sb.Append("}\n"); + return sb.ToString(); + } + + /// + /// Get the JSON string presentation of the object + /// + /// JSON string presentation of the object + public string ToJson() + { + return JsonConvert.SerializeObject(this, Formatting.Indented); + } + + } +} diff --git a/Source/FikaAmazonAPI/AmazonSpApiSDK/Models/ProductTypes/ProductTypeVersion.cs b/Source/FikaAmazonAPI/AmazonSpApiSDK/Models/ProductTypes/ProductTypeVersion.cs new file mode 100644 index 00000000..43b81555 --- /dev/null +++ b/Source/FikaAmazonAPI/AmazonSpApiSDK/Models/ProductTypes/ProductTypeVersion.cs @@ -0,0 +1,64 @@ +using Newtonsoft.Json; +using System.Runtime.Serialization; +using System.Text; + +namespace FikaAmazonAPI.AmazonSpApiSDK.Models.ProductTypes +{ + + /// + /// The version details for an Amazon product type. + /// + [DataContract] + public class ProductTypeVersion + { + /// + /// Version identifier. + /// + /// Version identifier. + [DataMember(Name = "version", EmitDefaultValue = false)] + [JsonProperty(PropertyName = "version")] + public string Version { get; set; } + + /// + /// When true, the version indicated by the version identifier is the latest available for the Amazon product type. + /// + /// When true, the version indicated by the version identifier is the latest available for the Amazon product type. + [DataMember(Name = "latest", EmitDefaultValue = false)] + [JsonProperty(PropertyName = "latest")] + public bool? Latest { get; set; } + + /// + /// When true, the version indicated by the version identifier is the prerelease (release candidate) for the Amazon product type. + /// + /// When true, the version indicated by the version identifier is the prerelease (release candidate) for the Amazon product type. + [DataMember(Name = "releaseCandidate", EmitDefaultValue = false)] + [JsonProperty(PropertyName = "releaseCandidate")] + public bool? ReleaseCandidate { get; set; } + + + /// + /// Get the string presentation of the object + /// + /// String presentation of the object + public override string ToString() + { + var sb = new StringBuilder(); + sb.Append("class ProductTypeVersion {\n"); + sb.Append(" Version: ").Append(Version).Append("\n"); + sb.Append(" Latest: ").Append(Latest).Append("\n"); + sb.Append(" ReleaseCandidate: ").Append(ReleaseCandidate).Append("\n"); + sb.Append("}\n"); + return sb.ToString(); + } + + /// + /// Get the JSON string presentation of the object + /// + /// JSON string presentation of the object + public string ToJson() + { + return JsonConvert.SerializeObject(this, Formatting.Indented); + } + + } +} diff --git a/Source/FikaAmazonAPI/AmazonSpApiSDK/Models/ProductTypes/PropertyGroup.cs b/Source/FikaAmazonAPI/AmazonSpApiSDK/Models/ProductTypes/PropertyGroup.cs new file mode 100644 index 00000000..1306307d --- /dev/null +++ b/Source/FikaAmazonAPI/AmazonSpApiSDK/Models/ProductTypes/PropertyGroup.cs @@ -0,0 +1,65 @@ +using Newtonsoft.Json; +using System.Collections.Generic; +using System.Runtime.Serialization; +using System.Text; + +namespace FikaAmazonAPI.AmazonSpApiSDK.Models.ProductTypes +{ + + /// + /// A property group represents a logical grouping of schema properties that can be used for display or informational purposes. + /// + [DataContract] + public class PropertyGroup + { + /// + /// The display label of the property group. + /// + /// The display label of the property group. + [DataMember(Name = "title", EmitDefaultValue = false)] + [JsonProperty(PropertyName = "title")] + public string Title { get; set; } + + /// + /// The description of the property group. + /// + /// The description of the property group. + [DataMember(Name = "description", EmitDefaultValue = false)] + [JsonProperty(PropertyName = "description")] + public string Description { get; set; } + + /// + /// The names of the schema properties for the property group. + /// + /// The names of the schema properties for the property group. + [DataMember(Name = "propertyNames", EmitDefaultValue = false)] + [JsonProperty(PropertyName = "propertyNames")] + public List PropertyNames { get; set; } + + + /// + /// Get the string presentation of the object + /// + /// String presentation of the object + public override string ToString() + { + var sb = new StringBuilder(); + sb.Append("class PropertyGroup {\n"); + sb.Append(" Title: ").Append(Title).Append("\n"); + sb.Append(" Description: ").Append(Description).Append("\n"); + sb.Append(" PropertyNames: ").Append(PropertyNames).Append("\n"); + sb.Append("}\n"); + return sb.ToString(); + } + + /// + /// Get the JSON string presentation of the object + /// + /// JSON string presentation of the object + public string ToJson() + { + return JsonConvert.SerializeObject(this, Formatting.Indented); + } + + } +} diff --git a/Source/FikaAmazonAPI/AmazonSpApiSDK/Models/ProductTypes/RequirementsEnforcedEnum.cs b/Source/FikaAmazonAPI/AmazonSpApiSDK/Models/ProductTypes/RequirementsEnforcedEnum.cs new file mode 100644 index 00000000..93010185 --- /dev/null +++ b/Source/FikaAmazonAPI/AmazonSpApiSDK/Models/ProductTypes/RequirementsEnforcedEnum.cs @@ -0,0 +1,15 @@ +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; +using System.Runtime.Serialization; + +namespace FikaAmazonAPI.AmazonSpApiSDK.Models.ProductTypes +{ + [JsonConverter(typeof(StringEnumConverter))] + public enum RequirementsEnforcedEnum + { + [EnumMember(Value = "ENFORCED")] + ENFORCED, + [EnumMember(Value = "NOT_ENFORCED")] + NOT_ENFORCED + } +} diff --git a/Source/FikaAmazonAPI/AmazonSpApiSDK/Models/ProductTypes/SchemaLink.cs b/Source/FikaAmazonAPI/AmazonSpApiSDK/Models/ProductTypes/SchemaLink.cs new file mode 100644 index 00000000..4b0225fe --- /dev/null +++ b/Source/FikaAmazonAPI/AmazonSpApiSDK/Models/ProductTypes/SchemaLink.cs @@ -0,0 +1,56 @@ +using Newtonsoft.Json; +using System; +using System.Runtime.Serialization; +using System.Text; + +namespace FikaAmazonAPI.AmazonSpApiSDK.Models.ProductTypes +{ + + /// + /// + /// + [DataContract] + public class SchemaLink + { + /// + /// Link to retrieve the schema. + /// + /// Link to retrieve the schema. + [DataMember(Name = "link", EmitDefaultValue = false)] + [JsonProperty(PropertyName = "link")] + public Object Link { get; set; } + + /// + /// Checksum hash of the schema (Base64 MD5). Can be used to verify schema contents, identify changes between schema versions, and for caching. + /// + /// Checksum hash of the schema (Base64 MD5). Can be used to verify schema contents, identify changes between schema versions, and for caching. + [DataMember(Name = "checksum", EmitDefaultValue = false)] + [JsonProperty(PropertyName = "checksum")] + public string Checksum { get; set; } + + + /// + /// Get the string presentation of the object + /// + /// String presentation of the object + public override string ToString() + { + var sb = new StringBuilder(); + sb.Append("class SchemaLink {\n"); + sb.Append(" Link: ").Append(Link).Append("\n"); + sb.Append(" Checksum: ").Append(Checksum).Append("\n"); + sb.Append("}\n"); + return sb.ToString(); + } + + /// + /// Get the JSON string presentation of the object + /// + /// JSON string presentation of the object + public string ToJson() + { + return JsonConvert.SerializeObject(this, Formatting.Indented); + } + + } +} diff --git a/Source/FikaAmazonAPI/Parameter/ProductTypes/GetDefinitionsProductTypeParameter.cs b/Source/FikaAmazonAPI/Parameter/ProductTypes/GetDefinitionsProductTypeParameter.cs new file mode 100644 index 00000000..5f6a90ed --- /dev/null +++ b/Source/FikaAmazonAPI/Parameter/ProductTypes/GetDefinitionsProductTypeParameter.cs @@ -0,0 +1,19 @@ +using FikaAmazonAPI.AmazonSpApiSDK.Models.ProductTypes; +using FikaAmazonAPI.Search; +using System.Collections.Generic; +using static FikaAmazonAPI.AmazonSpApiSDK.Models.ListingsItems.ListingsItemPutRequest; + +namespace FikaAmazonAPI.Parameter.ProductTypes +{ + public class GetDefinitionsProductTypeParameter : ParameterBased + { + public string productType { get; set; } + public string sellerId { get; set; } + public IList marketplaceIds { get; set; } = new List(); + public string productTypeVersion { get; set; } + public RequirementsEnum requirements { get; set; } + public RequirementsEnforcedEnum requirementsEnforced { get; set; } + public LocaleEnum locale { get; set; } + + } +} diff --git a/Source/FikaAmazonAPI/Parameter/ProductTypes/SearchDefinitionsProductTypesParameter.cs b/Source/FikaAmazonAPI/Parameter/ProductTypes/SearchDefinitionsProductTypesParameter.cs new file mode 100644 index 00000000..2dac0727 --- /dev/null +++ b/Source/FikaAmazonAPI/Parameter/ProductTypes/SearchDefinitionsProductTypesParameter.cs @@ -0,0 +1,11 @@ +using FikaAmazonAPI.Search; +using System.Collections.Generic; + +namespace FikaAmazonAPI.Parameter.ProductTypes +{ + public class SearchDefinitionsProductTypesParameter : ParameterBased + { + public IList keywords { get; set; } + public IList marketplaceIds { get; set; } = new List(); + } +} diff --git a/Source/FikaAmazonAPI/Services/ApiUrls.cs b/Source/FikaAmazonAPI/Services/ApiUrls.cs index 6119450d..5dd503b6 100644 --- a/Source/FikaAmazonAPI/Services/ApiUrls.cs +++ b/Source/FikaAmazonAPI/Services/ApiUrls.cs @@ -271,6 +271,16 @@ public static string GetCompetitivePricing public static string GetItemOffers(string Asin) => $"{_resourceBaseUrl}/items/{Asin}/offers"; } + protected class ProductTypeApiUrls + { + private readonly static string _resourceBaseUrl = "/definitions/2020-09-01"; + public static string SearchDefinitionsProductTypes + { + get => $"{_resourceBaseUrl}/productTypes"; + } + + public static string GetDefinitionsProductType(string productType) => $"{_resourceBaseUrl}/productTypes/{productType}"; + } protected class ReportApiUrls { diff --git a/Source/FikaAmazonAPI/Services/ProductTypeService.cs b/Source/FikaAmazonAPI/Services/ProductTypeService.cs index 22dd63cf..31abf410 100644 --- a/Source/FikaAmazonAPI/Services/ProductTypeService.cs +++ b/Source/FikaAmazonAPI/Services/ProductTypeService.cs @@ -1,4 +1,9 @@ -namespace FikaAmazonAPI.Services +using FikaAmazonAPI.AmazonSpApiSDK.Models.ProductTypes; +using FikaAmazonAPI.Parameter.ProductTypes; +using FikaAmazonAPI.Utils; +using System.Threading.Tasks; + +namespace FikaAmazonAPI.Services { public class ProductTypeService : RequestService { @@ -8,17 +13,32 @@ public ProductTypeService(AmazonCredential amazonCredential) : base(amazonCreden } - //public IList SearchDefinitionsProductTypes(ParameterGetPricing parameterGetPricing) => - // Task.Run(() => SearchDefinitionsProductTypesAsync(parameterGetPricing)).ConfigureAwait(false).GetAwaiter().GetResult(); - //public async Task> SearchDefinitionsProductTypesAsync(ParameterGetPricing parameterGetPricing) - //{ - // var param = parameterGetPricing.getParameters(); + public ProductTypeList SearchDefinitionsProductTypes(SearchDefinitionsProductTypesParameter parameter) => + Task.Run(() => SearchDefinitionsProductTypesAsync(parameter)).ConfigureAwait(false).GetAwaiter().GetResult(); + public async Task SearchDefinitionsProductTypesAsync(SearchDefinitionsProductTypesParameter parameter) + { + if (parameter.marketplaceIds == null || parameter.marketplaceIds.Count == 0) + parameter.marketplaceIds.Add(AmazonCredential.MarketPlace.ID); + + var param = parameter.getParameters(); + + await CreateAuthorizedRequestAsync(ProductTypeApiUrls.SearchDefinitionsProductTypes, RestSharp.Method.GET, param); + return await ExecuteRequestAsync(RateLimitType.ProductTypes_SearchDefinitionsProductTypes); + } + - // await CreateAuthorizedRequestAsync(ProductPricingApiUrls.GetPricing, RestSharp.Method.GET, param); - // var response = await ExecuteRequestAsync(RateLimitType.ProductPricing_GetPricing); - // if (response != null && response.Payload != null) - // return response.Payload; - // return null; - //} + public ProductTypeDefinition GetDefinitionsProductType(GetDefinitionsProductTypeParameter parameter) => + Task.Run(() => SearchDefinitionsProductTypesAsync(parameter)).ConfigureAwait(false).GetAwaiter().GetResult(); + public async Task SearchDefinitionsProductTypesAsync(GetDefinitionsProductTypeParameter parameter) + { + if (parameter.marketplaceIds == null || parameter.marketplaceIds.Count == 0) + parameter.marketplaceIds.Add(AmazonCredential.MarketPlace.ID); + + + var param = parameter.getParameters(); + + await CreateAuthorizedRequestAsync(ProductTypeApiUrls.GetDefinitionsProductType(parameter.productType), RestSharp.Method.GET, param); + return await ExecuteRequestAsync(RateLimitType.ProductTypes_GetDefinitionsProductType); + } } }