Fetches assets in an account.
Typical usage:
var assetIterator = AdsApp.adAssets().assets()
.withCondition("Type = IMAGE")
.get();
Methods:
get()
Fetches the requested assets and returns an iterator.
Return values:
orderBy(orderBy)
Specifies the ordering of the resulting entities.
orderBy
parameter can have one of the
following forms:
orderBy("asset.id ASC")
- orders results by asset.id, in ascending order.
orderBy("asset.name DESC")
- orders results by asset.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("asset.name ASC").orderBy("asset.id DESC");
The results will be ordered by asset.name in ascending order. Results with equal asset.name
values will be ordered by asset.id in descending order.
Arguments:
Name | Type | Description |
orderBy |
String |
Ordering to apply. |
Return values:
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. metrics.impressions, metrics.clicks):
< <= > >= = !=
- For
Double
columns (e.g. metrics.ctr):
< >
- For
String
columns (e.g. Name):
= != (NOT) (LIKE | CONTAINS | REGEXP_MATCH)
- 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)")
Columns
All column names are case-sensitive, and so are all values of enumerated columns (such as
Type).
Column |
Type |
Example |
Asset attributes |
asset.name |
String |
withCondition("asset.name REGEXP_MATCH '.*shoes.*'") |
asset.type |
Enumeration: IMAGE , MEDIA_BUNDLE , TEXT ,
YOUTUBE_VIDEO |
withCondition("asset.type = IMAGE") |
Arguments:
Name | Type | Description |
condition |
String |
Condition to add to the selector. |
Return values:
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:
Name | Type | Description |
ids |
Object[] |
Array of asset IDs. |
Return values:
withLimit(limit)
Specifies limit for the selector to use. For instance,
withLimit(50)
returns only the
first 50 entities.
Arguments:
Name | Type | Description |
limit |
int |
How many entities to return. |
Return values:
withResourceNames(resourceNames)
Restricts this selector to return only assets with the given Google Ads
API resource names.
const assetResourceNames = [
'customers/1234567890/assets/111',
'customers/1234567890/assets/222',
'customers/1234567890/assets/333',
];
selector = selector.withResourceNames(assetResourceNames);
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:
Name | Type | Description |
resourceNames |
String[] |
Array of asset resource names. |
Return values: