Share your feedback about the AdWords API! Take our annual survey.

Basic Operations Samples

The code samples below provide examples of basic operations using the AdWords API. Client Library.

Add ad groups to a campaign

#!/usr/bin/perl -w
#
# Copyright 2017, Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# This example adds ad groups to a campaign. To get campaigns, run
# get_all_campaigns.pl.

use strict;
use lib "../../../lib";
use utf8;

use Google::Ads::AdWords::Client;
use Google::Ads::AdWords::Logging;
use Google::Ads::AdWords::v201809::AdGroup;
use Google::Ads::AdWords::v201809::AdGroupAdRotationMode;
use Google::Ads::AdWords::v201809::AdGroupOperation;
use Google::Ads::AdWords::v201809::BiddingStrategyConfiguration;
use Google::Ads::AdWords::v201809::CpcBid;
use Google::Ads::AdWords::v201809::Money;
use Google::Ads::AdWords::v201809::TargetingSetting;
use Google::Ads::AdWords::v201809::TargetingSettingDetail;

use Cwd qw(abs_path);
use Data::Uniqid qw(uniqid);

# Replace with valid values of your account.
my $campaign_id = "INSERT_CAMPAIGN_ID_HERE";

# Example main subroutine.
sub add_ad_groups {
  my ($client, $campaign_id) = @_;

  my @operations = ();

  # Create ad group.
  my $ad_group = Google::Ads::AdWords::v201809::AdGroup->new({
    name       => sprintf("Earth to Mars Cruises #%s", uniqid()),
    status     => "ENABLED",
    campaignId => $campaign_id
  });

  # Optional settings.

  # Restricting to serve ads that match your ad group placements.
  # This is equivalent to choosing "Target and bid" in the UI.
  my $placements = Google::Ads::AdWords::v201809::TargetingSettingDetail->new({
    criterionTypeGroup => "PLACEMENT",
    targetAll          => 0
  });

  # Using your ad group verticals only for bidding. This is equivalent
  # to choosing "Bid only" in the UI.
  my $verticals = Google::Ads::AdWords::v201809::TargetingSettingDetail->new({
    criterionTypeGroup => "VERTICAL",
    targetAll          => 1
  });

  # Targeting restriction settings. Depending on the criterionTypeGroup value,
  # most TargetingSettingDetail only affect Display campaigns. However, the
  # USER_INTEREST_AND_LIST value works for RLSA campaigns - Search campaigns
  # targeting using a remarketing list.
  my $targeting = Google::Ads::AdWords::v201809::TargetingSetting->new({
      details => [$placements, $verticals]});
  $ad_group->set_settings([$targeting]);

  # Set the rotation mode.
  my $rotation_mode = Google::Ads::AdWords::v201809::AdGroupAdRotationMode->new(
    {
      adRotationMode => 'OPTIMIZE'
    });
  $ad_group->set_adGroupAdRotationMode($rotation_mode);

  # Create ad group bid.
  my $bidding_strategy_configuration =
    Google::Ads::AdWords::v201809::BiddingStrategyConfiguration->new({
      bids => [
        Google::Ads::AdWords::v201809::CpcBid->new({
            bid => Google::Ads::AdWords::v201809::Money->new({
                microAmount => 1000000
              }
            ),
          }
        ),
      ]});
  $ad_group->set_biddingStrategyConfiguration($bidding_strategy_configuration);

  # Add as many additional ad groups as you need.
  my $ad_group_2 = Google::Ads::AdWords::v201809::AdGroup->new({
    name       => sprintf("Earth to Mars Cruises #%s", uniqid()),
    status     => "ENABLED",
    campaignId => $campaign_id
  });

  my $bidding_strategy_configuration_2 =
    Google::Ads::AdWords::v201809::BiddingStrategyConfiguration->new({
      bids => [
        Google::Ads::AdWords::v201809::CpcBid->new({
            bid => Google::Ads::AdWords::v201809::Money->new({
                microAmount => 1000000
              }
            ),
          }
        ),
      ]});
  $ad_group_2->set_biddingStrategyConfiguration(
    $bidding_strategy_configuration_2);

  # Create operations.
  my $operation = Google::Ads::AdWords::v201809::AdGroupOperation->new({
    operator => "ADD",
    operand  => $ad_group
  });
  push @operations, $operation;
  my $operation_2 = Google::Ads::AdWords::v201809::AdGroupOperation->new({
    operator => "ADD",
    operand  => $ad_group_2
  });
  push @operations, $operation_2;

  # Add ad groups.
  my $result = $client->AdGroupService()->mutate({operations => \@operations});

  # Display ad groups.
  foreach my $ad_group (@{$result->get_value()}) {
    printf "Ad group with name \"%s\" and ID %d was added.\n",
      $ad_group->get_name(), $ad_group->get_id();
  }

  return 1;
}

# Don't run the example if the file is being included.
if (abs_path($0) ne abs_path(__FILE__)) {
  return 1;
}

# Log SOAP XML request, response and API errors.
Google::Ads::AdWords::Logging::enable_all_logging();

# Get AdWords Client, credentials will be read from ~/adwords.properties.
my $client = Google::Ads::AdWords::Client->new({version => "v201809"});

# By default examples are set to die on any server returned fault.
$client->set_die_on_faults(1);

# Call the example
add_ad_groups($client, $campaign_id);

Add campaigns

#!/usr/bin/perl -w
#
# Copyright 2017, Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# This example adds campaigns.

use strict;
use lib "../../../lib";
use utf8;

use Google::Ads::AdWords::Client;
use Google::Ads::AdWords::Logging;
use Google::Ads::AdWords::v201809::BiddingStrategyConfiguration;
use Google::Ads::AdWords::v201809::Budget;
use Google::Ads::AdWords::v201809::BudgetOperation;
use Google::Ads::AdWords::v201809::Campaign;
use Google::Ads::AdWords::v201809::CampaignOperation;
use Google::Ads::AdWords::v201809::FrequencyCap;
use Google::Ads::AdWords::v201809::GeoTargetTypeSetting;
use Google::Ads::AdWords::v201809::ManualCpcBiddingScheme;
use Google::Ads::AdWords::v201809::Money;
use Google::Ads::AdWords::v201809::NetworkSetting;

use Cwd qw(abs_path);
use Data::Uniqid qw(uniqid);

sub add_campaigns {
  my $client = shift;
  # Create a budget, which can be shared by multiple campaigns.
  my $budget = Google::Ads::AdWords::v201809::Budget->new({
      # Required attributes.
      name => "Interplanetary budget #" . uniqid(),
      amount =>
        Google::Ads::AdWords::v201809::Money->new({microAmount => 5000000}),
      deliveryMethod => "STANDARD"
  });

  my $budget_operation = Google::Ads::AdWords::v201809::BudgetOperation->new({
      operator => "ADD",
      operand  => $budget
  });

  # Add budget.
  my $budgetId =
    $client->BudgetService()->mutate({operations => ($budget_operation)})
    ->get_value()->get_budgetId()->get_value();

  # Create campaigns.
  my $num_campaigns = 2;
  my @operations    = ();
  for (my $i = 0 ; $i < $num_campaigns ; $i++) {
    my (undef, undef, undef, $mday, $mon, $year) = localtime(time);
    my $today = sprintf("%d%02d%02d", ($year + 1900), ($mon + 1), $mday);
    (undef, undef, undef, $mday, $mon, $year) = localtime(time + 60 * 60 * 24);
    my $tomorrow = sprintf("%d%02d%02d", ($year + 1900), ($mon + 1), $mday);
    my $campaign = Google::Ads::AdWords::v201809::Campaign->new({
        name => "Interplanetary Cruise #" . uniqid(),
        # Bidding strategy (required).
        biddingStrategyConfiguration =>
          Google::Ads::AdWords::v201809::BiddingStrategyConfiguration->new({
            biddingStrategyType => "MANUAL_CPC",
            # You can optionally provide a bidding scheme in place of the type.
          }
          ),
        # Budget (required) - note only the budgetId is required.
        budget =>
          Google::Ads::AdWords::v201809::Budget->new({budgetId => $budgetId}),
        # Create a Search Network with Display Select campaign.
        # To create a Display Only campaign, omit networkSetting and use the
        # DISPLAY advertisingChannelType.
        # NetworkSetting (optional).
        networkSetting => Google::Ads::AdWords::v201809::NetworkSetting->new({
            targetGoogleSearch         => 1,
            targetSearchNetwork        => 1,
            targetContentNetwork       => 1,
            targetPartnerSearchNetwork => 0
          }
        ),
        # Advertising channel type (required).
        advertisingChannelType => "SEARCH",
        # Frequency cap (non-required).
        frequencyCap => Google::Ads::AdWords::v201809::FrequencyCap->new({
            impressions => 5,
            timeUnit    => "DAY",
            level       => "ADGROUP"
          }
        ),
        settings => [
          # Advanced location targeting settings (non-required).
          Google::Ads::AdWords::v201809::GeoTargetTypeSetting->new({
              positiveGeoTargetType => "DONT_CARE",
              negativeGeoTargetType => "DONT_CARE"
            }
          ),
        ],
        # Additional properties (non-required).
        startDate                   => $today,
        endDate                     => $tomorrow,
        # Recommendation: Set the campaign to PAUSED when creating it to stop
        # the ads from immediately serving. Set to ENABLED once you've added
        # targeting and the ads are ready to serve.
        status                      => "PAUSED"
      });

    # Create operation.
    my $campaign_operation =
      Google::Ads::AdWords::v201809::CampaignOperation->new({
        operator => "ADD",
        operand  => $campaign
      });
    push @operations, $campaign_operation;
  }

  # Add campaigns.
  my $result = $client->CampaignService()->mutate({operations => \@operations});

  # Display campaigns.
  foreach my $campaign (@{$result->get_value()}) {
    printf "Campaign with name \"%s\" and id \"%s\" was added.\n",
      $campaign->get_name(), $campaign->get_id();
  }

  return 1;
}

# Don't run the example if the file is being included.
if (abs_path($0) ne abs_path(__FILE__)) {
  return 1;
}

# Log SOAP XML request, response and API errors.
Google::Ads::AdWords::Logging::enable_all_logging();

# Get AdWords Client, credentials will be read from ~/adwords.properties.
my $client = Google::Ads::AdWords::Client->new({version => "v201809"});

# By default examples are set to die on any server returned fault.
$client->set_die_on_faults(1);

# Call the example
add_campaigns($client);

Add expanded text ads to an ad group

#!/usr/bin/perl -w
#
# Copyright 2017, Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# This code example adds expanded text ads to a given ad group.
# To get ad groups, run get_ad_groups.pl.

use strict;
use lib "../../../lib";
use utf8;

use Google::Ads::AdWords::Client;
use Google::Ads::AdWords::Logging;
use Google::Ads::AdWords::v201809::AdGroupAd;
use Google::Ads::AdWords::v201809::AdGroupAdOperation;
use Google::Ads::AdWords::v201809::ExpandedTextAd;

use Cwd qw(abs_path);
use Data::Uniqid qw(uniqid);

# Replace with valid values of your account.
my $ad_group_id = "INSERT_AD_GROUP_ID_HERE";

# Example main subroutine.
sub add_expanded_text_ads {
  my $client      = shift;
  my $ad_group_id = shift;

  my $num_ads    = 5;
  my @operations = ();
  for (my $i = 0 ; $i < $num_ads ; $i++) {
    # Create expanded text ad.
    my $expanded_text_ad = Google::Ads::AdWords::v201809::ExpandedTextAd->new({
        headlinePart1 => "Cruise to Mars #" . substr(uniqid(), 0, 8),
        headlinePart2 => "Best Space Cruise Line",
        headlinePart3 => "For Your Loved Ones",
        description   => "Buy your tickets now!",
        description2  => "Discount ends soon",
        finalUrls     => ["http://www.example.com/" . $i],
        path1         => "all-inclusive",
        path2         => "deals"
    });

    # Create ad group ad for the expanded text ad.
    my $ad_group_ad = Google::Ads::AdWords::v201809::AdGroupAd->new({
        adGroupId => $ad_group_id,
        ad        => $expanded_text_ad,
        # Additional properties (non-required).
        status => "PAUSED"
    });

    # Create operation.
    my $ad_group_ad_operation =
      Google::Ads::AdWords::v201809::AdGroupAdOperation->new({
        operator => "ADD",
        operand  => $ad_group_ad
      });
    push @operations, $ad_group_ad_operation;
  }

  # Add expanded text ad.
  my $result =
    $client->AdGroupAdService()->mutate({operations => \@operations});

  # Display results.
  if ($result->get_value()) {
    foreach my $ad_group_ad (@{$result->get_value()}) {
      printf "Expanded text ad with ID %d and " .
        "headline '%s | %s%s' was added.\n",
        $ad_group_ad->get_ad()->get_id(),
        $ad_group_ad->get_ad()->get_headlinePart1(),
        $ad_group_ad->get_ad()->get_headlinePart2(),
        ((defined($ad_group_ad->get_ad()->get_headlinePart3()))
            ? (' | ' . $ad_group_ad->get_ad()->get_headlinePart3()) : '');
    }
  } else {
    print "No expanded text ads were added.\n";
  }

  return 1;
}

# Don't run the example if the file is being included.
if (abs_path($0) ne abs_path(__FILE__)) {
  return 1;
}

# Log SOAP XML request, response and API errors.
Google::Ads::AdWords::Logging::enable_all_logging();

# Get AdWords Client, credentials will be read from ~/adwords.properties.
my $client = Google::Ads::AdWords::Client->new({version => "v201809"});

# By default examples are set to die on any server returned fault.
$client->set_die_on_faults(1);

# Call the example
add_expanded_text_ads($client, $ad_group_id);

Add keywords to an ad group

#!/usr/bin/perl -w
#
# Copyright 2017, Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# This example adds multiple keywords to an ad group. To get ad groups run
# basic_operations/get_ad_groups.pl.

use strict;
use lib "../../../lib";
use utf8;

use Google::Ads::AdWords::Client;
use Google::Ads::AdWords::Logging;
use Google::Ads::AdWords::v201809::AdGroupCriterionOperation;
use Google::Ads::AdWords::v201809::BiddableAdGroupCriterion;
use Google::Ads::AdWords::v201809::BiddingStrategyConfiguration;
use Google::Ads::AdWords::v201809::CpcBid;
use Google::Ads::AdWords::v201809::Keyword;
use Google::Ads::AdWords::v201809::Money;
use Google::Ads::AdWords::v201809::Placement;
use Google::Ads::AdWords::v201809::UrlList;

use Cwd qw(abs_path);
use Data::Uniqid qw(uniqid);
use URI::Escape qw(uri_escape);

# Replace with valid values of your account.
my $ad_group_id = "INSERT_AD_GROUP_ID_HERE";

# Example main subroutine.
sub add_keywords {
  my $client      = shift;
  my $ad_group_id = shift;
  # Create keywords.
  my @keywords = ("mars cruise", "space hotel");

  # Create operations.
  my @operations = ();
  foreach my $keyword_text (@keywords) {
    my $keyword = Google::Ads::AdWords::v201809::Keyword->new({
        text      => $keyword_text,
        matchType => "BROAD"
    });

    # Create biddable ad group criterion.
    my $final_url =
      'http://www.example.com/mars/cruise/?kw=' . uri_escape($keyword_text);
    my $keyword_biddable_ad_group_criterion =
      Google::Ads::AdWords::v201809::BiddableAdGroupCriterion->new({
        adGroupId => $ad_group_id,
        criterion => $keyword,
        # Set bids (non-required).
        biddingStrategyConfiguration =>
          Google::Ads::AdWords::v201809::BiddingStrategyConfiguration->new({
            bids => [
              Google::Ads::AdWords::v201809::CpcBid->new({
                  bid => Google::Ads::AdWords::v201809::Money->new(
                    {microAmount => 500000})}
              ),
            ]}
          ),
        # Additional properties (non-required).
        userStatus => "PAUSED",
        finalUrls =>
          [Google::Ads::AdWords::v201809::UrlList->new({urls => [$final_url]})]}
      );

    # Create operation.
    my $keyword_ad_group_operation =
      Google::Ads::AdWords::v201809::AdGroupCriterionOperation->new({
        operator => "ADD",
        operand  => $keyword_biddable_ad_group_criterion
      });
    push @operations, $keyword_ad_group_operation;
  }

  # Add ad group criteria.
  my $result =
    $client->AdGroupCriterionService()->mutate({operations => \@operations});

  # Display ad group criteria.
  if ($result->get_value()) {
    foreach my $keyword (@{$result->get_value()}) {
      printf "Keyword with ad group id \"%d\", id \"%d\", " .
        "text \"%s\" and match type \"%s\" was added.\n",
        $keyword->get_adGroupId(),
        $keyword->get_criterion()->get_id(),
        $keyword->get_criterion()->get_text(),
        $keyword->get_criterion()->get_matchType();
    }
  } else {
    print "No keywords were added.";
  }

  return 1;
}

# Don't run the example if the file is being included.
if (abs_path($0) ne abs_path(__FILE__)) {
  return 1;
}

# Log SOAP XML request, response and API errors.
Google::Ads::AdWords::Logging::enable_all_logging();

# Get AdWords Client, credentials will be read from ~/adwords.properties.
my $client = Google::Ads::AdWords::Client->new({version => "v201809"});

# By default examples are set to die on any server returned fault.
$client->set_die_on_faults(1);

# Call the example
add_keywords($client, $ad_group_id);

Add a responsive search ad to an ad group

#!/usr/bin/perl -w
#
# Copyright 2018 Google LLC
#
# License:: Licensed under the Apache License, Version 2.0 (the "License");
#           you may not use this file except in compliance with the License.
#           You may obtain a copy of the License at
#
#           http://www.apache.org/licenses/LICENSE-2.0
#
#           Unless required by applicable law or agreed to in writing, software
#           distributed under the License is distributed on an "AS IS" BASIS,
#           WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
#           implied.
#           See the License for the specific language governing permissions and
#           limitations under the License.
#
# This example adds a responsive search ad to a given ad group.
# To get ad groups, run get_ad_groups.pl.

use strict;
use lib "../../../lib";
use utf8;

use Google::Ads::AdWords::Client;
use Google::Ads::AdWords::Logging;
use Google::Ads::AdWords::v201809::AdGroupAd;
use Google::Ads::AdWords::v201809::AdGroupAdOperation;
use Google::Ads::AdWords::v201809::AssetLink;
use Google::Ads::AdWords::v201809::ResponsiveSearchAd;
use Google::Ads::AdWords::v201809::TextAsset;

use Cwd qw(abs_path);
use Data::Uniqid qw(uniqid);

# Replace with valid values of your account.
my $ad_group_id = "INSERT_AD_GROUP_ID_HERE";

# Example main subroutine.
sub add_responsive_search_ad {
  my ($client, $ad_group_id) = @_;

  my $responsive_search_ad =
      Google::Ads::AdWords::v201809::ResponsiveSearchAd->new({
      headlines    => [
          Google::Ads::AdWords::v201809::AssetLink->new({
              asset       => Google::Ads::AdWords::v201809::TextAsset->new({
                  assetText => "Cruise to Mars #" . substr(uniqid(), 0, 8)
              }),
              pinnedField => "HEADLINE_1"
          }),
          Google::Ads::AdWords::v201809::AssetLink->new({
              asset => Google::Ads::AdWords::v201809::TextAsset->new({
                  assetText => "Best Space Cruise Line"
              }),
          }),
          Google::Ads::AdWords::v201809::AssetLink->new({
              asset => Google::Ads::AdWords::v201809::TextAsset->new({
                  assetText => "Experience the Stars"
              }),
          }) ],
      descriptions => [
          Google::Ads::AdWords::v201809::AssetLink->new({
              asset => Google::Ads::AdWords::v201809::TextAsset->new({
                  assetText => "Buy your tickets now"
              }),
          }),
          Google::Ads::AdWords::v201809::AssetLink->new({
              asset => Google::Ads::AdWords::v201809::TextAsset->new({
                  assetText => "Visit the Red Planet"
              })
          })
      ],
      finalUrls    => [ "http://www.example.com/cruise" ],
      path1        => "all-inclusive",
      path2        => "deals"
  });

  my $ad_group_ad = Google::Ads::AdWords::v201809::AdGroupAd->new({
      adGroupId => $ad_group_id,
      ad        => $responsive_search_ad,
      # Additional properties (non-required).
      status    => "PAUSED"
  });

  # Create operation.
  my $operation =
      Google::Ads::AdWords::v201809::AdGroupAdOperation->new({
          operator => "ADD",
          operand  => $ad_group_ad
      });

  # Add ad.
  my $result =
      $client->AdGroupAdService()->mutate({ operations => [ $operation ] });
  if ($result->get_value()) {
    foreach my $ad_group_ad (@{$result->get_value()}) {
      printf "New responsive search ad with ID %d was added.\n",
          $ad_group_ad->get_ad()->get_id();
      printf "  Headlines:\n";
      foreach my $headline (@{$ad_group_ad->get_ad()->get_headlines()}) {
        my $pinned = $headline->get_pinnedField();
        printf "    %s\n", $headline->get_asset()->get_assetText();
        if ($pinned) {
          printf "      (pinned to %s)\n", $pinned;
        }
      }
      printf "  Descriptions:\n";
      foreach my $description (@{$ad_group_ad->get_ad()->get_descriptions()}) {
        my $pinned = $description->get_pinnedField();
        printf "    %s\n", $description->get_asset()->get_assetText();
        if ($pinned) {
          printf "      (pinned to %s)\n", $pinned;
        }
      }
    }
  }
  else {
    print "No ads were added.\n";
  }

  return 1;
}

# Don't run the example if the file is being included.
if (abs_path($0) ne abs_path(__FILE__)) {
  return 1;
}

# Log SOAP XML request, response and API errors.
Google::Ads::AdWords::Logging::enable_all_logging();

# Get AdWords Client, credentials will be read from ~/adwords.properties.
my $client = Google::Ads::AdWords::Client->new({ version => "v201809" });

# By default examples are set to die on any server returned fault.
$client->set_die_on_faults(1);

# Call the example
add_responsive_search_ad($client, $ad_group_id);

Get the ad groups of a campaign

#!/usr/bin/perl -w
#
# Copyright 2017, Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# This example gets all ad groups in a campaign. To add ad groups, run
# basic_operations/add_ad_group.pl. To get campaigns, run
# basic_operations/get_campaigns.pl.

use strict;
use lib "../../../lib";
use utf8;

use Google::Ads::AdWords::Client;
use Google::Ads::AdWords::Logging;
use Google::Ads::AdWords::v201809::OrderBy;
use Google::Ads::AdWords::v201809::Paging;
use Google::Ads::AdWords::v201809::Predicate;
use Google::Ads::AdWords::v201809::Selector;
use Google::Ads::AdWords::Utilities::PageProcessor;

use constant PAGE_SIZE => 500;

# Replace with valid values of your account.
my $campaign_id = "INSERT_CAMPAIGN_ID_HERE";

use Cwd qw(abs_path);

