My favorites | English | Sign in

Documentation for the requested version is not available.Documentation for the requested diff is not available.

AdGroupService

Link to this version

AdGroupService provides operations for accessing, modifying, and creating ad groups.

More Information

Requests

addAdGroup

Creates a new ad group.

Parameters

campaignID int
Campaign to which the new ad group will belong.
newData AdGroup
Data for the new ad group.
  • If status is not present, 'Enabled' is used.
  • If name is not present, a default name of the form "Ad Group #n" is used.
  • If the parent campaign uses CPC bidding, then only keywordContentMaxCpc, keywordMaxCpc, and siteMaxCpc can be set. Similarly, if the parent campaign uses CPM bidding, then only siteMaxCpm can be set.
  • The ID field is ignored; ID is set by AdGroupService.

Response

AdGroup The new ad group with all values (including IDs) filled in.

Samples

Code sample not available.
57
58
59
60
61
62
63
64
      // Create new ad group structure.
      int campaignId = Integer.parseInt("INSERT_CAMPAIGN_ID_HERE");
      AdGroup adGroup = new AdGroup();
      adGroup.setName("Sample Ad Group");
      adGroup.setKeywordMaxCpc(new Long(100000));

      // Add ad group.
      adGroup = service.addAdGroup(campaignId, adGroup);

Code sample not available.
55
56
57
58
59
60
61
62
63
        // Create new ad group structure.
        int campaignId = int.Parse("INSERT_CAMPAIGN_ID_HERE");
        AdGroup adGroup = new AdGroup();
        adGroup.name = "Sample Ad Group";
        adGroup.keywordMaxCpc = 100000L;
        adGroup.keywordMaxCpcSpecified = true;

        // Add ad group.
        adGroup = service.addAdGroup(campaignId, adGroup);

Code sample not available.
61
62
63
64
65
66
67
68
69
70
# Create new ad group structure.
my $campaign_id = SOAP::Data->name('campaignID' => 'INSERT_CAMPAIGN_ID_HERE');
my $ad_group = SOAP::Data->name('newData' => {
  'name' => 'Sample Ad Group',
  'keywordMaxCpc' => 100000
});

# Add ad group.
$ad_group = $service->call('addAdGroup' => $campaign_id, $ad_group,
                           @headers)->result();

Code sample not available.
48
49
50
51
52
53
54
55
56
# Create new ad group structure.
campaign_id = int('INSERT_CAMPAIGN_ID_HERE')
ad_group = {
  'name': 'Sample Ad Group',
  'keywordMaxCpc': SOAPpy.Types.untypedType('100000')
}

# Add ad group.
ad_group = ad_group_service.addAdGroup(campaign_id, ad_group)

Code sample not available.
64
65
66
67
68
69
70
71
72
73
74
75
76
# Create new ad group structure.
campaign_id = 'INSERT_CAMPAIGN_ID_HERE'.to_i
ad_group = {
  :campaignId => SOAP::SOAPNil.new,
  :id => SOAP::SOAPNil.new,
  :name => 'Sample Ad Group',
  :keywordMaxCpc => 100000,
  :status => 'Enabled',
}

# Add ad group.
ad_group = ad_group_service.addAdGroup(:campaignID => campaign_id,
  :newData => ad_group).addAdGroupReturn

Code sample not available.
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# Create new ad group structure.
$campaign_id = 'INSERT_CAMPAIGN_ID_HERE';
$ad_group_xml =
  '<newData>' .
  '<name>Sample Ad Group</name><keywordMaxCpc>100000</keywordMaxCpc>' .
  '</newData>';
$request_xml =
  '<addAdGroup>' .
  '<campaignId>' . $campaign_id . '</campaignId>' .
  $ad_group_xml .
  '</addAdGroup>';

# Add ad group.
$ad_group = $ad_group_service->call('addAdGroup', $request_xml);
$ad_group = $ad_group['addAdGroupReturn'];

Code sample not available.
12
13
14
15
16
17
18
19
20
    <!-- Creates a new ad group given an existing campaign. -->
    <addAdGroup>
      <campaignID>INSERT_CAMPAIGN_ID_HERE</campaignID>
      <newData>
        <keywordMaxCpc>100000</keywordMaxCpc>
        <name>Sample Ad Group</name>
        <status>Enabled</status>
      </newData>
    </addAdGroup>

