Create ad assets

Unlike those that are served by other types of line items, creatives served by Demand Gen ads are constructed in the AdGroupAd resources themselves. The image and video assets assigned to ads to build these creatives are represented in the Display & Video 360 API by AdAsset resources.

Before creating an AdGroupAd resource, create the relevant AdAsset resources that the ad will use if they don't already exist. If they were previously created using the UI or API, you can retrieve existing assets using the advertisers.adAssets service get and list methods.

Image and video AdAsset resources are created using different methods:

The adAssetId of an AdAsset resource is used to associate an asset with a Demand Gen ad.

Upload image assets

Upload image files to create AD_ASSET_TYPE_IMAGE assets that can be used as companion banners, logos, and marketing images.

Here's how to upload an image asset to create an AdAsset resource:

Python

# Import the object used as the media body for the upload request.
from apiclient.http import MediaFileUpload

# Provide the parent advertiser ID to upload the media file under.
advertiser_id = advertiser-id

# Provide the filename and local path to the media file.
asset_filename = asset-filename
asset_path = asset-path

# Create the request body.
body = {"filename": asset_filename, "adAssetType": "AD_ASSET_TYPE_IMAGE"}

# Create the upload object and use a default MIME type if not identified.
media = MediaFileUpload(asset_path)
if not media.mimetype():
  media = MediaFileUpload(asset_path, "application/octet-stream")

# Upload the asset.
upload_response = (
    service.advertisers()
    .adAssets()
    .upload(advertiserId=advertiser_id, body=body, media_body=media)
    .execute()
)

# Display the new ad asset.
print(f"Ad asset {upload_response['adAsset']['name']} was created.")

Create YouTube assets

Provide YouTube video IDs to create AD_ASSET_TYPE_YOUTUBE_VIDEO assets that can be used in Demand Gen video ads.

Here's how to create a YouTube video asset to create an AdAsset resource:

Python

# Provide the ID of the parent advertiser.
advertiser_id = advertiser-id

# Provide the ID of the parent insertion order.
youtube_video_id = youtube-video-id

# Create a line item object with example values.
ad_asset_create_body = {
    "adAsset": {
        "adAssetType": "AD_ASSET_TYPE_YOUTUBE_VIDEO",
        "youtubeVideoAsset": {"youtubeVideoId": youtube_video_id},
    }
}

# Build and execute request.
response = (
    service.advertisers()
    .adAssets()
    .create(advertiserId=advertiser_id, body=ad_asset_create_body)
    .execute()
)

# Display the new ad asset.
print(f"Ad asset {response['name']} was created.")