# Example main subroutine.
sub get_ad_groups {
  my $client      = shift;
  my $campaign_id = shift;

  # Create predicates.
  my $campaign_predicate = Google::Ads::AdWords::v201809::Predicate->new({
      field    => "CampaignId",
      operator => "IN",
      values   => [$campaign_id]});

  # Create selector.
  my $paging = Google::Ads::AdWords::v201809::Paging->new({
      startIndex    => 0,
      numberResults => PAGE_SIZE
  });
  my $selector = Google::Ads::AdWords::v201809::Selector->new({
      fields     => ["Id", "Name"],
      predicates => [$campaign_predicate],
      ordering   => [
        Google::Ads::AdWords::v201809::OrderBy->new({
            field     => "Name",
            sortOrder => "ASCENDING"
          })
      ],
      paging => $paging
    });

  # Paginate through results.
  # The contents of the subroutine will be executed for each ad group.
  Google::Ads::AdWords::Utilities::PageProcessor->new({
      client   => $client,
      service  => $client->AdGroupService(),
      selector => $selector
    }
    )->process_entries(
    sub {
      my ($ad_group) = @_;
      printf "Ad group with name \"%s\" and id \"%d\" was found.\n",
        $ad_group->get_name(), $ad_group->get_id();
    });

  return 1;
}

# Don't run the example if the file is being included.
if (abs_path($0) ne abs_path(__FILE__)) {
  return 1;
}

# Log SOAP XML request, response and API errors.
Google::Ads::AdWords::Logging::enable_all_logging();

# Get AdWords Client, credentials will be read from ~/adwords.properties.
my $client = Google::Ads::AdWords::Client->new({version => "v201809"});

# By default examples are set to die on any server returned fault.
$client->set_die_on_faults(1);

# Call the example
get_ad_groups($client, $campaign_id);

Get all campaigns

#!/usr/bin/perl -w
#
# Copyright 2017, Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# This example gets all campaigns. To add a campaign, run
# basic_operations/add_campaign.pl.

use strict;
use lib "../../../lib";
use utf8;

use Google::Ads::AdWords::Client;
use Google::Ads::AdWords::Logging;
use Google::Ads::AdWords::v201809::OrderBy;
use Google::Ads::AdWords::v201809::Paging;
use Google::Ads::AdWords::v201809::Predicate;
use Google::Ads::AdWords::v201809::Selector;
use Google::Ads::AdWords::Utilities::PageProcessor;

use constant PAGE_SIZE => 500;

use Cwd qw(abs_path);

# Example main subroutine.
sub get_campaigns {
  my $client = shift;

  # Create selector.
  my $paging = Google::Ads::AdWords::v201809::Paging->new({
      startIndex    => 0,
      numberResults => PAGE_SIZE
  });
  my $selector = Google::Ads::AdWords::v201809::Selector->new({
      fields   => ["Id", "Name"],
      ordering => [
        Google::Ads::AdWords::v201809::OrderBy->new({
            field     => "Name",
            sortOrder => "ASCENDING"
          })
      ],
      paging => $paging
    });

  # Paginate through results.
  # The contents of the subroutine will be executed for each campaign.
  Google::Ads::AdWords::Utilities::PageProcessor->new({
      client   => $client,
      service  => $client->CampaignService(),
      selector => $selector
    }
    )->process_entries(
    sub {
      my ($campaign) = @_;
      printf "Campaign with name \"%s\" and id \"%d\" was found.\n",
        $campaign->get_name(), $campaign->get_id();
    });

  return 1;
}

# Don't run the example if the file is being included.
if (abs_path($0) ne abs_path(__FILE__)) {
  return 1;
}

# Log SOAP XML request, response and API errors.
Google::Ads::AdWords::Logging::enable_all_logging();

# Get AdWords Client, credentials will be read from ~/adwords.properties.
my $client = Google::Ads::AdWords::Client->new({version => "v201809"});

# By default examples are set to die on any server returned fault.
$client->set_die_on_faults(1);

# Call the example
get_campaigns($client);

Get all campaigns using AWQL

#!/usr/bin/perl -w
#
# Copyright 2017, Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# This example gets all campaigns using AWQL. To add a campaign, run
# basic_operations/add_campaign.pl.

use strict;
use lib "../../../lib";
use utf8;

use Google::Ads::AdWords::Client;
use Google::Ads::AdWords::Logging;
use Google::Ads::AdWords::v201809::OrderBy;
use Google::Ads::AdWords::v201809::Paging;
use Google::Ads::AdWords::v201809::Predicate;
use Google::Ads::AdWords::v201809::Selector;
use Google::Ads::AdWords::Utilities::PageProcessor;
use Google::Ads::AdWords::Utilities::ServiceQueryBuilder;

use constant PAGE_SIZE => 500;

use Cwd qw(abs_path);

# Example main subroutine.
sub get_campaigns_with_awql {
  my $client = shift;

  # Get all the campaigns for this account.
  my $query =
    Google::Ads::AdWords::Utilities::ServiceQueryBuilder->new(
    {client => $client})
    ->select(["Id", "Name", "Status"])
    ->order_by("Name")
    ->build();

  # Paginate through results.
  # The contents of the subroutine will be executed for each campaign.
  Google::Ads::AdWords::Utilities::PageProcessor->new({
      client    => $client,
      service   => $client->CampaignService(),
      query     => $query,
      page_size => PAGE_SIZE
    }
    )->process_entries(
    sub {
      my ($campaign) = @_;
      printf "Campaign with name \"%s\" and id \"%d\" was found.\n",
        $campaign->get_name(), $campaign->get_id();
    });

  return 1;
}

# Don't run the example if the file is being included.
if (abs_path($0) ne abs_path(__FILE__)) {
  return 1;
}

# Log SOAP XML request, response and API errors.
Google::Ads::AdWords::Logging::enable_all_logging();

# Get AdWords Client, credentials will be read from ~/adwords.properties.
my $client = Google::Ads::AdWords::Client->new({version => "v201809"});

# By default examples are set to die on any server returned fault.
$client->set_die_on_faults(1);

# Call the example
get_campaigns_with_awql($client);

Get expanded text ads in an ad group

#!/usr/bin/perl -w
#
# Copyright 2017, Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# This example gets non-removed expanded text ads in an ad group. To add
# expanded text ads, run add_expanded_text_ads.pl.
# To get ad groups, run get_ad_groups.pl.

use strict;
use lib "../../../lib";
use utf8;

use Google::Ads::AdWords::Client;
use Google::Ads::AdWords::Logging;
use Google::Ads::AdWords::v201809::OrderBy;
use Google::Ads::AdWords::v201809::Paging;
use Google::Ads::AdWords::v201809::Predicate;
use Google::Ads::AdWords::v201809::Selector;
use Google::Ads::AdWords::Utilities::PageProcessor;

use constant PAGE_SIZE => 500;

use Cwd qw(abs_path);

# Replace with valid values of your account.
my $ad_group_id = "INSERT_AD_GROUP_ID_HERE";

# Example main subroutine.
sub get_expanded_text_ads {
  my $client      = shift;
  my $ad_group_id = shift;

  # Create predicates.
  my $ad_group_predicate = Google::Ads::AdWords::v201809::Predicate->new({
      field    => "AdGroupId",
      operator => "IN",
      values   => [$ad_group_id]});
  my $status_predicate = Google::Ads::AdWords::v201809::Predicate->new({
      field    => "Status",
      operator => "IN",
      values   => ["ENABLED", "PAUSED"]});
  my $ad_type_predicate = Google::Ads::AdWords::v201809::Predicate->new({
      field    => "AdType",
      operator => "EQUALS",
      values   => ["EXPANDED_TEXT_AD"]});

  # Create selector.
  my $paging = Google::Ads::AdWords::v201809::Paging->new({
      startIndex    => 0,
      numberResults => PAGE_SIZE
  });
  my $selector = Google::Ads::AdWords::v201809::Selector->new({
      fields =>
        ["Id", "Status", "HeadlinePart1", "HeadlinePart2", "Description"],
      predicates =>
        [$ad_group_predicate, $status_predicate, $ad_type_predicate],
      ordering => [
        Google::Ads::AdWords::v201809::OrderBy->new({
            field     => "Id",
            sortOrder => "ASCENDING"
          })
      ],
      paging => $paging
    });

  # Paginate through results.
  # The contents of the subroutine will be executed for each text ad.
  Google::Ads::AdWords::Utilities::PageProcessor->new({
      client   => $client,
      service  => $client->AdGroupAdService(),
      selector => $selector
    }
    )->process_entries(
    sub {
      my ($ad_group_ad) = @_;
      printf "Expanded text ad with id \"%d\", status \"%s\", and " .
        "headline \"%s - %s\" was found.\n",
        $ad_group_ad->get_ad()->get_id(),
        $ad_group_ad->get_status(),
        $ad_group_ad->get_ad()->get_headlinePart1(),
        $ad_group_ad->get_ad()->get_headlinePart2();
    });

  return 1;
}

