TypeError: Message must be initialized with a dict: google.ads.googleads.v13.resources.CampaignCriterion

2,562 views
Skip to first unread message

Eran Mazur

unread,
Mar 6, 2023, 11:36:50 AM3/6/23
to Google Ads API and AdWords API Forum
Good evening, I've been trying to add criterions to a campaign but i receive this error:

  

    criterion.language = lang_resource.resource_name
    ^^^^^^^^^^^^^^^^^^

    self._pb.MergeFrom(self._meta.pb(**{key: pb_value}))
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: Message must be initialized with a dict: google.ads.googleads.v13.resources.CampaignCriterion

This is my code, Any idea what is it? i've searched the internet to see if anyone experienced it also but no luck.

def create_language_op(self, customer_id, campaign_id, lang_name="English"):
googleads_service = self.client.get_service("GoogleAdsService")
criterion_op = self.client.get_type("CampaignCriterionOperation")
query = f"""SELECT language_constant.resource_name FROM language_constant WHERE language_constant.name LIKE '{lang_name}' LIMIT 1"""
response = googleads_service.search(
customer_id=customer_id, query=query
)
lang_resource = response.results[0].language_constant
criterion = criterion_op.create
criterion.campaign = campaign_id
criterion.language = lang_resource.resource_name
return criterion_op

Google Ads API Forum Advisor

unread,
Mar 7, 2023, 12:08:31 AM3/7/23
to er...@marktrix.com, adwor...@googlegroups.com

Hi Eran,

Thank you for reaching out to us.

For our team to further investigate this and provide an appropriate recommendation to you, could you please provide us with the complete API logs (request and response with request-id) generated on your end in debug level?  

Note that this 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 here and click your client library for the specific guideline to enable it.

You may then send the requested information 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.

Best regards,

Google Logo Google Ads API Team


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