Пример #1
0
        public Dictionary <string, List <LowestOfferListingType> > GetLowestOfferListingsForASINs(IEnumerable <string> asins)
        {
            List <GetLowestOfferListingsForASINResult> getLowestOfferListingsForAsinResults = new List <GetLowestOfferListingsForASINResult>();

            foreach (IEnumerable <string> asinBatch in asins.Distinct().Batch(c_maxBatchAmount))
            {
                GetLowestOfferListingsForASINRequest requestListings = new GetLowestOfferListingsForASINRequest
                {
                    SellerId      = m_sellerId,
                    MarketplaceId = m_marketPlaceId,
                    ASINList      = new ASINListType().WithASIN(asinBatch.ToArray()),
                    ExcludeMe     = true,
                    ItemCondition = "New"
                };

                const int numAttempts        = 3;
                int       numAttemptsCounter = 0;

                Func <List <GetLowestOfferListingsForASINResult> > tryGetLowestOfferListingsForAsin =
                    () =>
                {
                    numAttemptsCounter++;

                    try
                    {
                        GetLowestOfferListingsForASINResponse response = m_productClient.GetLowestOfferListingsForASIN(requestListings);

                        return(response.GetLowestOfferListingsForASINResult);
                    }
                    catch (MarketplaceWebServiceProductsException e)
                    {
                        if (numAttemptsCounter == numAttempts)
                        {
                            throw new QuitException(string.Format("Call to 'GetLowestOfferListingsForASIN' failed on attempt #{0}. Message: {1} StackTrace: {2}", numAttemptsCounter, e.Message, e.StackTrace));
                        }

                        throw new RetryException("Try again to GetLowestOfferListingsForASINResult");
                    }
                };

                List <GetLowestOfferListingsForASINResult> currentBatchLowestOfferListings = tryGetLowestOfferListingsForAsin.Retry(numAttempts, 5000);

                Thread.Sleep(2000);

                getLowestOfferListingsForAsinResults.AddRange(currentBatchLowestOfferListings);
            }

            return(getLowestOfferListingsForAsinResults
                   .Where(x => x.Product != null && x.Product.LowestOfferListings != null)
                   .ToDictionary(x => x.ASIN, y => y.Product.LowestOfferListings.LowestOfferListing));
        }
Пример #2
0
 public GetLowestOfferListingsForASINResponse InvokeGetLowestOfferListingsForASIN(string sellerId, string mwsAuthToken, string marketplaceId, string itemCondition, bool excludeMe, out APIResults results)
 {
     try
     {
         // Create a request.
         GetLowestOfferListingsForASINRequest request = new GetLowestOfferListingsForASINRequest();
         request.SellerId      = sellerId;
         request.MWSAuthToken  = mwsAuthToken;
         request.MarketplaceId = marketplaceId;
         ASINListType _asinList = new ASINListType();
         request.ASINList      = _asinList;
         request.ItemCondition = itemCondition;
         request.ExcludeMe     = excludeMe;
         GetLowestOfferListingsForASINResponse output = this.productClient.GetLowestOfferListingsForASIN(request);
         results = new APIResults((IMWSResponse)output);
         return(output);
     }
     catch (MarketplaceWebServiceProductsException ex)
     {
         results = new APIResults(ex);
         throw ex;
     }
 }
