Filter AdGroups by campaign status

48 views
Skip to first unread message

denma test

unread,
Aug 8, 2020, 5:13:53 AM8/8/20
to AdWords API and Google Ads API Forum
public function getAdGroups(){
        $session = self::setSession();
        $adWordsServices = new AdWordsServices();
        $adGroupService = $adWordsServices->get($session, AdGroupService::class);
        $adGroupData = array();
        // Create selector.
        $selector = new Selector();
        $selector->setFields(['Id', 'Name', 'Status', 'AdGroupType', 'CampaignId', 'CampaignName', 'BiddingStrategyType', 'ContentBidCriterionTypeGroup','CpcBid', 'CpmBid']);
        $selector->setPredicates(
            [
                new Predicate(
                    'Status',
                    PredicateOperator::IN,
                    [AdGroupStatus::ENABLED, AdGroupStatus::PAUSED]
                )
            ]
        );
        $selector->setOrdering([new OrderBy('Name', SortOrder::ASCENDING)]);
        try{
             // Make the get request.
            $result = $adGroupService->get($selector);
            print_r($result); exit();
            // print_r($result->getEntries()); exit();
            $keyIndex = 0;
            if ($result->getEntries() !== null) {
                foreach ($result->getEntries() as $campaignRes) {
                    // print_r($campaignRes);
                    $campaignData[$keyIndex]['id'] = $campaignRes->getId();
                    $campaignData[$keyIndex]['name'] = $campaignRes->getName();
                    $campaignData[$keyIndex]['status'] = $campaignRes->getStatus();
                    $campaignData[$keyIndex]['amount'] = $campaignRes->getBudget()->getAmount()->getMicroAmount();
                    $campaignData[$keyIndex]['type'] = $campaignRes->getAdvertisingChannelType();
                    $campaignData[$keyIndex]['biddingStrategyType'] = $campaignRes->getBiddingStrategyConfiguration()->getBiddingStrategyType();
                    ++$keyIndex;
                }
            }
            return $campaignData[;
    }

It sliting all AdGroups including from removed campaigns too, i need to filter it out. Please guide me on this. Am using AdWords API v201809 php version.

Google Ads API Forum Advisor Prod

unread,
Aug 10, 2020, 9:44:52 AM8/10/20
to denm...@gmail.com, adwor...@googlegroups.com
Hello,

You can filter ad groups by their campaign statuses by using the field CampaignStatus.

Regards,
Anthony
Google Ads API Team 

ref:_00D1U1174p._5004Q23IfL2:ref

denma test

unread,
Aug 11, 2020, 12:43:57 AM8/11/20
to AdWords API and Google Ads API Forum
Hi Anthony,
Actually am not using Adgroup Performance Report service, am using AdGrup services to list all my adgroups as mentioned in previous code. Only thing is that service is returns all adgroups even from removed campaigns too, i just need to eliminate that part alone. Please correct me if am in wrong way.

Google Ads API Forum Advisor Prod

unread,
Aug 11, 2020, 11:41:22 AM8/11/20
to denm...@gmail.com, adwor...@googlegroups.com
Hello,

Unfortunately, there is no CampaignStatus field in the AdGroupService. You will either need to use the AdGroup Performance Report or call a GET method on the CampaignService to get all your enabled and paused then pass those campaigns to the AdGroupService.

denma test

unread,
Aug 12, 2020, 12:51:55 AM8/12/20
to AdWords API and Google Ads API Forum
Hello
Yes, done with AdGroup Performance Report, it looks fine to work it. Thanks.
Reply all
Reply to author
Forward
0 new messages