Add many keywords to the ad group via one request

650 views
Skip to first unread message

Dmitry Shvetsov

unread,
Feb 19, 2022, 3:53:40 PM2/19/22
to Google Ads API and AdWords API Forum
Hello!
Using this example 

I can add to the ad group only one keyword via one API request.
How to create many keywords using one API request?

PS I'm creating ad groups having 1000 keywords and it's awkward to make 1000 requests.

Thank you!

Dmitry Shvetsov

unread,
Feb 20, 2022, 4:07:25 PM2/20/22
to Google Ads API and AdWords API Forum
I've found decision by adding many elements to "operations=[ad_group_criterion_operation]" list. It's working correctly. Thank you for attention!
Changes in code:
        # Create keyword.
        ad_group_criterion_operations = []
        for keyword_text in keyword_texts:
            ad_group_criterion_operation = client.get_type("AdGroupCriterionOperation")
            ad_group_criterion = ad_group_criterion_operation.create
            ad_group_criterion.ad_group = ad_group_service.ad_group_path(
                customer_id, ad_group_id
            )
            ad_group_criterion.status = client.enums.AdGroupCriterionStatusEnum.ENABLED
            ad_group_criterion.keyword.text = keyword_text
            ad_group_criterion.keyword.match_type = (
                client.enums.KeywordMatchTypeEnum.BROAD  # EXACT, PHRASE, BROAD
            )
            ad_group_criterion_operations.append(ad_group_criterion_operation)

        # Optional field
        # All fields can be referenced from the protos directly.
        # The protos are located in subdirectories under:
        # https://github.com/googleapis/googleapis/tree/master/google/ads/googleads
        # ad_group_criterion.negative = True

        # Optional repeated field
        # ad_group_criterion.final_urls.append('https://www.example.com')

        # Add keyword
        ad_group_criterion_response = (
            ad_group_criterion_service.mutate_ad_group_criteria(
                customer_id=customer_id,
                operations=ad_group_criterion_operations,
            )
        )

Google Ads API Forum Advisor

unread,
Feb 21, 2022, 4:44:36 AM2/21/22
to hunter...@gmail.com, adwor...@googlegroups.com

Hello Dmitry,

Thank you for reaching out to us.

With regard to your approach, you are indeed correct. Since the operations field of the MutateAdGroupCriteriaRequest is an array, then you can add multiple operations on that request.

Regards,

Google Logo
Mark Kevin
Google Ads API Team
 

 

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