Пример #3
0
        /// <summary>
        /// Gets some of the lowest prices based on the product identified by the given
        /// MarketplaceId and ASIN.
        ///
        /// </summary>
        /// <param name="service">Instance of MarketplaceWebServiceProducts service</param>
        /// <param name="request">GetLowestOfferListingsForASINRequest request</param>
        public static void InvokeGetLowestOfferListingsForASIN(MarketplaceWebServiceProducts service, GetLowestOfferListingsForASINRequest request)
        {
            try
            {
                GetLowestOfferListingsForASINResponse response = service.GetLowestOfferListingsForASIN(request);


                Console.WriteLine("Service Response");
                Console.WriteLine("=============================================================================");
                Console.WriteLine();

                Console.WriteLine("        GetLowestOfferListingsForASINResponse");
                List <GetLowestOfferListingsForASINResult> getLowestOfferListingsForASINResultList = response.GetLowestOfferListingsForASINResult;
                foreach (GetLowestOfferListingsForASINResult getLowestOfferListingsForASINResult in getLowestOfferListingsForASINResultList)
                {
                    Console.WriteLine("            GetLowestOfferListingsForASINResult");
                    if (getLowestOfferListingsForASINResult.IsSetASIN())
                    {
                        Console.WriteLine("        ASIN");
                        Console.WriteLine();
                        Console.WriteLine("                {0}", getLowestOfferListingsForASINResult.ASIN);
                        Console.WriteLine();
                    }
                    if (getLowestOfferListingsForASINResult.IsSetstatus())
                    {
                        Console.WriteLine("        status");
                        Console.WriteLine();
                        Console.WriteLine("                {0}", getLowestOfferListingsForASINResult.status);
                        Console.WriteLine();
                    }
                    if (getLowestOfferListingsForASINResult.IsSetAllOfferListingsConsidered())
                    {
                        Console.WriteLine("                AllOfferListingsConsidered");
                        Console.WriteLine("                    {0}", getLowestOfferListingsForASINResult.AllOfferListingsConsidered);
                    }
                    if (getLowestOfferListingsForASINResult.IsSetProduct())
                    {
                        Console.WriteLine("                Product");
                        Product product = getLowestOfferListingsForASINResult.Product;
                        if (product.IsSetIdentifiers())
                        {
                            Console.WriteLine("                    Identifiers");
                            IdentifierType identifiers = product.Identifiers;
                            if (identifiers.IsSetMarketplaceASIN())
                            {
                                Console.WriteLine("                        MarketplaceASIN");
                                ASINIdentifier marketplaceASIN = identifiers.MarketplaceASIN;
                                if (marketplaceASIN.IsSetMarketplaceId())
                                {
                                    Console.WriteLine("                            MarketplaceId");
                                    Console.WriteLine("                                {0}", marketplaceASIN.MarketplaceId);
                                }
                                if (marketplaceASIN.IsSetASIN())
                                {
                                    Console.WriteLine("                            ASIN");
                                    Console.WriteLine("                                {0}", marketplaceASIN.ASIN);
                                }
                            }
                            if (identifiers.IsSetSKUIdentifier())
                            {
                                Console.WriteLine("                        SKUIdentifier");
                                SellerSKUIdentifier SKUIdentifier = identifiers.SKUIdentifier;
                                if (SKUIdentifier.IsSetMarketplaceId())
                                {
                                    Console.WriteLine("                            MarketplaceId");
                                    Console.WriteLine("                                {0}", SKUIdentifier.MarketplaceId);
                                }
                                if (SKUIdentifier.IsSetSellerId())
                                {
                                    Console.WriteLine("                            SellerId");
                                    Console.WriteLine("                                {0}", SKUIdentifier.SellerId);
                                }
                                if (SKUIdentifier.IsSetSellerSKU())
                                {
                                    Console.WriteLine("                            SellerSKU");
                                    Console.WriteLine("                                {0}", SKUIdentifier.SellerSKU);
                                }
                            }
                        }
                        if (product.IsSetCompetitivePricing())
                        {
                            Console.WriteLine("                    CompetitivePricing");
                            CompetitivePricingType competitivePricing = product.CompetitivePricing;
                            if (competitivePricing.IsSetCompetitivePrices())
                            {
                                Console.WriteLine("                        CompetitivePrices");
                                CompetitivePriceList        competitivePrices    = competitivePricing.CompetitivePrices;
                                List <CompetitivePriceType> competitivePriceList = competitivePrices.CompetitivePrice;
                                foreach (CompetitivePriceType competitivePrice in competitivePriceList)
                                {
                                    Console.WriteLine("                            CompetitivePrice");
                                    if (competitivePrice.IsSetcondition())
                                    {
                                        Console.WriteLine("                        condition");
                                        Console.WriteLine();
                                        Console.WriteLine("                                {0}", competitivePrice.condition);
                                        Console.WriteLine();
                                    }
                                    if (competitivePrice.IsSetsubcondition())
                                    {
                                        Console.WriteLine("                        subcondition");
                                        Console.WriteLine();
                                        Console.WriteLine("                                {0}", competitivePrice.subcondition);
                                        Console.WriteLine();
                                    }
                                    if (competitivePrice.IsSetbelongsToRequester())
                                    {
                                        Console.WriteLine("                        belongsToRequester");
                                        Console.WriteLine();
                                        Console.WriteLine("                                {0}", competitivePrice.belongsToRequester);
                                        Console.WriteLine();
                                    }
                                    if (competitivePrice.IsSetCompetitivePriceId())
                                    {
                                        Console.WriteLine("                                CompetitivePriceId");
                                        Console.WriteLine("                                    {0}", competitivePrice.CompetitivePriceId);
                                    }
                                    if (competitivePrice.IsSetPrice())
                                    {
                                        Console.WriteLine("                                Price");
                                        PriceType price = competitivePrice.Price;
                                        if (price.IsSetLandedPrice())
                                        {
                                            Console.WriteLine("                                    LandedPrice");
                                            MoneyType landedPrice = price.LandedPrice;
                                            if (landedPrice.IsSetCurrencyCode())
                                            {
                                                Console.WriteLine("                                        CurrencyCode");
                                                Console.WriteLine("                                            {0}", landedPrice.CurrencyCode);
                                            }
                                            if (landedPrice.IsSetAmount())
                                            {
                                                Console.WriteLine("                                        Amount");
                                                Console.WriteLine("                                            {0}", landedPrice.Amount);
                                            }
                                        }
                                        if (price.IsSetListingPrice())
                                        {
                                            Console.WriteLine("                                    ListingPrice");
                                            MoneyType listingPrice = price.ListingPrice;
                                            if (listingPrice.IsSetCurrencyCode())
                                            {
                                                Console.WriteLine("                                        CurrencyCode");
                                                Console.WriteLine("                                            {0}", listingPrice.CurrencyCode);
                                            }
                                            if (listingPrice.IsSetAmount())
                                            {
                                                Console.WriteLine("                                        Amount");
                                                Console.WriteLine("                                            {0}", listingPrice.Amount);
                                            }
                                        }
                                        if (price.IsSetShipping())
                                        {
                                            Console.WriteLine("                                    Shipping");
                                            MoneyType shipping = price.Shipping;
                                            if (shipping.IsSetCurrencyCode())
                                            {
                                                Console.WriteLine("                                        CurrencyCode");
                                                Console.WriteLine("                                            {0}", shipping.CurrencyCode);
                                            }
                                            if (shipping.IsSetAmount())
                                            {
                                                Console.WriteLine("                                        Amount");
                                                Console.WriteLine("                                            {0}", shipping.Amount);
                                            }
                                        }
                                    }
                                }
                            }
                            if (competitivePricing.IsSetNumberOfOfferListings())
                            {
                                Console.WriteLine("                        NumberOfOfferListings");
                                NumberOfOfferListingsList    numberOfOfferListings = competitivePricing.NumberOfOfferListings;
                                List <OfferListingCountType> offerListingCountList = numberOfOfferListings.OfferListingCount;
                                foreach (OfferListingCountType offerListingCount in offerListingCountList)
                                {
                                    Console.WriteLine("                            OfferListingCount");
                                    if (offerListingCount.IsSetcondition())
                                    {
                                        Console.WriteLine("                        condition");
                                        Console.WriteLine();
                                        Console.WriteLine("                                {0}", offerListingCount.condition);
                                        Console.WriteLine();
                                    }
                                    if (offerListingCount.IsSetValue())
                                    {
                                        Console.WriteLine("                        Value");
                                        Console.WriteLine();
                                        Console.WriteLine("                                {0}", offerListingCount.Value);
                                    }
                                }
                            }
                            if (competitivePricing.IsSetTradeInValue())
                            {
                                Console.WriteLine("                        TradeInValue");
                                MoneyType tradeInValue = competitivePricing.TradeInValue;
                                if (tradeInValue.IsSetCurrencyCode())
                                {
                                    Console.WriteLine("                            CurrencyCode");
                                    Console.WriteLine("                                {0}", tradeInValue.CurrencyCode);
                                }
                                if (tradeInValue.IsSetAmount())
                                {
                                    Console.WriteLine("                            Amount");
                                    Console.WriteLine("                                {0}", tradeInValue.Amount);
                                }
                            }
                        }
                        if (product.IsSetSalesRankings())
                        {
                            Console.WriteLine("                    SalesRankings");
                            SalesRankList        salesRankings = product.SalesRankings;
                            List <SalesRankType> salesRankList = salesRankings.SalesRank;
                            foreach (SalesRankType salesRank in salesRankList)
                            {
                                Console.WriteLine("                        SalesRank");
                                if (salesRank.IsSetProductCategoryId())
                                {
                                    Console.WriteLine("                            ProductCategoryId");
                                    Console.WriteLine("                                {0}", salesRank.ProductCategoryId);
                                }
                                if (salesRank.IsSetRank())
                                {
                                    Console.WriteLine("                            Rank");
                                    Console.WriteLine("                                {0}", salesRank.Rank);
                                }
                            }
                        }
                        if (product.IsSetLowestOfferListings())
                        {
                            Console.WriteLine("                    LowestOfferListings");
                            LowestOfferListingList        lowestOfferListings    = product.LowestOfferListings;
                            List <LowestOfferListingType> lowestOfferListingList = lowestOfferListings.LowestOfferListing;
                            foreach (LowestOfferListingType lowestOfferListing in lowestOfferListingList)
                            {
                                Console.WriteLine("                        LowestOfferListing");
                                if (lowestOfferListing.IsSetQualifiers())
                                {
                                    Console.WriteLine("                            Qualifiers");
                                    QualifiersType qualifiers = lowestOfferListing.Qualifiers;
                                    if (qualifiers.IsSetItemCondition())
                                    {
                                        Console.WriteLine("                                ItemCondition");
                                        Console.WriteLine("                                    {0}", qualifiers.ItemCondition);
                                    }
                                    if (qualifiers.IsSetItemSubcondition())
                                    {
                                        Console.WriteLine("                                ItemSubcondition");
                                        Console.WriteLine("                                    {0}", qualifiers.ItemSubcondition);
                                    }
                                    if (qualifiers.IsSetFulfillmentChannel())
                                    {
                                        Console.WriteLine("                                FulfillmentChannel");
                                        Console.WriteLine("                                    {0}", qualifiers.FulfillmentChannel);
                                    }
                                    if (qualifiers.IsSetShipsDomestically())
                                    {
                                        Console.WriteLine("                                ShipsDomestically");
                                        Console.WriteLine("                                    {0}", qualifiers.ShipsDomestically);
                                    }
                                    if (qualifiers.IsSetShippingTime())
                                    {
                                        Console.WriteLine("                                ShippingTime");
                                        ShippingTimeType shippingTime = qualifiers.ShippingTime;
                                        if (shippingTime.IsSetMax())
                                        {
                                            Console.WriteLine("                                    Max");
                                            Console.WriteLine("                                        {0}", shippingTime.Max);
                                        }
                                    }
                                    if (qualifiers.IsSetSellerPositiveFeedbackRating())
                                    {
                                        Console.WriteLine("                                SellerPositiveFeedbackRating");
                                        Console.WriteLine("                                    {0}", qualifiers.SellerPositiveFeedbackRating);
                                    }
                                }
                                if (lowestOfferListing.IsSetNumberOfOfferListingsConsidered())
                                {
                                    Console.WriteLine("                            NumberOfOfferListingsConsidered");
                                    Console.WriteLine("                                {0}", lowestOfferListing.NumberOfOfferListingsConsidered);
                                }
                                if (lowestOfferListing.IsSetSellerFeedbackCount())
                                {
                                    Console.WriteLine("                            SellerFeedbackCount");
                                    Console.WriteLine("                                {0}", lowestOfferListing.SellerFeedbackCount);
                                }
                                if (lowestOfferListing.IsSetPrice())
                                {
                                    Console.WriteLine("                            Price");
                                    PriceType price1 = lowestOfferListing.Price;
                                    if (price1.IsSetLandedPrice())
                                    {
                                        Console.WriteLine("                                LandedPrice");
                                        MoneyType landedPrice1 = price1.LandedPrice;
                                        if (landedPrice1.IsSetCurrencyCode())
                                        {
                                            Console.WriteLine("                                    CurrencyCode");
                                            Console.WriteLine("                                        {0}", landedPrice1.CurrencyCode);
                                        }
                                        if (landedPrice1.IsSetAmount())
                                        {
                                            Console.WriteLine("                                    Amount");
                                            Console.WriteLine("                                        {0}", landedPrice1.Amount);
                                        }
                                    }
                                    if (price1.IsSetListingPrice())
                                    {
                                        Console.WriteLine("                                ListingPrice");
                                        MoneyType listingPrice1 = price1.ListingPrice;
                                        if (listingPrice1.IsSetCurrencyCode())
                                        {
                                            Console.WriteLine("                                    CurrencyCode");
                                            Console.WriteLine("                                        {0}", listingPrice1.CurrencyCode);
                                        }
                                        if (listingPrice1.IsSetAmount())
                                        {
                                            Console.WriteLine("                                    Amount");
                                            Console.WriteLine("                                        {0}", listingPrice1.Amount);
                                        }
                                    }
                                    if (price1.IsSetShipping())
                                    {
                                        Console.WriteLine("                                Shipping");
                                        MoneyType shipping1 = price1.Shipping;
                                        if (shipping1.IsSetCurrencyCode())
                                        {
                                            Console.WriteLine("                                    CurrencyCode");
                                            Console.WriteLine("                                        {0}", shipping1.CurrencyCode);
                                        }
                                        if (shipping1.IsSetAmount())
                                        {
                                            Console.WriteLine("                                    Amount");
                                            Console.WriteLine("                                        {0}", shipping1.Amount);
                                        }
                                    }
                                }
                                if (lowestOfferListing.IsSetMultipleOffersAtLowestPrice())
                                {
                                    Console.WriteLine("                            MultipleOffersAtLowestPrice");
                                    Console.WriteLine("                                {0}", lowestOfferListing.MultipleOffersAtLowestPrice);
                                }
                            }
                        }
                        if (product.IsSetOffers())
                        {
                            Console.WriteLine("                    Offers");
                            OffersList       offers    = product.Offers;
                            List <OfferType> offerList = offers.Offer;
                            foreach (OfferType offer in offerList)
                            {
                                Console.WriteLine("                        Offer");
                                if (offer.IsSetBuyingPrice())
                                {
                                    Console.WriteLine("                            BuyingPrice");
                                    PriceType buyingPrice = offer.BuyingPrice;
                                    if (buyingPrice.IsSetLandedPrice())
                                    {
                                        Console.WriteLine("                                LandedPrice");
                                        MoneyType landedPrice2 = buyingPrice.LandedPrice;
                                        if (landedPrice2.IsSetCurrencyCode())
                                        {
                                            Console.WriteLine("                                    CurrencyCode");
                                            Console.WriteLine("                                        {0}", landedPrice2.CurrencyCode);
                                        }
                                        if (landedPrice2.IsSetAmount())
                                        {
                                            Console.WriteLine("                                    Amount");
                                            Console.WriteLine("                                        {0}", landedPrice2.Amount);
                                        }
                                    }
                                    if (buyingPrice.IsSetListingPrice())
                                    {
                                        Console.WriteLine("                                ListingPrice");
                                        MoneyType listingPrice2 = buyingPrice.ListingPrice;
                                        if (listingPrice2.IsSetCurrencyCode())
                                        {
                                            Console.WriteLine("                                    CurrencyCode");
                                            Console.WriteLine("                                        {0}", listingPrice2.CurrencyCode);
                                        }
                                        if (listingPrice2.IsSetAmount())
                                        {
                                            Console.WriteLine("                                    Amount");
                                            Console.WriteLine("                                        {0}", listingPrice2.Amount);
                                        }
                                    }
                                    if (buyingPrice.IsSetShipping())
                                    {
                                        Console.WriteLine("                                Shipping");
                                        MoneyType shipping2 = buyingPrice.Shipping;
                                        if (shipping2.IsSetCurrencyCode())
                                        {
                                            Console.WriteLine("                                    CurrencyCode");
                                            Console.WriteLine("                                        {0}", shipping2.CurrencyCode);
                                        }
                                        if (shipping2.IsSetAmount())
                                        {
                                            Console.WriteLine("                                    Amount");
                                            Console.WriteLine("                                        {0}", shipping2.Amount);
                                        }
                                    }
                                }
                                if (offer.IsSetRegularPrice())
                                {
                                    Console.WriteLine("                            RegularPrice");
                                    MoneyType regularPrice = offer.RegularPrice;
                                    if (regularPrice.IsSetCurrencyCode())
                                    {
                                        Console.WriteLine("                                CurrencyCode");
                                        Console.WriteLine("                                    {0}", regularPrice.CurrencyCode);
                                    }
                                    if (regularPrice.IsSetAmount())
                                    {
                                        Console.WriteLine("                                Amount");
                                        Console.WriteLine("                                    {0}", regularPrice.Amount);
                                    }
                                }
                                if (offer.IsSetFulfillmentChannel())
                                {
                                    Console.WriteLine("                            FulfillmentChannel");
                                    Console.WriteLine("                                {0}", offer.FulfillmentChannel);
                                }
                                if (offer.IsSetItemCondition())
                                {
                                    Console.WriteLine("                            ItemCondition");
                                    Console.WriteLine("                                {0}", offer.ItemCondition);
                                }
                                if (offer.IsSetItemSubCondition())
                                {
                                    Console.WriteLine("                            ItemSubCondition");
                                    Console.WriteLine("                                {0}", offer.ItemSubCondition);
                                }
                                if (offer.IsSetSellerId())
                                {
                                    Console.WriteLine("                            SellerId");
                                    Console.WriteLine("                                {0}", offer.SellerId);
                                }
                                if (offer.IsSetSellerSKU())
                                {
                                    Console.WriteLine("                            SellerSKU");
                                    Console.WriteLine("                                {0}", offer.SellerSKU);
                                }
                            }
                        }
                    }
                    if (getLowestOfferListingsForASINResult.IsSetError())
                    {
                        Console.WriteLine("                Error");
                        Error error = getLowestOfferListingsForASINResult.Error;
                        if (error.IsSetType())
                        {
                            Console.WriteLine("                    Type");
                            Console.WriteLine("                        {0}", error.Type);
                        }
                        if (error.IsSetCode())
                        {
                            Console.WriteLine("                    Code");
                            Console.WriteLine("                        {0}", error.Code);
                        }
                        if (error.IsSetMessage())
                        {
                            Console.WriteLine("                    Message");
                            Console.WriteLine("                        {0}", error.Message);
                        }
                    }
                }
                if (response.IsSetResponseMetadata())
                {
                    Console.WriteLine("            ResponseMetadata");
                    ResponseMetadata responseMetadata = response.ResponseMetadata;
                    if (responseMetadata.IsSetRequestId())
                    {
                        Console.WriteLine("                RequestId");
                        Console.WriteLine("                    {0}", responseMetadata.RequestId);
                    }
                }
                Console.WriteLine("            ResponseHeaderMetadata");
                Console.WriteLine("                RequestId");
                Console.WriteLine("                    " + response.ResponseHeaderMetadata.RequestId);
                Console.WriteLine("                ResponseContext");
                Console.WriteLine("                    " + response.ResponseHeaderMetadata.ResponseContext);
                Console.WriteLine("                Timestamp");
                Console.WriteLine("                    " + response.ResponseHeaderMetadata.Timestamp);
                Console.WriteLine();
            }
            catch (MarketplaceWebServiceProductsException ex)
            {
                Console.WriteLine("Caught Exception: " + ex.Message);
                Console.WriteLine("Response Status Code: " + ex.StatusCode);
                Console.WriteLine("Error Code: " + ex.ErrorCode);
                Console.WriteLine("Error Type: " + ex.ErrorType);
                Console.WriteLine("Request ID: " + ex.RequestId);
                Console.WriteLine("XML: " + ex.XML);
                Console.WriteLine("ResponseHeaderMetadata: " + ex.ResponseHeaderMetadata);
            }
        }
