How to bulk remove ads with Google Ads API?

20 views
Skip to first unread message

EladB

unread,
Sep 8, 2021, 7:34:30 PM9/8/21
to AdWords API and Google Ads API Forum
Hi

I saw this [code][1] for bulk creating ad groups.
I want to write similar code for bulk removing ads.

Is my modification correct?

    def build_ad_removal_sync_operation(customer_id, campaign_id, ad_id):
        resource_name = serviceWrapper.ad_group_ad_service.ad_group_ad_path(customer_id, campaign_id, ad_id)
        ad_group_ad_op1 = serviceWrapper.client.get_type("AdGroupAdOperation")
        ad_group_ad_op1.remove.name = f"Remove ad: {customer_id}/{campaign_id}/{ad_id}"
        ad_group_ad_op1.remove.ad = resource_name
        return ad_group_ad_op1
    
    def send_bulk_mutate_request(customer_id, operations):
        # Issue a mutate request, setting partial_failure=True.
        request = serviceWrapper.client.get_type("MutateAdGroupsAdRequest")
        request.customer_id = customer_id
        request.operations = operations
        request.partial_failure = True
        return serviceWrapper.ad_group_ad_service.mutate_ad_groups(request=request)

Thanks!
(also posted on the python api github)

Google Ads API Forum Advisor

unread,
Sep 8, 2021, 11:15:53 PM9/8/21
to adwor...@googlegroups.com
Hi Elad,

For Python client library or code implementation verification and assistance, you may continue discussion with their team instead and in the Github thread you created, as this is more related to their expertise.

Best regards,

Google Logo
Peter Laurence Napa Oliquino
Google Ads API Team
 


ref:_00D1U1174p._5004Q2NSbSC:ref
Reply all
Reply to author
Forward
0 new messages