Select a programming language to view its sample

addAdGroupList

Adds multiple ad groups to a campaign.

Parameters

campaignID int
Campaign to which the new ad groups will belong.
newData AdGroup[]
Data for each of the new ad groups. See addAdGroup for details.

Response

AdGroup[] Array of new AdGroup objects, with all values (including IDs) filled in.

getActiveAdGroups +v13

Returns all information about active ad groups associated with a campaign.

Parameters

campaignID int
ID of the campaign whose ad groups will be retrieved.

Response

AdGroup[] Array of AdGroup data objects, each representing an ad group.

getAdGroup

Returns information about the specified ad group

Parameters

adGroupId long
ID of the ad group to return

Response

AdGroup a structure with the ad group data

getAdGroupList

Returns information about multiple ad groups.

Parameters

adgroupIDs long[]
IDs of the ad groups to return

Response

AdGroup[] Array of AdGroup data objects, each representing an ad group. The returned objects will be in the same order as their IDs in the input array.

getAdGroupStats

Get statistics for a list of ad groups in a campaign. See StatsRecord for details about the statistics returned. The time granularity is one day, and is always with respect to the account's local timezone.

Parameters

campaignId int
The campaign in which to find the ad groups
adGroupIds long[]
The ad groups whose statistics are being queried
startDay date
The starting day of the period for which statistics are to be collected (xsd:date).
endDay date
The ending day of the period for which statistics are to be collected, inclusive (xsd:date).

Response

StatsRecord[] an array of StatsRecords containing information about the activity on the ad groups. The order of StatsRecord objects returned may be different from the order in which the IDs were requested.

getAllAdGroups

Returns all information about the ad groups associated with a campaign.

Parameters

campaignID int
ID of the campaign whose ad groups will be retrieved.

Response

AdGroup[] Array of AdGroup objects, each representing an ad group.

Samples