Пример #4
0
        public static void InvokeGetLowestOfferListingsForASIN(MarketplaceWebServiceProducts service,
                                                               GetLowestOfferListingsForASINRequest request)
        {
            int newConditionCount  = 0;
            int usedConditionCount = 0;
            int totalOfferCount    = 0;

            try{
                GetLowestOfferListingsForASINResponse response = service.GetLowestOfferListingsForASIN(request);

                List <GetLowestOfferListingsForASINResult> getLowestOfferListingsForASINResultList =
                    response.GetLowestOfferListingsForASINResult;
                foreach (
                    GetLowestOfferListingsForASINResult getLowestOfferListingsForASINResult in
                    getLowestOfferListingsForASINResultList)
                {
                    if (getLowestOfferListingsForASINResult.IsSetProduct())
                    {
                        Product product = getLowestOfferListingsForASINResult.Product;

                        //Listing Price, shipping amount, conditions, and subconditions for new, used, all for the LOWEST 3.

                        if (product.IsSetLowestOfferListings())
                        {
                            LowestOfferListingList        lowestOfferListings    = product.LowestOfferListings;
                            List <LowestOfferListingType> lowestOfferListingList =
                                lowestOfferListings.LowestOfferListing;
                            foreach (LowestOfferListingType lowestOfferListing in lowestOfferListingList)
                            {
                                if (lowestOfferListing.IsSetQualifiers())
                                {
                                    QualifiersType qualifiers = lowestOfferListing.Qualifiers;
                                    PriceType      price      = lowestOfferListing.Price;

                                    if (qualifiers.IsSetItemCondition())
                                    {
                                        if (newConditionCount < 3)
                                        {
                                            if (qualifiers.ItemCondition.Equals("New"))
                                            {
                                                newConditions[newConditionCount] = qualifiers.ItemCondition;
                                                if (qualifiers.IsSetItemSubcondition())
                                                {
                                                    newSubConditions[newConditionCount] =
                                                        qualifiers.ItemSubcondition;
                                                }

                                                if (price.IsSetListingPrice())
                                                {
                                                    MoneyType listingPrice = price.ListingPrice;
                                                    newListingPrice[newConditionCount] =
                                                        Convert.ToString(listingPrice.Amount);
                                                }
                                                if (price.IsSetShipping())
                                                {
                                                    MoneyType shippingPrice = price.Shipping;
                                                    newShippingPrice[newConditionCount] =
                                                        Convert.ToString(shippingPrice.Amount);
                                                }

                                                Console.WriteLine(
                                                    "NewConditions: {0} NewSubCondition: {1} NewListingPrice {2} NewShippingPrice: {3}\n",
                                                    newConditions[newConditionCount],
                                                    newSubConditions[newConditionCount],
                                                    newListingPrice[newConditionCount],
                                                    newShippingPrice[newConditionCount]);
                                                newConditionCount++;
                                            }
                                        }
                                        if (usedConditionCount < 3)
                                        {
                                            if (qualifiers.ItemCondition.Equals("Used"))
                                            {
                                                usedConditions[usedConditionCount] = qualifiers.ItemCondition;
                                                if (qualifiers.IsSetItemSubcondition())
                                                {
                                                    usedSubConditions[usedConditionCount] =
                                                        qualifiers.ItemSubcondition;
                                                }
                                                if (price.IsSetListingPrice())
                                                {
                                                    MoneyType listingPrice = price.ListingPrice;
                                                    usedListingPrice[usedConditionCount] =
                                                        Convert.ToString(listingPrice.Amount);
                                                }
                                                if (price.IsSetShipping())
                                                {
                                                    MoneyType shippingPrice = price.Shipping;
                                                    usedShippingPrice[usedConditionCount] =
                                                        Convert.ToString(shippingPrice.Amount);
                                                }
                                                Console.WriteLine(
                                                    "UsedConditions: {0} UsedSubCondition: {1} UsedListingPrice {2} UsedShippingPrice: {3}\n",
                                                    usedConditions[usedConditionCount],
                                                    usedSubConditions[usedConditionCount],
                                                    usedListingPrice[usedConditionCount],
                                                    usedShippingPrice[usedConditionCount]);
                                                usedConditionCount++;
                                            }
                                        }
                                    }
                                    totalOfferCount++;
                                }
                            }
                        }
                    }
                }
                totalCount = Convert.ToString(totalOfferCount);
                Console.WriteLine("The Total Count: " + totalCount);
            }
            catch (MarketplaceWebServiceProductsException ex) {
                Console.WriteLine("Caught Exception: " + ex.Message);
                Console.WriteLine("Response Status Code: " + ex.StatusCode);
                Console.WriteLine("Error Code: " + ex.ErrorCode);
                Console.WriteLine("Error Type: " + ex.ErrorType);
                Console.WriteLine("Request ID: " + ex.RequestId);
                Console.WriteLine("XML: " + ex.XML);
                Console.WriteLine("ResponseHeaderMetadata: " + ex.ResponseHeaderMetadata);
            }
        }
