2016-04-15 62 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); 

      } 
相关问题