I am using the Google Ads API in Python to create a campaign, an ad group, 
and an ad of the Demand Generation type for videos on YouTube. When I 
create the ad, I get an error that I don't understand yet: 

[GoogleAdsException] An error occurred:
        Request ID: Q0Pc0-OQ8bPz0dh6SBzlRQ
        Failure Type: <class 
'google.ads.googleads.v18.errors.types.errors.GoogleAdsFailure'>
        Total Errors: 1
                Error Details:
                 - Error Message: The required field was not present.
                 - Field Path: operations > create > user_list > user_list
                 - Error Codes:
                field_error: REQUIRED - 2
[End of Exception Details]

This is the code to create the ad: 

def create_video(self,ad_create: GAdCreate):        
        ad_group_ad_service = client.get_service("AdGroupAdService")        
        try:            
            if not ad_create.url.startswith("http"):
                raise ValueError("URL final inválida")
            if not ad_create.video_id:
                raise ValueError("video_id no puede ser nulo o vacío")     
       
            
            tipo_edad = client.enums.AgeRangeTypeEnum.AGE_RANGE_18_24
            tipo_genero = client.enums.GenderTypeEnum.MALE
            
            audience_resource_name = self.agregar_segmentacion_demografica(
client, customer_id, ad_create.ad_group_id, tipo_edad, tipo_genero)
            self.attach_audience_to_ad_group(client, customer_id, ad_create.
ad_group_id, audience_resource_name)
            
            ad_group_ad_operation = client.get_type("AdGroupAdOperation")
            ad_group_ad = ad_group_ad_operation.create

            ad_group_ad.ad_group = f"customers/{
                customer_id}/adGroups/{ad_create.ad_group_id}"
            ad_group_ad.ad.final_urls.append(ad_create.url)         

            ad = ad_group_ad.ad              
            
            ad.video_responsive_ad.videos.append(client.get_type(
"AdVideoAsset"))
            ad.video_responsive_ad.videos[-1].asset = f"customers/{
customer_id}/assets/{ad_create.video_id}"

            ad.video_responsive_ad.long_headlines.append(client.get_type(
"AdTextAsset"))
            ad.video_responsive_ad.long_headlines[-1].text = ad_create.
headline

            ad.video_responsive_ad.headlines.append(client.get_type(
"AdTextAsset"))
            ad.video_responsive_ad.headlines[-1].text = ad_create.headline2

            ad.video_responsive_ad.descriptions.append(client.get_type(
"AdTextAsset"))
            ad.video_responsive_ad.descriptions[-1].text = ad_create.
description
                      
            ad.final_urls.append(ad_create.url)
            
            if ad_create.status == "ACTIVE":
                ad_group_ad.status = client.enums.AdGroupStatusEnum.ENABLED
            else:
                ad_group_ad.status = client.enums.AdGroupStatusEnum.PAUSED
        
            ad_response = ad_group_ad_service.mutate_ad_group_ads(
                customer_id=customer_id, operations=[ad_group_ad_operation]
            )
            ad_resource_name = ad_response.results[0].resource_name
            ad_id = ad_resource_name.split("/")[-1]
            ad_id = ad_id.split("~")[-1]

            api_response = {
                "resource_name": ad_resource_name,
                "ad_id": ad_id
            }
        except GoogleAdsException as ex:
            print(f"An error occurred while creating the ad: {ex}")
            raise ex
        except Exception  as ex:
            print(f"An error occurred : {ex}")
            raise ex

        print("Ad Created: ")
        print(api_response)
        return api_response

I can't find how to fix this error.
If you could provide some guidance, I would really appreciate it.
Thanks  


-- 
-- 
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
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 
"Google Ads API and AdWords 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 visit 
https://groups.google.com/d/msgid/adwords-api/8531a375-5d0c-4989-a766-f0cca3221900n%40googlegroups.com.
  • Er... Fausto Esthela Espinoza
    • ... 'Google Ads API Forum Advisor' via Google Ads API and AdWords API Forum

Reply via email to