Пример #5
0
        public List <Listing> GetAllListingsForAsin(IEnumerable <string> asins)
        {
            List <Listing> foundListings = new List <Listing>();

            foreach (IEnumerable <string> asinBatch in asins.Distinct().Batch(c_maxBatchAmount))
            {
                List <string> enumeratedASINs = asinBatch.ToList();

                List <GetLowestOfferListingsForASINResult> lowestOfferListingsResults = null;
                GetLowestOfferListingsForASINRequest       lowestOfferListingsRequest = new GetLowestOfferListingsForASINRequest
                {
                    ASINList = new ASINListType {
                        ASIN = enumeratedASINs
                    },
                    MarketplaceId = m_marketPlaceId,
                    SellerId      = m_sellerId
                };

                List <GetMatchingProductResult> matchingProductResult  = null;
                GetMatchingProductRequest       matchingProductRequest = new GetMatchingProductRequest
                {
                    ASINList = new ASINListType {
                        ASIN = enumeratedASINs
                    },
                    MarketplaceId = m_marketPlaceId,
                    SellerId      = m_sellerId
                };

                // Attempt 5 times to issue requests to Amazon, since throttling causes exceptions.
                for (int i = 0; i < 5; i++)
                {
                    try
                    {
                        GetLowestOfferListingsForASINResponse lowestOfferListingsResponse = m_productClient.GetLowestOfferListingsForASIN(lowestOfferListingsRequest);
                        lowestOfferListingsResults = lowestOfferListingsResponse.GetLowestOfferListingsForASINResult;

                        GetMatchingProductResponse matchingProductResponse = m_productClient.GetMatchingProduct(matchingProductRequest);
                        matchingProductResult = matchingProductResponse.GetMatchingProductResult;

                        // If we get to here without an exception, then we don't have to issue the request again.
                        break;
                    }
                    catch (MarketplaceWebServiceProductsException e)
                    {
                        Console.WriteLine(e.Message);
                        Thread.Sleep(10000);
                    }
                }

                if (lowestOfferListingsResults != null && matchingProductResult != null)
                {
                    foreach (string asin in enumeratedASINs)
                    {
                        GetLowestOfferListingsForASINResult lowestOfferListing = lowestOfferListingsResults
                                                                                 .Where(w => w.Product != null)
                                                                                 .FirstOrDefault(w => w.Product.Identifiers.MarketplaceASIN.ASIN == asin);

                        GetMatchingProductResult matchingProduct = matchingProductResult
                                                                   .Where(w => w.Product != null)
                                                                   .FirstOrDefault(f => f.Product.Identifiers.MarketplaceASIN.ASIN == asin);

                        if (lowestOfferListing != null && matchingProduct != null)
                        {
                            List <LowestOfferListingType> lowestofferListingTypes = lowestOfferListing
                                                                                    .Product
                                                                                    .LowestOfferListings
                                                                                    .LowestOfferListing;

                            int numberOfMerchantFulfilledOffers = lowestofferListingTypes
                                                                  .Where(w => w.Qualifiers.ItemCondition == "New")
                                                                  .Count(c => c.Qualifiers.FulfillmentChannel == FulfillmentChannel.Merchant.ToString());

                            int numberOfAmazonFulfilledOffers = lowestofferListingTypes
                                                                .Where(w => w.Qualifiers.ItemCondition == "New")
                                                                .Count(c => c.Qualifiers.FulfillmentChannel == FulfillmentChannel.Amazon.ToString());

                            decimal?lowestPrice = null;

                            if (lowestofferListingTypes.Any())
                            {
                                lowestPrice = lowestofferListingTypes
                                              .Where(w => w.Qualifiers.ItemCondition == "New")
                                              .Select(s => s.Price.ListingPrice.Amount + (s.Price.Shipping == null ? 0m : s.Price.Shipping.Amount))                           // s.Price.Shipping can be null.
                                              .Where(w => w > 0)
                                              .OrderBy(o => o)
                                              .FirstOrDefault();
                            }

                            var salesRank = matchingProduct
                                            .Product
                                            .SalesRankings
                                            .SalesRank
                                            .Select(s => new { Rank = (decimal?)s.Rank, ProductCategory = s.ProductCategoryId })
                                            .FirstOrDefault()
                                            ??
                                            new { Rank = (decimal?)null, ProductCategory = string.Empty };

                            foundListings.Add(new Listing
                            {
                                ASIN                            = asin,
                                SellersRank                     = salesRank.Rank,
                                SellersRankCategory             = salesRank.ProductCategory,
                                LowestPrice                     = lowestPrice,
                                NumberOfMerchantFulfilledOffers = numberOfMerchantFulfilledOffers,
                                NumberOfAmazonFulfilledOrders   = numberOfAmazonFulfilledOffers,
                            });
                        }
                    }
                }
            }

            return(foundListings);
        }