How to apply labels to ad groups (Google Ads API v1)?

230 views
Skip to first unread message

vgapites...@gmail.com

unread,
Apr 26, 2019, 6:14:22 AM4/26/19
to AdWords API and Google Ads API Forum
I'm working on a function that takes an existing label and applies it to selected ad groups (using their ad group ids). Not sure if I'm setting this up right since I keep getting exceptions, ex: 

NameValueType
Failure{{ "errors": [ { "errorCode": { "newResourceCreationError": "CANNOT_SET_ID_FOR_CREATE" }, "message": "Do not set the id field while creating new resources.", "trigger": { "int64Value": "1052616624" }, "location": { "fieldPathElements": [ { "fieldName": "operations", "index": "0" }, { "fieldName": "create" }, { "fieldName": "resource_name" } ] } } ] }}Google.Ads.GoogleAds.V1.Errors.GoogleAdsFailure

This is the resource name: "customers/9878485465/adGroupLabels/54654643~459484545"

Can someone take a look at this and tell me what I'm doing wrong


               
AdGroupLabel adGroupLabel = new AdGroupLabel();
                adGroupLabel
.ResourceName = ResourceNames.AdGroupLabel(long.Parse(client.Config.LoginCustomerId), id, long.Parse("459484545"));


               
// Create the operation.
               
AdGroupLabelOperation operation = new AdGroupLabelOperation()
               
{
                   
Create = adGroupLabel
               
};
               
//AdGroup adGroup = new AdGroup();
               
//adGroup.ResourceName = ResourceNames.AdGroup(client.Config.LoginCustomerId.ToString(),
               
//    id);


               
//AdGroupOperation operation = new AdGroupOperation()
               
//{
               
//    Update = adGroup,
               
//    UpdateMask = FieldMasks.AllSetFieldsOf(adGroup)
               
//};


               
try
               
{
                   
// Update the ad group.label
                   
MutateAdGroupLabelsResponse retVal = adGroupLabelService.MutateAdGroupLabels(
                        client
.Config.LoginCustomerId.ToString(), new AdGroupLabelOperation[] { operation });


                   
// Display the results.
                   
MutateAdGroupLabelResult adGroupLabelResult = retVal.Results[0];


                   
Console.WriteLine($"Ad group with resource name '{adGroupLabelResult.ResourceName}' " +
                       
"was updated.");
               
}
               
catch (GoogleAdsException e)
               
{
                   
Console.WriteLine("Failure:");
                   
Console.WriteLine($"Message: {e.Message}");
                   
Console.WriteLine($"Failure: {e.Failure}");
                   
Console.WriteLine($"Request ID: {e.RequestId}");
               
}
           
}

googleadsapi...@google.com

unread,
Apr 26, 2019, 3:16:48 PM4/26/19
to vgapites...@gmail.com, AdWords API and Google Ads API Forum
Hello Nyugen, 

Could you please share the API request and response logs for the operation that you're performing, to check this further? You can reply back via Reply privately to author option.

Regards,
Bharani, Google Ads API Team

=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and discussion group:
    https://ads-developers.googleblog.com/search/label/google_ads_api
    https://developers.google.com/adwords/api/community/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Reply all
Reply to author
Forward
0 new messages