Error creating Demand Generation ad in Google Ads API (Python)

70 views
Skip to first unread message

Fausto Esthela Espinoza

unread,
Mar 7, 2025, 7:04:20 AMMar 7
to Google Ads API and AdWords API Forum
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  


Google Ads API Forum Advisor

unread,
Mar 7, 2025, 10:07:06 AMMar 7
to fausto...@gmail.com, adwor...@googlegroups.com

Hi,

Thank you for contacting the Google Ads API support team. 

Based on the request Id provided, I understand that you are encountering FieldError.REQUIRED error while trying to create an ad group criterion with the criterion as userList. Please refer to the following sample request body and confirm whether the request body present in the logs generated is of the same format or some field is missing.

{

  "operations": [

    {

      "create": {

        "userList": {

          "userList": "<Enter user_list resource name here in the format customers/{customerId}/userLists/{userListId}>"

        }

      }

    }

  ]

} 

If you have followed the above format and still you are encountering the error, kindly get back to us with complete API logs (request and response with request-id and request header) generated at your end without redacting any information.

Based on the email subject, I understand that you are using the Python client library. So, if you haven't enabled the logging yet, I would request you to enable logging for the Python client library. You may refer to the guide Python to enable logging at your end. You can enable logging via the curl command by using the -i flag for REST interface requests.

I noticed that you are using version V18 of Google Ads API. Please note that ‘v18’ will be deprecated in June 2025 and will sunset in September 2025. I would recommend you to upgrade to the latest version, 'v19', as soon as possible to benefit from new features. You may refer to the documentation on deprecation and sunset for more information regarding the specific deprecation and sunset dates for each available version.

You can send the details via Reply privately to the author option, or direct private reply to this email.

Thanks,
 
Google Logo Google Ads API Team

Feedback
How was our support today?

rating1    rating2    rating3    rating4    rating5
[2025-03-07 15:05:50Z GMT] This message is in relation to case "ref:!00D1U01174p.!5004Q02vH75l:ref" (ADR-00292246)



Reply all
Reply to author
Forward
0 new messages