# Don't run the example if the file is being included.
if (abs_path($0) ne abs_path(__FILE__)) {
  return 1;
}

# Log SOAP XML request, response and API errors.
Google::Ads::AdWords::Logging::enable_all_logging();

# Get AdWords Client, credentials will be read from ~/adwords.properties.
my $client = Google::Ads::AdWords::Client->new({version => "v201809"});

# By default examples are set to die on any server returned fault.
$client->set_die_on_faults(1);

# Call the example
get_expanded_text_ads($client, $ad_group_id);

Get keywords in an ad group

#!/usr/bin/perl -w
#
# Copyright 2017, Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# This example gets keywords in an ad group. To add keywords, run
# basic_operations/add_keywords.pl. To get ad groups, run
# basic_operations/get_ad_groups.pl.

use strict;
use lib "../../../lib";
use utf8;

use Google::Ads::AdWords::Client;
use Google::Ads::AdWords::Logging;
use Google::Ads::AdWords::v201809::OrderBy;
use Google::Ads::AdWords::v201809::Paging;
use Google::Ads::AdWords::v201809::Predicate;
use Google::Ads::AdWords::v201809::Selector;
use Google::Ads::AdWords::Utilities::PageProcessor;

use Cwd qw(abs_path);

use constant PAGE_SIZE => 500;

# Replace with valid values of your account.
my $ad_group_id = "INSERT_AD_GROUP_ID_HERE";

# Example main subroutine.
sub get_keywords {
  my $client      = shift;
  my $ad_group_id = shift;

  # Create selector.
  my $ad_group_id_predicate = Google::Ads::AdWords::v201809::Predicate->new({
      field    => "AdGroupId",
      operator => "IN",
      values   => [$ad_group_id]});
  my $criteria_type_predicate = Google::Ads::AdWords::v201809::Predicate->new({
      field    => "CriteriaType",
      operator => "EQUALS",
      values   => ["KEYWORD"]});
  my $paging = Google::Ads::AdWords::v201809::Paging->new({
      startIndex    => 0,
      numberResults => PAGE_SIZE
  });
  my $selector = Google::Ads::AdWords::v201809::Selector->new({
      fields => ["Id", "CriteriaType", "KeywordMatchType", "KeywordText"],
      predicates => [$ad_group_id_predicate, $criteria_type_predicate],
      ordering => Google::Ads::AdWords::v201809::OrderBy->new({
          field     => "KeywordText",
          sortOrder => "ASCENDING"
        }
      ),
      paging => $paging
    });

  # Paginate through results.
  # The contents of the subroutine will be executed for each criterion.
  Google::Ads::AdWords::Utilities::PageProcessor->new({
      client   => $client,
      service  => $client->AdGroupCriterionService(),
      selector => $selector
    }
    )->process_entries(
    sub {
      my ($ad_group_criterion) = @_;
      my $prefix = "Keyword";
      if (
        $ad_group_criterion->isa(
          "Google::Ads::AdWords::v201809::NegativeAdGroupCriterion"))
      {
        my $prefix = "Negative keyword";
      }
      printf "$prefix with text '%s', match type '%s', criteria type '%s', "
        . "and ID %d was found.\n",
        $ad_group_criterion->get_criterion()->get_text(),
        $ad_group_criterion->get_criterion()->get_matchType(),
        $ad_group_criterion->get_criterion()->get_type(),
        $ad_group_criterion->get_criterion()->get_id();
    });

  return 1;
}

# Don't run the example if the file is being included.
if (abs_path($0) ne abs_path(__FILE__)) {
  return 1;
}

# Log SOAP XML request, response and API errors.
Google::Ads::AdWords::Logging::enable_all_logging();

# Get AdWords Client, credentials will be read from ~/adwords.properties.
my $client = Google::Ads::AdWords::Client->new({version => "v201809"});

# By default examples are set to die on any server returned fault.
$client->set_die_on_faults(1);

# Call the example
get_keywords($client, $ad_group_id);

Get responsive search ads in an ad group

#!/usr/bin/perl -w
#
# Copyright 2018 Google LLC
#
# License:: Licensed under the Apache License, Version 2.0 (the "License");
#           you may not use this file except in compliance with the License.
#           You may obtain a copy of the License at
#
#           http://www.apache.org/licenses/LICENSE-2.0
#
#           Unless required by applicable law or agreed to in writing, software
#           distributed under the License is distributed on an "AS IS" BASIS,
#           WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
#           implied.
#           See the License for the specific language governing permissions and
#           limitations under the License.
#
# This example gets non-removed responsive search ads in an ad group. To add
# responsive search ads, run add_responsive_search_ad.pl.
# To get ad groups, run get_ad_groups.pl.

use strict;
use lib "../../../lib";
use utf8;

use Google::Ads::AdWords::Client;
use Google::Ads::AdWords::Logging;
use Google::Ads::AdWords::v201809::OrderBy;
use Google::Ads::AdWords::v201809::Paging;
use Google::Ads::AdWords::v201809::Predicate;
use Google::Ads::AdWords::v201809::Selector;
use Google::Ads::AdWords::Utilities::PageProcessor;

use constant PAGE_SIZE => 500;

use Cwd qw(abs_path);

# Replace with valid values of your account.
my $ad_group_id = "INSERT_AD_GROUP_ID_HERE";

# Example main subroutine.
sub get_responsive_search_ads {
  my ($client, $ad_group_id) = @_;

  # Get all the ads for this ad group.
  my $ad_group_predicate = Google::Ads::AdWords::v201809::Predicate->new({
      field    => "AdGroupId",
      operator => "IN",
      values   => [ $ad_group_id ] });
  my $status_predicate = Google::Ads::AdWords::v201809::Predicate->new({
      field    => "Status",
      operator => "IN",
      values   => [ "ENABLED", "PAUSED" ] });
  my $ad_type_predicate = Google::Ads::AdWords::v201809::Predicate->new({
      field    => "AdType",
      operator => "EQUALS",
      values   => [ "RESPONSIVE_SEARCH_AD" ] });

  # Create selector.
  my $paging = Google::Ads::AdWords::v201809::Paging->new({
      startIndex    => 0,
      numberResults => PAGE_SIZE
  });
  my $selector = Google::Ads::AdWords::v201809::Selector->new({
      fields     =>
          [ "Id", "Status", "ResponsiveSearchAdHeadlines",
              "ResponsiveSearchAdDescriptions" ],
      predicates =>
          [ $ad_group_predicate, $status_predicate, $ad_type_predicate ],
      ordering   => [
          Google::Ads::AdWords::v201809::OrderBy->new({
              field     => "Id",
              sortOrder => "ASCENDING"
          })
      ],
      paging     => $paging
  });

  # Paginate through results.
  # The contents of the subroutine will be executed for each ad.
  Google::Ads::AdWords::Utilities::PageProcessor->new({
      client   => $client,
      service  => $client->AdGroupAdService(),
      selector => $selector
  }
  )->process_entries(
      sub {
        my ($ad_group_ad) = @_;
        printf "Responsive search ad with ID %d and status %s was found.\n",
            $ad_group_ad->get_ad()->get_id(),
            $ad_group_ad->get_status();
        printf "  Headlines:\n";
        foreach my $headline (@{$ad_group_ad->get_ad()->get_headlines()}) {
          my $pinned = $headline->get_pinnedField();
          printf "    %s\n", $headline->get_asset()->get_assetText();
          if ($pinned) {
            printf "      (pinned to %s)\n", $pinned;
          }
        }
        printf "  Descriptions:\n";
        foreach my $description
          (@{$ad_group_ad->get_ad()->get_descriptions()}) {
          my $pinned = $description->get_pinnedField();
          printf "    %s\n", $description->get_asset()->get_assetText();
          if ($pinned) {
            printf "      (pinned to %s)\n", $pinned;
          }
        }
      });
  return 1;
}

# Don't run the example if the file is being included.
if (abs_path($0) ne abs_path(__FILE__)) {
  return 1;
}

# Log SOAP XML request, response and API errors.
Google::Ads::AdWords::Logging::enable_all_logging();

# Get AdWords Client, credentials will be read from ~/adwords.properties.
my $client = Google::Ads::AdWords::Client->new({ version => "v201809" });

# By default examples are set to die on any server returned fault.
$client->set_die_on_faults(1);

# Call the example
get_responsive_search_ads($client, $ad_group_id);

Pause an ad

#!/usr/bin/perl -w
#
# Copyright 2017, Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# This example updates an ad by setting the status to 'PAUSED'. To get ads,
# run basic_operations/get_expanded_text_ads.pl.

use strict;
use lib "../../../lib";
use utf8;

use Google::Ads::AdWords::Client;
use Google::Ads::AdWords::Logging;
use Google::Ads::AdWords::v201809::AdGroupAd;
use Google::Ads::AdWords::v201809::AdGroupAdOperation;

use Cwd qw(abs_path);

# Replace with valid values of your account.
my $ad_group_id = "INSERT_AD_GROUP_ID_HERE";
my $ad_id       = "INSERT_AD_ID_HERE";

# Example main subroutine.
sub pause_ad {
  my $client      = shift;
  my $ad_group_id = shift;
  my $ad_id       = shift;

  # Create ad with updated status.
  my $ad = Google::Ads::AdWords::v201809::Ad->new({id => $ad_id});

  my $ad_group_ad = Google::Ads::AdWords::v201809::AdGroupAd->new({
      adGroupId => $ad_group_id,
      ad        => $ad,
      status    => "PAUSED"
  });

  # Create operation.
  my $operation = Google::Ads::AdWords::v201809::AdGroupAdOperation->new({
      operand  => $ad_group_ad,
      operator => "SET"
  });

  # Validate the ads.
  my $result =
    $client->AdGroupAdService()->mutate({operations => [$operation]});

  # Reading the response.
  if ($result->get_value()) {
    my $ad_group_ad = $result->get_value()->[0];
    printf "Ad with id \"%d\", type \"%s\" and status \"%s\" was updated.\n",
      $ad_group_ad->get_ad()->get_id(),
      $ad_group_ad->get_ad()->get_Ad__Type(), $ad_group_ad->get_status();
  } else {
    print "No ad was updated.";
  }

  return 1;
}

# Don't run the example if the file is being included.
if (abs_path($0) ne abs_path(__FILE__)) {
  return 1;
}

# Log SOAP XML request, response and API errors.
Google::Ads::AdWords::Logging::enable_all_logging();

# Get AdWords Client, credentials will be read from ~/adwords.properties.
my $client = Google::Ads::AdWords::Client->new({version => "v201809"});

# By default examples are set to die on any server returned fault.
$client->set_die_on_faults(1);

# Call the example
pause_ad($client, $ad_group_id, $ad_id);

Remove an ad

#!/usr/bin/perl -w
#
# Copyright 2017, Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# This example removes an ad using the 'REMOVE' operator. To get ads, run
# basic_operations/get_expanded_text_ads.pl.

use strict;
use lib "../../../lib";
use utf8;

use Google::Ads::AdWords::Client;
use Google::Ads::AdWords::Logging;
use Google::Ads::AdWords::v201809::Ad;
use Google::Ads::AdWords::v201809::AdGroupAd;
use Google::Ads::AdWords::v201809::AdGroupAdOperation;

use Cwd qw(abs_path);

# Replace with valid values of your account.
my $ad_group_id = "INSERT_AD_GROUP_ID_HERE";
my $ad_id       = "INSERT_AD_ID_HERE";

# Example main subroutine.
sub remove_ad {
  my $client      = shift;
  my $ad_group_id = shift;
  my $ad_id       = shift;

  # Create base class ad to avoid setting type specific fields.
  my $ad = Google::Ads::AdWords::v201809::Ad->new({id => $ad_id,});

  # Create ad group ad.
  my $ad_group_ad = Google::Ads::AdWords::v201809::AdGroupAd->new({
      adGroupId => $ad_group_id,
      ad        => $ad
  });

  # Create operations.
  my $operation = Google::Ads::AdWords::v201809::AdGroupAdOperation->new({
      operand  => $ad_group_ad,
      operator => "REMOVE"
  });

  # Remove ad.
  my $result =
    $client->AdGroupAdService()->mutate({operations => [$operation]});

  # Display ads.
  if ($result->get_value()) {
    my $ad_group_ad = $result->get_value()->[0];
    printf "Ad with id \"%d\" and type \"%s\" was removed.\n",
      $ad_group_ad->get_ad()->get_id(),
      $ad_group_ad->get_ad()->get_Ad__Type();
  } else {
    print "No ad was removed.\n";
  }

  return 1;
}

# Don't run the example if the file is being included.
if (abs_path($0) ne abs_path(__FILE__)) {
  return 1;
}

# Log SOAP XML request, response and API errors.
Google::Ads::AdWords::Logging::enable_all_logging();

# Get AdWords Client, credentials will be read from ~/adwords.properties.
my $client = Google::Ads::AdWords::Client->new({version => "v201809"});

# By default examples are set to die on any server returned fault.
$client->set_die_on_faults(1);

# Call the example
remove_ad($client, $ad_group_id, $ad_id);

Remove an ad group

#!/usr/bin/perl -w
#
# Copyright 2017, Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# This example removes an ad group by setting the status to 'REMOVED'.
# To get ad groups, run basic_operations/get_ad_groups.pl.

use strict;
use lib "../../../lib";
use utf8;

use Google::Ads::AdWords::Client;
use Google::Ads::AdWords::Logging;
use Google::Ads::AdWords::v201809::AdGroup;
use Google::Ads::AdWords::v201809::AdGroupOperation;

use Cwd qw(abs_path);
use Data::Uniqid qw(uniqid);

# Replace with valid values of your account.
my $ad_group_id = "INSERT_AD_GROUP_ID_HERE";

# Example main subroutine.
sub remove_ad_group {
  my $client      = shift;
  my $ad_group_id = shift;

  # Create ad group with REMOVED status.
  my $ad_group = Google::Ads::AdWords::v201809::AdGroup->new({
      id     => $ad_group_id,
      status => "REMOVED"
  });

  # Create operation.
  my $operation = Google::Ads::AdWords::v201809::AdGroupOperation->new({
      operand  => $ad_group,
      operator => "SET"
  });

  # Remove ad group.
  my $result = $client->AdGroupService()->mutate({operations => [$operation]});

  # Display ad groups.
  if ($result->get_value()) {
    my $ad_group = $result->get_value()->[0];
    printf "The ad group with id %d was removed.\n", $ad_group->get_id();
  } else {
    print "No ad group was removed.\n";
  }

  return 1;
}

# Don't run the example if the file is being included.
if (abs_path($0) ne abs_path(__FILE__)) {
  return 1;
}

# Log SOAP XML request, response and API errors.
Google::Ads::AdWords::Logging::enable_all_logging();

# Get AdWords Client, credentials will be read from ~/adwords.properties.
my $client = Google::Ads::AdWords::Client->new({version => "v201809"});

# By default examples are set to die on any server returned fault.
$client->set_die_on_faults(1);

# Call the example
remove_ad_group($client, $ad_group_id);

Remove a campaign

#!/usr/bin/perl -w
#
# Copyright 2017, Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# This example removes a campaign by setting the status to 'REMOVED'.
# To get campaigns, run basic_operations/get_campaigns.pl.

