Batch create callout_asset and campaign_assets

53 views
Skip to first unread message

Antony Kyalo Musyoki

unread,
Aug 17, 2023, 1:05:17 PM8/17/23
to Google Ads API and AdWords API Forum
Hello,
I am looking to use a batch process in python to create campaigns using the Google Ads API. 

I want to create callout_assets to be attached to the campaigns through campaign_assets. I am running into a problem where I am unable to assign a resource_name to the callout_asset which can latter be used to attach the callout_asset to a campaign_asset. 

Any ideas how I can solution for this. 

Code extract for the section I am getting error in is below

def build_campaign_callout_assets(client, campaign_operation):
    calloutstext = ['callout #1', 'callout #2', 'callout #3', 'callout #4']
    return [
        build_campaign_callout_asset(client, campaign_operation, callouttext)
        for callouttext in calloutstext
    ]

def build_campaign_callout_asset(client, callouttext):
    asset_operation = client.get_type("AssetOperation")
    asset = asset_operation.create.callout_asset
    asset.callout_text = callouttext
    asset.resource_name = callouttext <============ AttributeError: Protocol message CalloutAsset has no "resource_name" field.

    return asset_operation

def build_campaign_assets(client, campaign_operations, asset_operations):
    return [
        build_campaign_asset(client, campaign_operation, asset_operation)
        for campaign_operation in campaign_operations
            for asset_operation in asset_operations
    ]

def build_campaign_asset(client, campaign_operation,  asset_operation ):
    campaign_asset_operation = client.get_type("CampaignAssetOperation")
    campaign_asset = campaign_asset_operation.create
    campaign_asset.asset =  asset_operation .create.resource_name    <===== LOOKING TO USE THE RESOUSE NAME HERE
    campaign_asset.field_type = client.enums.AssetFieldTypeEnum.CALLOUT
    campaign_asset.campaign = campaign_operation.create.resource_name

    return campaign_asset_operation

Google Ads API Forum Advisor

unread,
Aug 17, 2023, 6:01:25 PM8/17/23
to bookinghub...@gmail.com, adwor...@googlegroups.com
Hello,

Thank you for reaching out to us.

Here is our example for Python using batch jobs for reference: https://github.com/googleads/google-ads-python/blob/main/examples/campaign_management/add_complete_campaigns_using_batch_job.py.

I hope this helps.
 
This message is in relation to case "ref:_00D1U1174p._5004Q2ntUZ1:ref"

Thanks,
 
Google Logo Google Ads API Team


Antony Kyalo Musyoki

unread,
Aug 17, 2023, 7:47:46 PM8/17/23
to Google Ads API Forum Advisor, adwor...@googlegroups.com
Hello,
Thank you for providing me information on the python sample for campaign batch creation.
I actually started off working with that sample and have been modifying it to customize to our goals.
I have run into  a specific problem where the callout_asset does not look to have a resource_name property which is how I would attach it to a campaign_asset and wanted to know if you have suggestions on how I can accomplish this?

Google Ads API Forum Advisor

unread,
Aug 18, 2023, 2:05:52 AM8/18/23
to bookinghub...@gmail.com, adwor...@googlegroups.com

Hi Antony,

Thank you for the reply.

For our team to further check and provide appropriate recommendations for the specific problem you are encountering, could you please provide us with the complete API logs (request, response, and request ID) generated on your end?

Note that logs can be requested or provided to the developer handling the Google Ads API transactions when logging of the API requests has been enabled. You may check this specific guideline to enable Python: https://developers.google.com/google-ads/api/docs/client-libs/python/logging.

You may then send the requested logs via the Reply privately to author option. If this option is not available, you may send the details directly to our googleadsa...@google.com alias instead.
 

Reply all
Reply to author
Forward
0 new messages