Hi, 

I am getting internal error when trying to upload the product group tree of 
ad groups. It seems no matter what way this is done it throws the same 
error. Is there anyway to get a more useful error to know why it is failing 
or is the issue just google end? I have attached the code i am using.

Thanks,

Darren




-- 
-- 
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog:
https://googleadsdeveloper.blogspot.com/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

You received this message because you are subscribed to the Google
Groups "AdWords API and Google Ads API Forum" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/adwords-api?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Google Ads API and AdWords API Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/adwords-api/87bdb475-cbc1-4c00-9963-72b722e3c69bn%40googlegroups.com.
public GoogleAwApi.AdGroupCriterionReturnValue 
MutateProductPartitionsForAdGroupGA(GoogleAwApi.AdGroupCriterionOperation[] 
operations, long clientId)
    {
        var result = new GoogleAwApi.AdGroupCriterionReturnValue();

        AdGroupCriterionServiceClient service = this.AdGroupCriterionServiceGA;

        List<AdGroupCriterionOperation> operationsGA = new 
List<AdGroupCriterionOperation>();
        List<GoogleAwApi.AdGroupCriterion> results = new 
List<GoogleAwApi.AdGroupCriterion>();
        List<GoogleAwApi.ApiError> partialFailures = new 
List<GoogleAwApi.ApiError>();

        foreach (var item in operations)
        {
            try
            {
                var operand = 
(GoogleAwApi.BiddableAdGroupCriterion)item.operand;
                // Start creating the criteron...
                GoogleAdsResources.AdGroupCriterion adGroupCriterion = new 
GoogleAdsResources.AdGroupCriterion()
                {
                    // The resource name the criterion will be created with. 
This will define the ID
                    // for the ad group criterion.
                    AdGroup = ResourceNames.AdGroup(clientId, 
item.operand.adGroupId),
                    //ResourceName = ResourceNames.AdGroupCriterion(clientId, 
item.operand.adGroupId, item.operand.criterion.id),
                    Status = 
Google.Ads.GoogleAds.V10.Enums.AdGroupCriterionStatusEnum.Types.AdGroupCriterionStatus.Enabled
                };

                switch (operand.userStatus)
                {
                    case GoogleAwApi.UserStatus.ENABLED:
                        adGroupCriterion.Status = 
AdGroupCriterionStatusEnum.Types.AdGroupCriterionStatus.Enabled;
                        break;
                    case GoogleAwApi.UserStatus.REMOVED:
                        adGroupCriterion.Status = 
AdGroupCriterionStatusEnum.Types.AdGroupCriterionStatus.Removed;
                        break;
                    case GoogleAwApi.UserStatus.PAUSED:
                        adGroupCriterion.Status = 
AdGroupCriterionStatusEnum.Types.AdGroupCriterionStatus.Paused;
                        break;
                    default:
                        adGroupCriterion.Status = 
AdGroupCriterionStatusEnum.Types.AdGroupCriterionStatus.Enabled;
                        break;
                }
                string cType = item.operand.criterion.GetType().Name;

                if (operand.biddingStrategyConfiguration != null)
                {
                    var bids = operand.biddingStrategyConfiguration.bids;
                    var thidBid = (GoogleAwApi.CpcBid)bids[0];
                    adGroupCriterion.CpcBidMicros = thidBid.bid.microAmount;
                    adGroupCriterion.EffectiveCpcBidSource = 
Google.Ads.GoogleAds.V10.Enums.BiddingSourceEnum.Types.BiddingSource.AdGroup;
                }

                adGroupCriterion.ApprovalStatus = 
APIHelper.MapApprovalStatus(operand.approvalStatus);
                adGroupCriterion.BidModifier = operand.bidModifier;
                var criterion = 
(GoogleAwApi.ProductPartition)item.operand.criterion;
                adGroupCriterion.CriterionId = criterion.id;

                ListingGroupTypeEnum.Types.ListingGroupType lType = 
ListingGroupTypeEnum.Types.ListingGroupType.Unknown;
                if (criterion.partitionType == 
GoogleAwApi.ProductPartitionType.SUBDIVISION)
                {
                    lType = 
ListingGroupTypeEnum.Types.ListingGroupType.Subdivision;
                    adGroupCriterion.ResourceName = 
ResourceNames.AdGroupCriterion(clientId, item.operand.adGroupId, 
item.operand.criterion.id);
                }
                if (criterion.partitionType == 
GoogleAwApi.ProductPartitionType.UNIT)
                { 
                    lType = ListingGroupTypeEnum.Types.ListingGroupType.Unit;
                }
                var casevalue = 
(GoogleAwApi.ProductDimension)criterion.caseValue;
                var lLevel = 
Google.Ads.GoogleAds.V10.Enums.ProductTypeLevelEnum.Types.ProductTypeLevel.Unknown;
                var cIndex = 
Google.Ads.GoogleAds.V10.Enums.ProductCustomAttributeIndexEnum.Types.ProductCustomAttributeIndex.Unknown;
                var lValue = "";
                Google.Ads.GoogleAds.V10.Common.ListingDimensionInfo 
listingDimensionInfo = null;
                if (casevalue != null)
                {
                    //Get listing Group Info
                    switch (casevalue.ProductDimensionType)
                    {
                        case "ProductType":
                            if (casevalue != null)
                            {
                                string[] caseValueItems = 
casevalue.ToString().Split(',');
                                if (caseValueItems.Length == 2)
                                {
                                    if 
(caseValueItems[0].Contains("PRODUCT_TYPE_L1"))
                                        lLevel = 
Google.Ads.GoogleAds.V10.Enums.ProductTypeLevelEnum.Types.ProductTypeLevel.Level1;
                                    if 
(caseValueItems[0].Contains("PRODUCT_TYPE_L2"))
                                        lLevel = 
Google.Ads.GoogleAds.V10.Enums.ProductTypeLevelEnum.Types.ProductTypeLevel.Level2;
                                    if 
(caseValueItems[0].Contains("PRODUCT_TYPE_L3"))
                                        lLevel = 
Google.Ads.GoogleAds.V10.Enums.ProductTypeLevelEnum.Types.ProductTypeLevel.Level3;
                                    if 
(caseValueItems[0].Contains("PRODUCT_TYPE_L4"))
                                        lLevel = 
Google.Ads.GoogleAds.V10.Enums.ProductTypeLevelEnum.Types.ProductTypeLevel.Level4;
                                    if 
(caseValueItems[0].Contains("PRODUCT_TYPE_L5"))
                                        lLevel = 
Google.Ads.GoogleAds.V10.Enums.ProductTypeLevelEnum.Types.ProductTypeLevel.Level5;
                                    string[] lValueItems = 
caseValueItems[1].Split(':');
                                    if (lValueItems.Length == 2)
                                        lValue = lValueItems[1].Trim();

                                    if (String.IsNullOrEmpty(lValue))
                                    {
                                        //isEverythingElse
                                        listingDimensionInfo = new 
Google.Ads.GoogleAds.V10.Common.ListingDimensionInfo()
                                        {
                                            ProductType = new 
Google.Ads.GoogleAds.V10.Common.ProductTypeInfo
                                            { Level = lLevel }
                                        };
                                    }
                                    listingDimensionInfo = new 
Google.Ads.GoogleAds.V10.Common.ListingDimensionInfo()
                                    {
                                        ProductType = new 
Google.Ads.GoogleAds.V10.Common.ProductTypeInfo
                                        { Level = lLevel, Value = lValue }
                                    };
                                }
                            }
                            break;
                        case "Brand":
                            if (casevalue != null)
                            {
                                string[] caseValueItems = 
casevalue.ToString().Split(',');
                                if (caseValueItems.Length == 2)
                                {
                                    string[] lValueItems = 
caseValueItems[1].Split(':');
                                    if (lValueItems.Length == 2)
                                        lValue = lValueItems[1].Trim();
                                }
                                if (caseValueItems.Length == 1)
                                {
                                    string[] lValueItems = 
caseValueItems[0].Split(':');
                                    if (lValueItems.Length == 2)
                                        lValue = lValueItems[1].Trim();
                                }

                                //isEverythingElse
                                if (String.IsNullOrEmpty(lValue))
                                {
                                    listingDimensionInfo = new 
Google.Ads.GoogleAds.V10.Common.ListingDimensionInfo()
                                    {
                                        ProductBrand = new 
Google.Ads.GoogleAds.V10.Common.ProductBrandInfo()
                                    };
                                }
                                else
                                {
                                    listingDimensionInfo = new 
Google.Ads.GoogleAds.V10.Common.ListingDimensionInfo()
                                    {
                                        ProductBrand = new 
Google.Ads.GoogleAds.V10.Common.ProductBrandInfo
                                        { Value = lValue }
                                    };
                                }
                            }
                            break;
                        case "Custom":
                            if (casevalue != null)
                            {
                                string[] caseValueItems = 
casevalue.ToString().Split(',');
                                if (caseValueItems.Length == 2)
                                {
                                    if 
(caseValueItems[0].Contains("CUSTOM_ATTRIBUTE_0"))
                                        cIndex = 
Google.Ads.GoogleAds.V10.Enums.ProductCustomAttributeIndexEnum.Types.ProductCustomAttributeIndex.Index0;
                                    if 
(caseValueItems[0].Contains("CUSTOM_ATTRIBUTE_1"))
                                        cIndex = 
Google.Ads.GoogleAds.V10.Enums.ProductCustomAttributeIndexEnum.Types.ProductCustomAttributeIndex.Index1;
                                    if 
(caseValueItems[0].Contains("CUSTOM_ATTRIBUTE_2"))
                                        cIndex = 
Google.Ads.GoogleAds.V10.Enums.ProductCustomAttributeIndexEnum.Types.ProductCustomAttributeIndex.Index2;
                                    if 
(caseValueItems[0].Contains("CUSTOM_ATTRIBUTE_3"))
                                        cIndex = 
Google.Ads.GoogleAds.V10.Enums.ProductCustomAttributeIndexEnum.Types.ProductCustomAttributeIndex.Index3;
                                    if 
(caseValueItems[0].Contains("CUSTOM_ATTRIBUTE_4"))
                                        cIndex = 
Google.Ads.GoogleAds.V10.Enums.ProductCustomAttributeIndexEnum.Types.ProductCustomAttributeIndex.Index4;
                                    string[] lValueItems = 
caseValueItems[1].Split(':');
                                    if (lValueItems.Length == 2)
                                        lValue = lValueItems[1].Trim();

                                    if (String.IsNullOrEmpty(lValue))
                                    {
                                        //isEverythingElse
                                        listingDimensionInfo = new 
Google.Ads.GoogleAds.V10.Common.ListingDimensionInfo()
                                        {
                                            ProductCustomAttribute = new 
Google.Ads.GoogleAds.V10.Common.ProductCustomAttributeInfo
                                            { Index = cIndex }
                                        };
                                    }
                                    else
                                    {
                                        listingDimensionInfo = new 
Google.Ads.GoogleAds.V10.Common.ListingDimensionInfo()
                                        {
                                            ProductCustomAttribute = new 
Google.Ads.GoogleAds.V10.Common.ProductCustomAttributeInfo
                                            { Index = cIndex, Value = lValue }
                                        };
                                    }
                                }
                            }
                            break;
                        case "OfferId":
                            if (casevalue != null)
                            {
                                string[] caseValueItems = 
casevalue.ToString().Split(',');
                                if (caseValueItems.Length == 2)
                                {
                                    string[] lValueItems = 
caseValueItems[1].Split(':');
                                    if (lValueItems.Length == 2)
                                        lValue = lValueItems[1].Trim();
                                }
                                if (caseValueItems.Length == 1)
                                {
                                    string[] lValueItems = 
caseValueItems[0].Split(':');
                                    if (lValueItems.Length == 2)
                                        lValue = lValueItems[1].Trim();
                                }

                                if (String.IsNullOrEmpty(lValue))
                                {
                                    //isEverythingElse
                                    listingDimensionInfo = new 
Google.Ads.GoogleAds.V10.Common.ListingDimensionInfo()
                                    {
                                        ProductItemId = new 
Google.Ads.GoogleAds.V10.Common.ProductItemIdInfo()
                                    };
                                }
                                else
                                {
                                    listingDimensionInfo = new 
Google.Ads.GoogleAds.V10.Common.ListingDimensionInfo()
                                    {
                                        ProductItemId = new 
Google.Ads.GoogleAds.V10.Common.ProductItemIdInfo
                                        { Value = lValue }
                                    };
                                }
                            }
                            break;
                        default:
                            break;
                    }
                }

                Google.Ads.GoogleAds.V10.Common.ListingGroupInfo ListingGroup = 
new Google.Ads.GoogleAds.V10.Common.ListingGroupInfo()
                {
                    Type = lType,  // SubDivision OR Unit
                    CaseValue = listingDimensionInfo                        
                };

                if (criterion.id != -1)
                    ListingGroup.ParentAdGroupCriterion = 
ResourceNames.AdGroupCriterion(clientId, item.operand.adGroupId, 
criterion.parentCriterionId);

                adGroupCriterion.ListingGroup = ListingGroup;
                adGroupCriterion.CriterionId = criterion.id;

                if (item.@operator == GoogleAwApi.Operator.ADD) { 
operationsGA.Add(new AdGroupCriterionOperation() { Create = adGroupCriterion 
}); }
                if (item.@operator == GoogleAwApi.Operator.REMOVE) { 
operationsGA.Add(new AdGroupCriterionOperation() { Remove = 
adGroupCriterion.ResourceName }); }
                if (item.@operator == GoogleAwApi.Operator.SET) { 
operationsGA.Add(new AdGroupCriterionOperation() { Update = adGroupCriterion 
}); }

            }
            catch (Exception ex)
            {
                string except = ex.Message;
            }
        }

        try
        {
            // Issues a mutate request to process Ads.
            MutateAdGroupCriteriaResponse retVal = 
service.MutateAdGroupCriteria(
                new MutateAdGroupCriteriaRequest()
                {
                    CustomerId = clientId.ToString(),
                    Operations = { operationsGA },
                    PartialFailure = true,
                    ValidateOnly = false,
                    ResponseContentType = 
ResponseContentTypeEnum.Types.ResponseContentType.MutableResource // required 
to bring back a complete mutated object to report on.
                });

            if (retVal.Results[0].AdGroupCriterion != null)
                
results.Add(APIHelper.MapAdGroupCriterion(retVal.Results[0].AdGroupCriterion));

            if (retVal.PartialFailureError != null)
            {
                var ApiError = new ApiErrorGA();
                ApiError.errorString = retVal.PartialFailureError.Message;
                ApiError.ApiErrorType = 
retVal.PartialFailureError.GetType().ToString();
                partialFailures.Add(ApiError);
            }
        }
        catch (GoogleAdsException ex)
        {
            string except = ex.Message;
        }
        result.ListReturnValueType = "AdGroupAdService";
        result.value = results.ToArray();
        result.partialFailureErrors = partialFailures.ToArray();

        return result;
    }
  • In... BrillDaza
    • ... 'Google Ads API Forum Advisor' via Google Ads API and AdWords API Forum

Reply via email to