use strict;
use lib "../../../lib";
use utf8;

use Google::Ads::AdWords::Client;
use Google::Ads::AdWords::Logging;
use Google::Ads::AdWords::v201809::Campaign;
use Google::Ads::AdWords::v201809::CampaignOperation;

use Cwd qw(abs_path);
use Data::Uniqid qw(uniqid);

# Replace with valid values of your account.
my $campaign_id = "INSERT_CAMPAIGN_ID_HERE";

# Example main subroutine.
sub remove_campaign {
  my $client      = shift;
  my $campaign_id = shift;

  # Create campaign with REMOVED status.
  my $campaign = Google::Ads::AdWords::v201809::Campaign->new({
      id     => $campaign_id,
      status => "REMOVED"
  });

  # Create operations.
  my $operation = Google::Ads::AdWords::v201809::CampaignOperation->new({
      operand  => $campaign,
      operator => "SET"
  });

  # Remove campaign.
  my $result = $client->CampaignService()->mutate({operations => [$operation]});

  # Display campaign.
  if ($result->get_value()) {
    my $campaign = $result->get_value()->[0];
    printf "The campaign with id %d was removed.\n", $campaign->get_id();
  } else {
    print "No campaign was removed.\n";
  }

  return 1;
}

# Don't run the example if the file is being included.
if (abs_path($0) ne abs_path(__FILE__)) {
  return 1;
}

# Log SOAP XML request, response and API errors.
Google::Ads::AdWords::Logging::enable_all_logging();

# Get AdWords Client, credentials will be read from ~/adwords.properties.
my $client = Google::Ads::AdWords::Client->new({version => "v201809"});

# By default examples are set to die on any server returned fault.
$client->set_die_on_faults(1);

# Call the example
remove_campaign($client, $campaign_id);

Remove a keyword

#!/usr/bin/perl -w
#
# Copyright 2017, Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# This example removes a keyword using the 'REMOVE' operator. To get keywords,
# run basic_operations/get_keywords.pl.

use strict;
use lib "../../../lib";
use utf8;

use Google::Ads::AdWords::Client;
use Google::Ads::AdWords::Logging;
use Google::Ads::AdWords::v201809::AdGroupCriterion;
use Google::Ads::AdWords::v201809::AdGroupCriterionOperation;

# Replace with valid values of your account.
my $ad_group_id = "INSERT_AD_GROUP_ID_HERE";
my $keyword_id  = "INSERT_KEYWORD_ID_HERE";

use Cwd qw(abs_path);

# Example main subroutine.
sub remove_keyword {
  my $client      = shift;
  my $ad_group_id = shift;
  my $keyword_id  = shift;

  # Create base class criterion to avoid setting keyword specific fields.
  my $criterion =
    Google::Ads::AdWords::v201809::Criterion->new({id => $keyword_id});

  # Create ad group criterion.
  my $ad_group_criterion = Google::Ads::AdWords::v201809::AdGroupCriterion->new(
    {
      adGroupId => $ad_group_id,
      criterion => $criterion
    });

  # Create operation.
  my $operation = Google::Ads::AdWords::v201809::AdGroupCriterionOperation->new(
    {
      operand  => $ad_group_criterion,
      operator => "REMOVE"
    });

  # Remove ad group criteria.
  my $result =
    $client->AdGroupCriterionService()->mutate({operations => [$operation]});

  # Display ad group criteria.
  if ($result->get_value()) {
    my $ad_group_criterion = $result->get_value()->[0];
    printf "Keyword with ad group id \"%d\" and id \"%d\" was removed.\n",
      $ad_group_criterion->get_adGroupId(),
      $ad_group_criterion->get_criterion()->get_id();
  } else {
    print "No keyword was removed.\n";
  }

  return 1;
}

# Don't run the example if the file is being included.
if (abs_path($0) ne abs_path(__FILE__)) {
  return 1;
}

# Log SOAP XML request, response and API errors.
Google::Ads::AdWords::Logging::enable_all_logging();

# Get AdWords Client, credentials will be read from ~/adwords.properties.
my $client = Google::Ads::AdWords::Client->new({version => "v201809"});

# By default examples are set to die on any server returned fault.
$client->set_die_on_faults(1);

# Call the example
remove_keyword($client, $ad_group_id, $keyword_id);

Update an ad group

#!/usr/bin/perl -w
#
# Copyright 2017, Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# This example updates an ad group by setting the status to 'PAUSED' and by
# setting the CPC bid. To get ad groups, run basic_operations/get_ad_groups.pl.

use strict;
use lib "../../../lib";
use utf8;

use Google::Ads::AdWords::Client;
use Google::Ads::AdWords::Logging;
use Google::Ads::AdWords::v201809::AdGroup;
use Google::Ads::AdWords::v201809::AdGroupOperation;
use Google::Ads::AdWords::v201809::BiddingStrategyConfiguration;
use Google::Ads::AdWords::v201809::CpcBid;
use Google::Ads::AdWords::v201809::Money;

use Cwd qw(abs_path);

# Replace with valid values of your account.
my $ad_group_id = "INSERT_AD_GROUP_ID_HERE";
# Set this to undef if you do not want to update the CPC bid.
my $cpc_bid_micro_amount = "INSERT_CPC_BID_MICRO_AMOUNT_HERE";

# Example main subroutine.
sub update_ad_group {
  my ($client, $ad_group_id, $cpc_bid_micro_amount) = @_;
  # Create an ad group with the specified ID.
  # Pause the ad group.
  my $ad_group = Google::Ads::AdWords::v201809::AdGroup->new({
    id     => $ad_group_id,
    status => "PAUSED"
  });

  # Update the CPC bid if specified.
  if ($cpc_bid_micro_amount) {
    my $bidding_strategy_configuration =
      Google::Ads::AdWords::v201809::BiddingStrategyConfiguration->new({
        bids => [
          Google::Ads::AdWords::v201809::CpcBid->new({
              bid => Google::Ads::AdWords::v201809::Money->new({
                  microAmount => $cpc_bid_micro_amount
              }),
            }),
        ]
      });
    $ad_group->set_biddingStrategyConfiguration(
      $bidding_strategy_configuration);
  }

  # Create operation.
  my $operation = Google::Ads::AdWords::v201809::AdGroupOperation->new({
    operand  => $ad_group,
    operator => "SET"
  });

  # Update ad group.
  my $result = $client->AdGroupService()->mutate({operations => [$operation]});

  # Display ad groups.
  foreach my $ad_group_result (@{$result->get_value()}) {
    my $bidding_strategy_configuration =
      $ad_group_result->get_biddingStrategyConfiguration();
    # Find the CpcBid in the bidding strategy configuration's bids collection.
    my $cpc_bid_micros = undef;
    if ($bidding_strategy_configuration) {
      if ($bidding_strategy_configuration->get_bids()) {
        foreach my $bid (@{$bidding_strategy_configuration->get_bids()}) {
          if ($bid->isa("Google::Ads::AdWords::v201809::CpcBid")) {
            $cpc_bid_micros = $bid->get_bid()->get_microAmount();
            last;
          }
        }
      }
    }
    printf("Ad group with ID %d and name '%s' updated to have status '%s' " .
      "and CPC bid %s\n", $ad_group_result->get_id(),
      $ad_group_result->get_name(), $ad_group_result->get_status(),
      ($cpc_bid_micros) ? $cpc_bid_micros : "undef"
    );

  }

  return 1;
}

# Don't run the example if the file is being included.
if (abs_path($0) ne abs_path(__FILE__)) {
  return 1;
}

# Log SOAP XML request, response and API errors.
Google::Ads::AdWords::Logging::enable_all_logging();

# Get AdWords Client, credentials will be read from ~/adwords.properties.
my $client = Google::Ads::AdWords::Client->new({version => "v201809"});

# By default examples are set to die on any server returned fault.
$client->set_die_on_faults(1);

# Call the example
update_ad_group($client, $ad_group_id, $cpc_bid_micro_amount);

