AWQL query.

73 views
Skip to first unread message

Евгений Мотуз

unread,
Mar 27, 2015, 11:54:12 AM3/27/15
to adwor...@googlegroups.com
HI!
Please, help me with AWQL
How can i make request like:
SELECT Id, Name, Status WHERE Status != "REMOVED" AND ( Name CONTAINS "General campaign"  OR Name CONTAINS "Campaign #" OR ...N ) ORDER BY Id

"General campaign" and "Campaign #" it is part of campaign name (full name is General campaign (#45)_1,  General campaign (#45)_2, General campaign (#45)_2 ...) .

My code is:
public function getCampaignsWithCounters(array $campName)
    {

        $awqlInsert = 'AND ( ';
        $insert = FALSE;
        foreach($campName as $cmp)
        {
            if($insert)
                $awqlInsert.=' OR ';
            else
                $insert = TRUE;
            $awqlInsert.= ' Name CONTAINS "'.$cmp.'"';
        }
        $awqlInsert.= ' )';

        $result = [];
        $campaignService = $this->_user->GetService('CampaignService');
        $query = 'SELECT Id, Name, Status WHERE Status != "REMOVED" '.$awqlInsert.' ORDER BY Id';
        // Create paging controls.
        $offset = 0;
        do {
            $pageQuery = sprintf('%s LIMIT %d,%d', $query, $offset,
                \AdWordsConstants::RECOMMENDED_PAGE_SIZE);
            $page = $campaignService->query($pageQuery);
            if (isset($page->entries)) {
                foreach ($page->entries as $campaign) {
                    $result []= [
                        'name' => $campaign->name,
                        'cmpID' => $campaign->id
                    ];
                }
            } else {
                $result = [];
            }
            $offset += \AdWordsConstants::RECOMMENDED_PAGE_SIZE;
        } while ($page->totalNumEntries > $offset);

        return $result;
    }



Josh Radcliff (AdWords API Team)

unread,
Mar 27, 2015, 2:48:28 PM3/27/15
to adwor...@googlegroups.com
Hi,

When using AWQL, you cannot create nested conditions as you described below. Therefore, you would need to submit two requests:

1. WHERE Status != REMOVED AND Name CONTAINS 'General campaign'
2. WHERE Status != REMOVED AND Name CONTAINS 'Campaign #'

As an alternative you could label your campaigns, and then use labels in your report predicates. See our Labels Guide for details.

Thanks,
Josh, AdWords API Team

Евгений Мотуз

unread,
Mar 30, 2015, 7:28:08 AM3/30/15
to adwor...@googlegroups.com
Thanks for answer!

пятница, 27 марта 2015 г., 21:48:28 UTC+3 пользователь Josh Radcliff (AdWords API Team) написал:
Reply all
Reply to author
Forward
0 new messages