Code sample not available.
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
      // Get all campaigns.
      Campaign[] campaigns = campaignService.getAllAdWordsCampaigns(0);

      int count = 0;

      if (campaigns != null) {
        for (Campaign campaign : campaigns) {
          // Get all ad groups.
          AdGroup[] adGroups = adGroupService.getAllAdGroups(campaign.getId());

          if (adGroups != null) {
            for (AdGroup adGroup : adGroups) {
              // Get all criteria.
              Criterion[] criteria =
                  criterionService.getAllCriteria(adGroup.getId());

Code sample not available.
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
        // Get all campaigns.
        Campaign[] campaigns = campaignService.getAllAdWordsCampaigns(0);

        int count = 0;

        if (campaigns != null) {
          for (int i = 0; i < campaigns.Length; i++) {
            // Get all ad groups.
            AdGroup[] adGroups = adGroupService.getAllAdGroups(campaigns[i].id);

            if (adGroups != null) {
              for (int j = 0; j < adGroups.Length; j++) {
                // Get all criteria.
                Criterion[] criteria =
                    criterionService.getAllCriteria(adGroups[j].id);

Code sample not available.
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# Get all campaigns.
my $dummy = SOAP::Data->name('dummy' => 0);
my $response = $campaign_service->call('getAllAdWordsCampaigns' => $dummy,
  @headers);
my @campaigns = ($response->result(), $response->paramsout());

my $count = 0;
foreach my $campaign (@campaigns) {
  # Get all ad groups.
  my $campaign_id = SOAP::Data->name('campaignID' => $campaign->{'id'});
  $response = $ad_group_service->call('getAllAdGroups' => $campaign_id,
    @headers);
  my @ad_groups = ($response->result(), $response->paramsout());

  for my $ad_group (@ad_groups) {
    # Get all criteria.
    my $ad_group_id = SOAP::Data->name('adGroupId' => $ad_group->{'id'});
    $response = $criterion_service->call('getAllCriteria' => $ad_group_id,
      @headers);
    my @criteria = ($response->result(), $response->paramsout());

Code sample not available.
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# Get all campaigns.
campaigns = campaign_service.getAllAdWordsCampaigns(0)

# Convert to a list if we get back a single object.
if len(campaigns) > 0 and not isinstance(campaigns, list):
  campaigns = [campaigns]

count = 0
for campaign in campaigns:
  # Get all ad groups.
  ad_groups = ad_group_service.getAllAdGroups(int(campaign['id']))

  # Convert to a list if we get back a single object.
  if len(ad_groups) > 0 and not isinstance(ad_groups, list):
    ad_groups = [ad_groups]

  for ad_group in ad_groups:
    # Get all criteria.
    criteria = criterion_service.getAllCriteria(
        SOAPpy.Types.untypedType(str(ad_group['id'])))

Code sample not available.
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# Get all campaigns.
campaigns = campaign_service.getAllAdWordsCampaigns(:dummy => 0
  ).getAllAdWordsCampaignsReturn

# Convert to a list if we get back a single object.
if ! campaigns.respond_to?('each')
  campaigns = [campaigns]
end

count = 0
campaigns.each do |campaign|
  # Get all ad groups.
  ad_groups = ad_group_service.getAllAdGroups(:campaignID => campaign['id'])
  if ad_groups.respond_to?('getAllAdGroupsReturn')
    ad_groups = ad_groups.getAllAdGroupsReturn
  end

  # Convert to a list if we get back a single object.
  if ! ad_groups.respond_to?('each')
    ad_groups = [ad_groups]
  end

  ad_groups.each do |ad_group|
    # Get all criteria.
    criteria = criterion_service.getAllCriteria(:adGroupId => ad_group['id'])
    if criteria.respond_to?('getAllCriteriaReturn')
      criteria = criteria.getAllCriteriaReturn

Code sample not available.
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# Get all campaigns.
$request_xml =
  '<getAllAdWordsCampaigns><dummy>0</dummy></getAllAdWordsCampaigns>';
$campaigns = $campaign_service->call('getAllAdWordsCampaigns', $request_xml);
$campaigns = $campaigns['getAllAdWordsCampaignsReturn'];
if ($debug) show_xml($campaign_service);
if ($campaign_service->fault) show_fault($campaign_service);

# Convert to a list if we get back a single object.
if (!$campaigns[0]) {
  $campaigns = array($campaigns);
}

$count = 0;
for ($i = 0; $i < count($campaigns); $i++) {
  if (!$campaigns[$i]) {
    continue;
  }

  # Get all ad groups.
  $request_xml =
    '<getAllAdGroups>' .
    '<campaignId>' . $campaigns[$i]['id'] . '</campaignId>' .
    '</getAllAdGroups>';
  $ad_groups = $ad_group_service->call('getAllAdGroups', $request_xml);
  $ad_groups = $ad_groups['getAllAdGroupsReturn'];
  if ($debug) show_xml($ad_group_service);
  if ($ad_group_service->fault) show_fault($ad_group_service);

  # Convert to a list if we get back a single object.
  if (!$ad_groups[0]) {
    $ad_groups = array($ad_groups);
  }

  for ($j = 0; $j < count($ad_groups); $j++) {
    if (!$ad_groups[$j]) {
      continue;
    }

    # Get all criteria.
    $request_xml =
      '<getAllCriteria>' .
      '<adGroupId>' . $ad_groups[$j]['id'] . '</adGroupId>' .
      '</getAllCriteria>';
    $criteria = $criterion_service->call('getAllCriteria', $request_xml);
    $criteria = $criteria['getAllCriteriaReturn'];

Code sample not available.
12
13
14
15
    <!-- Retrieves info about all ad groups given an existing campaign. -->
    <getAllAdGroups>
      <campaignID>INSERT_CAMPAIGN_ID_HERE</campaignID>
    </getAllAdGroups>

Select a programming language to view its sample

updateAdGroup

Updates an existing ad group.

Parameters

changedData AdGroup
Data to update. The ad group whose ID matches changedData.id will be updated with the values specified in changedData. name, status, and the bid-related fields are mutable; id is immutable. Omitted fields will be left unchanged.

Response

(none)

updateAdGroupList

Updates multiple existing ad groups.

Parameters

changedData AdGroup[]
List of ad groups to update. See updateAdGroup for details.

Response

(none)