Update a campaign

#!/usr/bin/perl -w
#
# Copyright 2017, Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# This example updates a campaign by setting its status to PAUSED.
# To get campaigns, run basic_operations/get_campaigns.pl.

use strict;
use lib "../../../lib";
use utf8;

use Google::Ads::AdWords::Client;
use Google::Ads::AdWords::Logging;
use Google::Ads::AdWords::v201809::Campaign;
use Google::Ads::AdWords::v201809::CampaignOperation;

use Cwd qw(abs_path);

# Replace with valid values of your account.
my $campaign_id = "INSERT_CAMPAIGN_ID_HERE";

# Example main subroutine.
sub update_campaign {
  my $client      = shift;
  my $campaign_id = shift;

  # Create campaign with updated status.
  my $campaign = Google::Ads::AdWords::v201809::Campaign->new({
      id     => $campaign_id,
      status => "PAUSED"
  });

  # Create operation.
  my $operation = Google::Ads::AdWords::v201809::CampaignOperation->new({
      operand  => $campaign,
      operator => "SET"
  });

  # Update campaign.
  my $result = $client->CampaignService()->mutate({operations => [$operation]});

  # Display campaigns.
  if ($result->get_value()) {
    my $campaign = $result->get_value()->[0];
    printf "Campaign with name \"%s\", id \"%d\" and status " .
      "\"%s\" was updated.\n", $campaign->get_name(), $campaign->get_id(),
      $campaign->get_status();
  } else {
    print "No campaign was updated.\n";
  }

  return 1;
}

# Don't run the example if the file is being included.
if (abs_path($0) ne abs_path(__FILE__)) {
  return 1;
}

# Log SOAP XML request, response and API errors.
Google::Ads::AdWords::Logging::enable_all_logging();

# Get AdWords Client, credentials will be read from ~/adwords.properties.
my $client = Google::Ads::AdWords::Client->new({version => "v201809"});

# By default examples are set to die on any server returned fault.
$client->set_die_on_faults(1);

# Call the example
update_campaign($client, $campaign_id);

Update an expanded text ad

#!/usr/bin/perl -w
#
# Copyright 2018 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# This example updates an expanded text ad. To get expanded text ads, run
# get_expanded_text_ads.pl .

use strict;
use lib "../../../lib";
use utf8;

use Google::Ads::AdWords::Client;
use Google::Ads::AdWords::Logging;
use Google::Ads::AdWords::v201809::AdOperation;
use Google::Ads::AdWords::v201809::ExpandedTextAd;

use Cwd qw(abs_path);
use Data::Uniqid qw(uniqid);

# Replace with valid values of your account.
my $ad_id = "INSERT_AD_ID_HERE";

# Example main subroutine.
sub update_expanded_text_ad {
    my ($client, $ad_id) = @_;

    my @operations = ();
    # Creates an expanded text ad using the provided ad ID.
    my $expanded_text_ad = Google::Ads::AdWords::v201809::ExpandedTextAd->new({
        id              => $ad_id,
        headlinePart1   => "Cruise to Pluto #" . substr(uniqid(), 0, 8),
        headlinePart2   => "Tickets on sale now",
        description     => "Best space cruise ever.",
        finalUrls       => [ "http://www.example.com/" ],
        finalMobileUrls => [ "http://www.example.com/mobile" ]
    });

    # Creates ad group ad operation and add it to the list.
    my $operation =
        Google::Ads::AdWords::v201809::AdOperation->new({
            operator => "SET",
            operand  => $expanded_text_ad
        });
    push @operations, $operation;

    # Updates the ad on the server.
    my $result =
        $client->AdService()->mutate({ operations => \@operations });
    my $updated_ad = $result->get_value()->[0];

    # Prints out some information.
    printf("Expanded text ad with ID %d was updated.\n",
        $updated_ad->get_id());
    printf("Headline part 1 is '%s'.\nHeadline part 2 is '%s'." .
        "'\nDescription is '%s'.\n",
        $updated_ad->get_headlinePart1(),
        $updated_ad->get_headlinePart2(),
        $updated_ad->get_description()
    );
    printf(
        "Final URL is '%s'.\nFinal mobile URL is '%s'.\n",
        $updated_ad->get_finalUrls()->[0],
        $updated_ad->get_finalMobileUrls()->[0]
    );

    return 1;
}

# Don't run the example if the file is being included.
if (abs_path($0) ne abs_path(__FILE__)) {
    return 1;
}

# Log SOAP XML request, response and API errors.
Google::Ads::AdWords::Logging::enable_all_logging();

# Get AdWords Client, credentials will be read from ~/adwords.properties.
my $client = Google::Ads::AdWords::Client->new({ version => "v201809" });

# By default examples are set to die on any server returned fault.
$client->set_die_on_faults(1);

# Call the example
update_expanded_text_ad($client, $ad_id);

Update a keyword

#!/usr/bin/perl -w
#
# Copyright 2017, Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# This example updates the bid of a keyword. To get keywords, run
# basic_operations/get_keywords.pl.

use strict;
use lib "../../../lib";
use utf8;

use Google::Ads::AdWords::Client;
use Google::Ads::AdWords::Logging;
use Google::Ads::AdWords::v201809::AdGroupCriterionOperation;
use Google::Ads::AdWords::v201809::BiddableAdGroupCriterion;
use Google::Ads::AdWords::v201809::Criterion;

use Cwd qw(abs_path);

# Replace with valid values of your account.
my $ad_group_id = "INSERT_AD_GROUP_ID_HERE";
my $keyword_id  = "INSERT_KEYWORD_ID_HERE";

# Example main subroutine.
sub update_keyword {
  my $client      = shift;
  my $ad_group_id = shift;
  my $keyword_id  = shift;

  # Create base class criterion to avoid setting keyword specific fields.
  my $criterion =
    Google::Ads::AdWords::v201809::Criterion->new({id => $keyword_id,});

  # Create ad group criterion.
  my $ad_group_criterion =
    Google::Ads::AdWords::v201809::BiddableAdGroupCriterion->new({
      adGroupId => $ad_group_id,
      criterion => $criterion
    });

  # Create bids.
  my $bids = Google::Ads::AdWords::v201809::BiddingStrategyConfiguration->new({
      bids => [
        Google::Ads::AdWords::v201809::CpcBid->new({
            bid => Google::Ads::AdWords::v201809::Money->new(
              {microAmount => 1000000})}
        ),
      ]});

  $ad_group_criterion->set_biddingStrategyConfiguration($bids);

  # Create operation.
  my $operation = Google::Ads::AdWords::v201809::AdGroupCriterionOperation->new(
    {
      operand  => $ad_group_criterion,
      operator => "SET"
    });

  # Update ad group criteria.
  my $result =
    $client->AdGroupCriterionService()->mutate({operations => [$operation]});

  # Display ad group criteria.
  if ($result->get_value()) {
    my $ad_group_criterion = $result->get_value()->[0];
    printf "Keyword with ad group id \"%d\", id \"%d\" was updated with bid " .
      "amount = \"%d\" micros.\n",
      $ad_group_criterion->get_adGroupId(),
      $ad_group_criterion->get_criterion()->get_id,
      $ad_group_criterion->get_biddingStrategyConfiguration()->get_bids()->[0]
      ->get_bid()->get_microAmount();
  } else {
    print "No keyword was updated.\n";
  }

  return 1;
}

# Don't run the example if the file is being included.
if (abs_path($0) ne abs_path(__FILE__)) {
  return 1;
}

# Log SOAP XML request, response and API errors.
Google::Ads::AdWords::Logging::enable_all_logging();

# Get AdWords Client, credentials will be read from ~/adwords.properties.
my $client = Google::Ads::AdWords::Client->new({version => "v201809"});

# By default examples are set to die on any server returned fault.
$client->set_die_on_faults(1);

# Call the example
update_keyword($client, $ad_group_id, $keyword_id);

フィードバックを送信...

ご不明な点がありましたら、Google のサポートページをご覧ください。