Hello, I am running into some trouble when adding criteria to an adgroup.

Traceback (most recent call last):
  File 
"/usr/local/anaconda3/lib/python3.7/site-packages/googleads/common.py", 
line 992, in MakeSoapRequest
    *packed_args, _soapheaders=soap_headers)['body']['rval']
  File "/usr/local/anaconda3/lib/python3.7/site-packages/zeep/proxy.py", 
line 45, in __call__
    kwargs,
  File 
"/usr/local/anaconda3/lib/python3.7/site-packages/zeep/wsdl/bindings/soap.py", 
line 130, in send
    return self.process_reply(client, operation_obj, response)
  File 
"/usr/local/anaconda3/lib/python3.7/site-packages/zeep/wsdl/bindings/soap.py", 
line 195, in process_reply
    return self.process_error(doc, operation)
  File 
"/usr/local/anaconda3/lib/python3.7/site-packages/zeep/wsdl/bindings/soap.py", 
line 299, in process_error
    detail=fault_node.find("detail"),
zeep.exceptions.Fault: [InternalApiError.UNEXPECTED_INTERNAL_API_ERROR @ 
com.google.ads.api.services.common.error.InternalApiError.<init>(InternalApiErro]

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "add_audiences.py", line 79, in <module>
    main(adwords_client, 'XXXXXXXXXXXX')
  File "add_audiences.py", line 60, in main
    response = ad_group_criterion_service.mutate(operations)
  File 
"/usr/local/anaconda3/lib/python3.7/site-packages/googleads/common.py", 
line 1004, in MakeSoapRequest
    e.detail, errors=error_list, message=e.message)
googleads.errors.GoogleAdsServerFault: 
[InternalApiError.UNEXPECTED_INTERNAL_API_ERROR @ 
com.google.ads.api.services.common.error.InternalApiError.<init>(InternalApiErro]


My code attempts to add 19 separate criteria to an adgroup given its ID, 
however it is always returning this error. You can find my code attached in 
this message also, so the error can be reproduced. 

Thanks for your time

-- 
-- 
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog:
https://googleadsdeveloper.blogspot.com/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

You received this message because you are subscribed to the Google
Groups "AdWords API and Google Ads API Forum" group.
To post to this group, send email to adwords-api@googlegroups.com
To unsubscribe from this group, send email to
adwords-api+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/adwords-api?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"AdWords API and Google Ads API Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to adwords-api+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/adwords-api/940f14bf-c6c3-4e1a-89fc-ea67f5c02ba6%40googlegroups.com.
# @author jasperan

'''
This code adds audiences at the adgroup level. A list of these audiences can be found in here:

https://developers.google.com/adwords/api/docs/appendix/codes-formats

Valid affinity categories and corresponding criterion IDs used in CriterionUserInterest.
We can also retrieve this list via the getUserInterestCriterion method of ConstantDataService by passing userInterestTaxonomyType = BRAND.
'''

from googleads import adwords

# Total of 21 audiences.
audience_ids = [80141, 92949, 92947, 93034, 93014, 92945, 93015, 93017, 80237, 93002, 92948, 80191, 80545, 92901, 80142, 80133, 93028, 80140, 93040]


def main(client, ad_group_id):
	# Initialize appropriate service.
	ad_group_criterion_service = client.GetService(
			'AdGroupCriterionService', version='v201809')

	# Create the ad group criteria.
	'''
	# Example object:
	ad_group_criteria = [
			# Targeting criterion.
			{
					'xsi_type': 'BiddableAdGroupCriterion',
					'adGroupId': ad_group_id,
					'criterion': {
							'xsi_type': 'CriterionUserInterest',
							'id': audience_ids[0]
					}
			}
	]
	'''

	ad_group_criteria = list()
	for i in audience_ids:
		aux_obj = dict()
		aux_obj['xsi_type'] = 'BiddableAdGroupCriterion'
		aux_obj['adGroupId'] = ad_group_id
		criterion_obj = dict()
		criterion_obj['xsi_type'] = 'CriterionUserInterest'
		criterion_obj['id'] = str(i)
		aux_obj['criterion'] = dict(criterion_obj)
		ad_group_criteria.append(aux_obj)

	print('Full object: {}'.format(ad_group_criteria))
	
	# Create operations.
	operations = []
	for criterion in ad_group_criteria:
		operations.append({
				'operator': 'ADD',
				'operand': criterion
		})

	response = ad_group_criterion_service.mutate(operations)

	if response and response['value']:
		criteria = response['value']
		for ad_group_criterion in criteria:
			criterion = ad_group_criterion['criterion']
			print('Ad group criterion with ad group ID %s, criterion ID %s and '
						'type "%s" was added.' %
						(ad_group_criterion['adGroupId'], criterion['id'],
						 criterion['type']))
	else:
		print('No criteria were returned.')
	


if __name__ == '__main__':
	# Initialize client object.
	adwords_client = adwords.AdWordsClient.LoadFromStorage()
	# Example with a specific adgroup id: XX
	main(adwords_client, 'XX')

Reply via email to