/// <summary> /// Create a campaign group. /// </summary> /// <param name="user">The AdWords user.</param> /// <returns>The campaign group.</returns> private static CampaignGroup CreateCampaignGroup(AdWordsUser user) { using (CampaignGroupService campaignGroupService = (CampaignGroupService)user.GetService(AdWordsService.v201806.CampaignGroupService)) { // Create the campaign group. CampaignGroup campaignGroup = new CampaignGroup { name = "Mars campaign group - " + ExampleUtilities.GetShortRandomString() }; // Create the operation. CampaignGroupOperation operation = new CampaignGroupOperation { operand = campaignGroup, @operator = Operator.ADD }; try { CampaignGroupReturnValue retval = campaignGroupService.mutate( new CampaignGroupOperation[] { operation }); // Display the results. CampaignGroup newCampaignGroup = retval.value[0]; Console.WriteLine("Campaign group with ID = '{0}' and name = '{1}' was created.", newCampaignGroup.id, newCampaignGroup.name); return(newCampaignGroup); } catch (Exception e) { throw new System.ApplicationException("Failed to add campaign group.", e); } } }
/// <summary> /// Creates a new CampaignGroup in the specified client account. /// </summary> /// <param name="client">The Google Ads API client.</param> /// <param name="customerId">The Google Ads customer ID for which the call is made.</param> /// <returns>resource name of the newly created campaign group.</returns> private static String CreateCampaignGroup(GoogleAdsClient client, long customerId) { CampaignGroupServiceClient campaignGroupService = client.GetService( Services.V0.CampaignGroupService); CampaignGroup campaignGroup = new CampaignGroup() { Name = "Mars campaign group #" + ExampleUtilities.GetRandomString() }; CampaignGroupOperation op = new CampaignGroupOperation() { Create = campaignGroup }; MutateCampaignGroupsResponse response = campaignGroupService.MutateCampaignGroups( customerId.ToString(), new CampaignGroupOperation[] { op }); String groupResourceName = response.Results[0].ResourceName; Console.WriteLine($"Added campaign group with resource name: {groupResourceName}"); return(groupResourceName); }