2016-04-15 78 views
3

在我的應用我想通過C#的API添加品牌和MPN現有eBay的項目,所以,我運行代碼:如何將品牌添加到現有的易趣項目?

 string eCommerceID = (dr["eCommerceID"] ?? "").ToString().Trim(); 
     string upc = (dr["UPC"] ?? "").ToString().Trim(); 
     string manufacturerName = (dr["ManufacturerName"] ?? "").ToString().Trim(); 
     string brandMPN = (dr["BrandMPN"] ?? "").ToString().Trim(); 

     ReviseItemRequestType reviseItemRequestType = new ReviseItemRequestType(); 
     reviseItemRequestType.Version = version; 
     reviseItemRequestType.Item = new ItemType(); 
     reviseItemRequestType.Item.ItemID = eCommerceID; 
     reviseItemRequestType.Item.ProductListingDetails = new ProductListingDetailsType(); 
     reviseItemRequestType.Item.ProductListingDetails.UPC = upc; 

     reviseItemRequestType.Item.ProductListingDetails.BrandMPN = new BrandMPNType(); 
     reviseItemRequestType.Item.ProductListingDetails.BrandMPN.Brand = manufacturerName; 
     reviseItemRequestType.Item.ProductListingDetails.BrandMPN.MPN = brandMPN; 

     ReviseItemResponseType reviseItemResponseType = ebayService.ReviseItem(reviseItemRequestType); 

但是當我執行此代碼,易趣將返回錯誤:

「品牌特定品牌缺失。將品牌添加到此列表,輸入有效值,然後重試。「

我在做什麼錯了?

感謝任何幫助。謝謝。

enter image description here

錯誤: enter image description here

回答

4

由於錯誤消息說:

The item specific Brand is missing

不要在您的要求使用Item.ProductListingDetails.BrandMPN。相反,您需要創建兩個名爲Band和MPN的Item Specifics

<ItemSpecifics> 
    <NameValueList> 
     <Name>Brand</Name> 
     <Value>[BRAND VALUE]</Value> 
    </NameValueList> 
    <NameValueList> 
     <Name>MPN</Name> 
     <Value>[MPN VALUE]</Value> 
    </NameValueList> 
</ItemSpecifics> 
+0

它的作品,謝謝! – ihorko

3

這裏是C#溶液的複製粘貼代碼段。

ItemType itemType = new ItemType(); // = class eBay.Service.Core.Soap.ItemType 
Int32 condCodeAsInt = 1000; // upto you to derrive this from your use case. 
String myBrandValue = "Some BRAND"; 
String myMpnValue = "some MPN"; 
String myUpcValue = "Does not apply"; 

....

//if condition is "New" or "New with Details" then we need to set extra REQUIRED fields 

      if (condCodeAsInt == 1000 || condCodeAsInt == 1500) 
      { 

       //if it is "new" then remove inputted desc text completely REQUIRED 
       if (condCodeAsInt == 1000) 
       { 
        itemType.ConditionDescription = ""; 
       } 

       // set UPC value HERE, not in ItemSpecifics. 
       ProductListingDetailsType pldt = new ProductListingDetailsType(); 
       pldt.UPC = myUpcValue; 

       itemType.ProductListingDetails = pldt; 

       //init Item specifics (and set BRAND and MPN) 
       itemType.ItemSpecifics = new NameValueListTypeCollection(); 

       //brand 
       NameValueListType nvBrand = new NameValueListType(); 
       nvBrand.Name = "Brand"; 
       StringCollection brandStringCol = new StringCollection(); 
       brandStringCol.Add(myBrandValue); 
       nvBrand.Value = brandStringCol; 

       itemType.ItemSpecifics.Add(nvBrand); 

       //MPN 
       NameValueListType nvMpn = new NameValueListType(); 
       nvMpn.Name = "MPN"; 
       StringCollection mpnStringCol = new StringCollection(); 
       mpnStringCol.Add(myMpnValue); 
       nvMpn.Value = mpnStringCol; 

       itemType.ItemSpecifics.Add(nvMpn); 

      } 
相關問題