Upload and connect html 5 ad in google ads api

199 views
Skip to first unread message

Adhub manager

unread,
Dec 9, 2019, 6:54:58 AM12/9/19
to AdWords API and Google Ads API Forum
Hi friends!

I am currently trying to get html5 upload to work, but im running into an issue when i try to create an ad i can connect to an adgroup.

Let me explain.

1. Create a campaign

2. Create an adgroup

3. Upload html 5

4. Create ad with html 5 ad.

Im stuck on 4 where i am trying to use the api like this from a c# client.

        public static void AssetConnectionToAd(string mediaBundleResourceName, string adgroup)
       
{
           
AdGroupAdServiceClient adgroupServiceClient = client.GetService(Services.V2.AdGroupAdService);
           
var req = new MutateAdGroupAdsRequest();
            req
.Operations.Add(new AdGroupAdOperation {
               
Create = new AdGroupAd
               
{
                   
Ad = new Ad
                   
{                        
                       
                       
DisplayUploadAd = new DisplayUploadAdInfo
                       
{
                           
DisplayUploadProductType = DisplayUploadProductTypeEnum.Types.DisplayUploadProductType.DynamicHtml5CustomAd,
                           
MediaBundle = new AdMediaBundleAsset
                           
{
                               
Asset = mediaBundleResourceName
                           
}
                       
},                        
                   
},
                   
AdGroup = adgroup,                  
                   
               
}
               
           
});
            req
.CustomerId = customerId.ToString();
           
var ad = adgroupServiceClient.MutateAdGroupAds(req);
       
}

If i try to connect this i get an error message:
"Resource name 'customers/6282670156/mediaFiles/26325216408' is malformed: expected 'customers/{customer_id}/assets/{part_1}'."

I am suspecting im uploading it wrong since its creating the resource in another place with /mediafiles and not /assets.

My upload method:

        public static MutateMediaFileResult UploadHtml5(string filepath)
       
{
           
MediaFileServiceClient mediaService = client.GetService(Services.V2.MediaFileService);

           
MutateMediaFilesRequest req = new MutateMediaFilesRequest();

           
var data = File.ReadAllBytes(filepath);
            req
.Operations.Add(new MediaFileOperation()
           
{
               
Create = new MediaFile
               
{
                   
MediaBundle = new MediaBundle
                   
{
                       
Data = ByteString.CopyFrom(data)                      
                   
},
                   
Type = MediaTypeEnum.Types.MediaType.MediaBundle                  
                   
               
}
           
});
            req
.CustomerId = customerId.ToString();
         
var result = mediaService.MutateMediaFiles(req);            
           
return result.Results.First();              
           
       
}

This will return 'customers/6282670156/mediaFiles/26325216408'

I have tested my bundle from the google ads ui and run a succesful campaign with the asset so it is working, however i think im using the wrong upload service.

Can anyone advise? 

Thanks

Google Ads API Forum Advisor Prod

unread,
Dec 9, 2019, 12:50:46 PM12/9/19
to ad...@1stweb.dk, adwor...@googlegroups.com
Hi,

Thank you for reaching out. Instead of using the MediaFileService to create your media_bundle you need to use the AssetService since the new Ad requires a MediaBundleAsset. Additionally, make sure you follow the instructions in this guide  when creating an HTML5 ad.

Regards,
Mitchell
Google Ads API Team

ref:_00D1U1174p._5001UOE7Gs:ref

Adhub manager

unread,
Dec 9, 2019, 5:52:07 PM12/9/19
to AdWords API and Google Ads API Forum
Hi Mitchell

I tried doing as you said i changed my method to upload it like an asset:
        public static MutateAssetResult UploadHtml5(string filepath)
       
{
           
AssetServiceClient assetService = client.GetService(Services.V2.AssetService);


           
MutateAssetsRequest req = new MutateAssetsRequest();


           
var data = File.ReadAllBytes(filepath);
            req
.Operations.Add(new AssetOperation
           
{    
                   
Create = new Asset
                   
{
                       
MediaBundleAsset = new MediaBundleAsset
                       
{
                           
Data = ByteString.CopyFrom(data)
                       
},
                       
Type = AssetTypeEnum.Types.AssetType.MediaBundle,
                       
Name = "testbundle1",
                       
                   
}
           
});
            req
.CustomerId = customerId.ToString();
           
var result = assetService.MutateAssets(req);            
           
return result.Results.First();                
           
       
}

This however ended up giving me another error message 
"The error code is not in this version."

im using latest version of google ads api c# for nuget:
2.6.0

Am i missing an argument maybe?

Thank you for your time!

Google Ads API Forum Advisor Prod

unread,
Dec 10, 2019, 10:52:57 AM12/10/19
to ad...@1stweb.dk, adwor...@googlegroups.com
Hi,

Thank you for sharing that info. Can you please share the detailed request and response logs via reply privately to author so that I can further investigate the issue? You can find information on enabling logging here.

Please make sure you have followed the instructions here to create the zip file for a dynamic product type.
Reply all
Reply to author
Forward
0 new messages