AdsApp.​LabelSelector

Fetches labels. Supports filtering and sorting.

Typical usage:

var labelSelector = AdsApp.labels()
    .withCondition("CampaignsCount > 5")
    .orderBy("CampaignsCount DESC");

var labelIterator = labelSelector.get();
while (labelIterator.hasNext()) {
  var label = labelIterator.next();
}
Related:

Methods:

MemberTypeDescription
get AdsApp.LabelIterator Fetches the requested labels and returns an iterator.
orderBy AdsApp.LabelSelector Specifies the ordering of the resulting entities.
withCondition AdsApp.LabelSelector Adds the specified condition to the selector in order to narrow down the results.
withIds AdsApp.LabelSelector Restricts this selector to return only labels with the given label IDs.
withLimit AdsApp.LabelSelector Specifies limit for the selector to use.
withResourceNames AdsApp.LabelSelector Restricts this selector to return only labels with the given Google Ads API resource names.

get()

Fetches the requested labels and returns an iterator.

Return values:

TypeDescription
AdsApp.LabelIterator Iterator of the requested labels.

orderBy(orderBy)

Specifies the ordering of the resulting entities. orderBy parameter can have one of the following forms:
  • orderBy("label.name") - orders results by label.name, in ascending order.
  • orderBy("label.name ASC") - orders results by label.name, in ascending order.
  • orderBy("label.id DESC") - orders results by label.id, in descending order.

See LabelSelector.withCondition(String) for enumeration of columns that can be used.

orderBy() may be called multiple times. Consider the following example:

selector = selector.orderBy("label.name DESC").orderBy("label.id");

The results will be ordered by label.name in descending order. Results with equal label.name value will be ordered by label.id in ascending order.

Arguments:

NameTypeDescription
orderBy String Ordering to apply.

Return values:

TypeDescription
AdsApp.LabelSelector The selector with ordering applied.

withCondition(condition)

Adds the specified condition to the selector in order to narrow down the results.

Multiple conditions may be added to the same selector:

selector = selector
    .withCondition("label.name CONTAINS 'test'")
    .withCondition("label.description CONTAINS 'cool'");
All specified conditions are AND-ed together. The above example will retrieve labels whose name contains 'test' and whose description contains 'cool'.

The parameter to be passed into this method must be of the following form:

"COLUMN_NAME OPERATOR VALUE"

Operators

The operator that can be used in a condition depends on the type of column.
  • For String columns (e.g. label.name):
    =  !=  (NOT) (LIKE | CONTAINS | REGEXP_MATCH)

Columns

All column names are case-sensitive.

Column Type Example
label.name String withCondition("label.name CONTAINS 'priority'")

Arguments:

NameTypeDescription
condition String Condition to add to the selector.

Return values:

TypeDescription
AdsApp.LabelSelector The selector with the condition applied.

withIds(ids)

Restricts this selector to return only labels with the given label IDs.
var labelIds = ['12345', '23456', '34567'];
selector = selector.withIds(labelIds);

The resulting selector can be further refined by applying additional conditions to it. The ID-based condition will then be AND-ed together with all the other conditions, including any other ID-based conditions. So, for instance, the following selector:

AdsApp.labels()
   .withIds(['12345', '23456', '34567'])
   .withIds(['34567', '45678', '56789']);
will only get the label with ID 34567, since it would be the only label that satisfies both ID conditions.

The selector can only support up to 10,000 IDs. If more than 10,000 IDs are specified, the corresponding get() call will fail with a runtime error.

Arguments:

NameTypeDescription
ids Object[] Array of label IDs.

Return values:

TypeDescription
AdsApp.LabelSelector The selector restricted to the given IDs.

withLimit(limit)

Specifies limit for the selector to use. For instance, withLimit(50) returns only the first 50 entities.

Arguments:

NameTypeDescription
limit int How many entities to return.

Return values:

TypeDescription
AdsApp.LabelSelector The selector with limit applied.

withResourceNames(resourceNames)

Restricts this selector to return only labels with the given Google Ads API resource names.
const labelResourceNames = [
  'customers/1234567890/labels/111',
  'customers/1234567890/labels/222',
  'customers/1234567890/labels/333',
];
selector = selector.withResourceNames(labelResourceNames);

The resulting selector can be further refined by applying additional conditions to it. The resource name condition will then be AND-ed together with all the other conditions.

The selector can only support up to 10,000 resource names. If more than 10,000 resource names are specified, the corresponding get() call will fail with a runtime error.

Arguments:

NameTypeDescription
resourceNames String[] Array of label resource names.

Return values:

TypeDescription
AdsApp.LabelSelector The selector restricted to the given resource names.