ManagedCustomerService Filtering By AccountLabels

205 views
Skip to first unread message

Daniel Alvarado

unread,
Aug 26, 2015, 3:15:28 PM8/26/15
to AdWords API Forum
Hi Team, 

I'm trying to pull a simple report that gets performance data for a sub-section of our accounts based on a given label. However, I'm having a terrible time figuring out how to setup the Predicate correctly, as anything I try results in 

[InternalApiError.UNEXPECTED_INTERNAL_API_ERROR @ com.google.ads.api.services.common.error.InternalApiError.<init>(InternalApiErro]

$user = $this->user;
//Reset to the main MCC
$user->SetClientCustomerId(AWHelper::$MASTER_CLIENT_ID);
// Get the service, which loads the required classes.
$managedCustomerService =
    $user->GetService('ManagedCustomerService', AWHelper::$ADWORDS_VERSION);
// Create selector.
$selector = new Selector();
// Specify the fields to retrieve.
$selector->fields = array('AccountLabels','CustomerId',  'Name', 'CanManageClients', 'CurrencyCode');
$predicate = new Predicate();
$predicate->field = 'AccountLabels';
$predicate->operator = 'CONTAINS_ANY';
$predicate->values = array($labelName);
$selector->predicates = array($predicate);
// Make the get request.
$graph = $managedCustomerService->get($selector);
// Display serviced account graph.
if (isset($graph->entries)) {
    $accounts = array();
    foreach ($graph->entries as $account) {
        //Only include non-manager accounts
        if (!$account->canManageClients) {
            $accounts[$account->customerId] = $account;
        }
    }
    return $accounts;
} else {
    return null;
}

I've also tried a few combinations for the predicate such as: 

$predicate = new Predicate();
$predicate->field = 'AccountLabels';
$predicate->operator = 'IN';
$predicate->values = array($labelName);

and

$predicate = new Predicate();
$predicate->field = 'AccountLabels';
$predicate->operator = 'EQUALS';
$predicate->values = $labelName;

Be advised, I'm trying to filter by Label Name, as I don't know what the Label IDs are. 

Any help is appreciated. 

Thanks, 

Josh Radcliff (AdWords API Team)

unread,
Aug 27, 2015, 8:51:35 AM8/27/15
to AdWords API Forum
Hi Daniel,

Account label filtering in the AdWords API is based on the AccountLabel id rather than the name. Therefore, if you create a predicate using the AccountLabels field, CONTAINS_ANY or CONTAINS_ALL, and the AccountLabel IDs, it should work as expected.

    <ns10:field>AccountLabels</ns10:field>
    <ns10:operator>CONTAINS_ANY</ns10:operator>
    <ns10:values>4099876</ns10:values>
    <ns10:values>4099899</ns10:values>
</ns10:predicates>

To get the list of available account labels and their IDs, you can use AccountLabelService.get.

Cheers,
Josh, AdWords API Team
Reply all
Reply to author
Forward
0 new messages