This is the legacy documentation for Google Ads scripts. Go to the current docs.

AdsApp.​AssetSelector

Fetches assets in an account.

Typical usage:

 var assetIterator = AdsApp.adAssets().assets()
   .withCondition("Type = IMAGE")
   .get();

Methods:

MemberTypeDescription
get AdsApp.AssetIterator Fetches the requested assets and returns an iterator.
orderBy AdsApp.AssetSelector Specifies the ordering of the resulting entities.
withCondition AdsApp.AssetSelector Adds the specified condition to the selector in order to narrow down the results.
withIds AdsApp.AssetSelector Restricts this selector to return only assets with the given asset IDs.
withLimit AdsApp.AssetSelector Specifies limit for the selector to use.

get()

Fetches the requested assets and returns an iterator.

Return values:

TypeDescription
AdsApp.AssetIterator Iterator of the requested assets.

orderBy(orderBy)

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

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

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

 selector = selector.orderBy("Name ASC").orderBy("Id DESC");

The results will be ordered by Name in ascending order. Results with equal Name values will be ordered by Id in descending order.

Arguments:

NameTypeDescription
orderBy String Ordering to apply.

Return values:

TypeDescription
AdsApp.AssetSelector 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("Type = "IMAGE").withCondition("Name CONTAINS 's'");
All specified conditions are AND-ed together. The above example will retrieve entities that are of type Image AND have a name containing 's'.

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 Integer and Long columns (e.g. Impressions, Clicks):
    <  <=  >  >=  =  !=
  • For Double columns (e.g. Ctr):
    <  >
  • For String columns (e.g. Name):
    =  !=  STARTS_WITH  STARTS_WITH_IGNORE_CASE  CONTAINS
     CONTAINS_IGNORE_CASE  DOES_NOT_CONTAIN  DOES_NOT_CONTAIN_IGNORE_CASE
  • For Enumeration columns (ones that can only take one value from a predefined list, such as Status):
    =  !=  IN []  NOT_IN []
  • For StringSet columns (e.g. LabelNames):
    CONTAINS_ALL []  CONTAINS_ANY []  CONTAINS_NONE []
Conditions using IN, NOT_IN, CONTAINS_ALL, CONTAINS_ANY and CONTAINS_NONE operators look as follows:
 withCondition("ColumnName IN [Value1, Value2]")
Operators are case-sensitive: starts_with won't work.

Columns

All column names are case-sensitive, and so are all values of enumerated columns (such as Type).

Column Type Example
Asset attributes
Name String withCondition("Name CONTAINS_IGNORE_CASE 'shoes'")
Type Enumeration: IMAGE, MEDIA_BUNDLE, TEXT, YOUTUBE_VIDEO withCondition("Type = IMAGE")
YouTubeVideoId String withCondition("YouTubeVideoId = 'vPqslcwZ8Kk'")

Arguments:

NameTypeDescription
condition String Condition to add to the selector.

Return values:

TypeDescription
AdsApp.AssetSelector The selector with the condition applied.

withIds(ids)

Restricts this selector to return only assets with the given asset IDs.
 var assetIds = [12345, 23456, 34567];
 selector = selector.withIds(assetIds);

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.adAssets().assets()
    .withIds([12345, 23456, 34567])
    .withIds([34567, 45678, 56789]);
will only get the asset with ID 34567, since it would be the only asset 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 long[] Array of asset IDs.

Return values:

TypeDescription
AdsApp.AssetSelector 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.AssetSelector The selector with limit applied.