Update/Create TemplateAd

198 views
Skip to first unread message

Hazar Hayat

unread,
Aug 6, 2015, 12:59:13 PM8/6/15
to AdWords API Forum
We have a requirement to update the final url of the template ads to add a tracking code to the url, but we are facing issue to create a copy of the existing ads with updated final URL.

We are updating ads with templateId equals to 486.

AdGroupAdPage page = adGroupAdService.get(selector);
TemplateAd templateAd = adGroupAd.ad as TemplateAd;

TemplateAd templateAdNew = new TemplateAd();

//Update the url in the downloaded ads

templateAdNew.url = templateAd.url;
templateAdNew.finalUrls = templateAd.finalUrls;
templateAdNew.trackingUrlTemplate = templateAd.trackingUrlTemplate;
templateAdNew.displayUrl = templateAd.displayUrl;
templateAdNew.name = templateAd.name;
templateAdNew.templateElements = templateAd.templateElements;
templateAdNew.templateId = templateAd.templateId;
templateAdNew.adUnionId = templateAd.adUnionId;
templateAdNew.dimensions = templateAd.dimensions;


AdGroupAd textadGroupAd = new AdGroupAd();
textadGroupAd.adGroupId = adgroupId;
textadGroupAd.ad = newAd;
textadGroupAd.status = adGroupAd.status;

AdGroupAdOperation adGroupAdOperation = new AdGroupAdOperation();
adGroupAdOperation.@operator = Operator.ADD;
adGroupAdOperation.operand = textadGroupAd;

adGroupAdService.mutate(new AdGroupAdOperation[] {adGroupAdOperation});


Request:

<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Header><RequestHeader xmlns="https://adwords.google.com/api/adwords/cm/v201502"><developerToken xmlns="https://adwords.google.com/api/adwords/cm/v201502">xxxx</developerToken><clientCustomerId xmlns="https://adwords.google.com/api/adwords/cm/v201502">xxxx</clientCustomerId><userAgent xmlns="https://adwords.google.com/api/adwords/cm/v201502">xxxx</userAgent></RequestHeader></soap:Header><soap:Body><mutate xmlns="https://adwords.google.com/api/adwords/cm/v201502"><operations><operator>ADD</operator><operand><adGroupId>19997049181</adGroupId><ad xsi:type="TemplateAd"><url>http://Hyundai.example.com</url><displayUrl>Hyundai.example.com</displayUrl><templateId>486</templateId><templateElements><uniqueName>adData</uniqueName><fields><name>multiDestinationUrl1</name><type>URL</type><fieldText>http://www.example.com/privacy</fieldText></fields><fields><name>actionUrl1</name><type>URL</type><fieldText>http://www.example.com/gsp/ukwid=4b9a156f-d0ab-41b2-b0e6-53d3b380dde7</fieldText></fields><fields><name>description</name><type>TEXT</type><fieldText>Find Hyundai Equus Specials &amp; Save!</fieldText></fields><fields><name>subject</name><type>TEXT</type><fieldText>Hyundai Equus Deals</fieldText></fields><fields><name>advertiser</name><type>TEXT</type><fieldText>car.com</fieldText></fields><fields><name>previewFileName</name><type>TEXT</type><fieldText>preview.jpg</fieldText></fields><fields><name>logoFileName</name><type>TEXT</type><fieldText>teaser.png</fieldText></fields><fields><name>Custom_layout</name><type>IMAGE</type><fieldMedia xsi:type="Image"><mediaId>1489628318</mediaId><referenceId>-8627339302394658816</referenceId><dimensions><key>FULL</key><value><width>0</width><height>0</height></value></dimensions><urls><key>FULL</key><value>https://tpc.googlesyndication.com/sadbundle/9819404771314892800/index.html</value></urls><sourceUrl>media://da/image?source=user_file&amp;id_from_source=GSP_Creative.zip&amp;operation=original</sourceUrl><name>GSP_Creative.zip</name><Media.Type>Image</Media.Type></fieldMedia></fields><fields><name>layout</name><type>ENUM</type><fieldText>Custom</fieldText></fields><fields><name>creationContext</name><type>TEXT</type><fieldText>WORKFLOW:BURDOCK,TEMPLATE_SOURCE:AD_GALLERY</fieldText></fields></templateElements><name>Display Ad created 8/5/15</name></ad><status>ENABLED</status></operand></operations></mutate></soap:Body></soap:Envelope>


Response:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Header><ResponseHeader xmlns="https://adwords.google.com/api/adwords/cm/v201502"><requestId>00051c9e53e2d7780a814607d50f1ad7</requestId><serviceName>AdGroupAdService</serviceName><methodName>mutate</methodName><operations>0</operations><responseTime>528</responseTime></ResponseHeader></soap:Header><soap:Body><soap:Fault><faultcode>soap:Server</faultcode><faultstring>[AdError.EMPTY_FIELD @ operations[0].operand.ad.templateElements[0].fields[7].fieldMedia.assetPath; trigger:'&lt;null&gt;']</faultstring><detail><ApiExceptionFault xmlns="https://adwords.google.com/api/adwords/cm/v201502"><message>[AdError.EMPTY_FIELD @ operations[0].operand.ad.templateElements[0].fields[7].fieldMedia.assetPath; trigger:'&lt;null&gt;']</message><ApplicationException.Type>ApiException</ApplicationException.Type><errors xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="AdError"><fieldPath>operations[0].operand.ad.templateElements[0].fields[7].fieldMedia.assetPath</fieldPath><trigger>&lt;null&gt;</trigger><errorString>AdError.EMPTY_FIELD</errorString><ApiError.Type>AdError</ApiError.Type><reason>EMPTY_FIELD</reason></errors></ApiExceptionFault></detail></soap:Fault></soap:Body></soap:Envelope>


Can some please provide the code for creating copy of template ads

Thanks

Anthony Madrigal

unread,
Aug 6, 2015, 4:16:01 PM8/6/15
to AdWords API Forum
Hi Hazar,

From your code, I notice that you are setting textadGroupAd.ad = newAd. However, I do not see newAd declared anywhere and you will want to set textadGroupAd.ad = templateAdNew.

If you are still getting this error, could you please reply privately to author your CID and the Ad ID of the ad you are trying to copy?

Thanks,
Anthony
AdWords API Team

Hazar Hayat

unread,
Aug 7, 2015, 4:39:57 AM8/7/15
to AdWords API Forum
Thanks for your reply I have the following statement in my code.

Ad newAd = templateAdNew;

I am not sure about the exact solution for creating copy of template ads if you can help me on this.

Thanks

Anthony Madrigal

unread,
Aug 7, 2015, 2:56:48 PM8/7/15
to AdWords API Forum
Hi Hazar,

After looking at your ad, I saw that its final URL is null, so when you set templateAdNew.finalUrls = templateAd.finalUrls there is no value going in there. Once you set that you should no longer be getting the EMPTY_FIELD error.

Cheers,
Anthony
AdWords API Team

Hazar Hayat

unread,
Aug 10, 2015, 7:31:12 AM8/10/15
to AdWords API Forum
The finalUrls value is going in the url element as you can see it in the post.

The problem is with the [templateElements[0].fields[7].fieldMedia.assetPath] field name is Custom_layout and field type is IMAGE which contain the zip file we uploaded for the gmail_custom_ad that contain the HTML,teaser images etc.I think that i need to set the contents of this element but I am unable to get this using MediaService because the MediaService return no record for the Media Id shown here.

Following is the element xml that I am using in the post.

<fields><name>Custom_layout</name><type>IMAGE</type><fieldMedia xsi:type="Image"><mediaId>1489628318</mediaId><referenceId>-8627339302394658816</referenceId><dimensions><key>FULL</key><value><width>0</width><height>0</height></value></dimensions><urls><key>FULL</key><value>https://tpc.googlesyndication.com/sadbundle/9819404771314892800/index.html</value></urls><sourceUrl>media://da/image?source=user_file&amp;id_from_source=GSP_Creative.zip&amp;operation=original</sourceUrl><name>GSP_Creative.zip</name><Media.Type>Image</Media.Type></fieldMedia></fields>

Please clarify what I am missing.

Is there any way I can download the GSP_Creative.zip using API?

Thanks

Josh Radcliff (AdWords API Team)

unread,
Aug 10, 2015, 8:51:42 PM8/10/15
to AdWords API Forum
Hi Hazar,

I was able to reproduce this issue on my side. It appears that the template ad validation is looking for the assetPath field, but that field is not settable via the API. Do you have to make copies of a large number of such ads, or just the handful in this particular ad group? If it's just this handful, I'd recommend editing/copying the ads through the user interface.

I will follow up with the template ads team to see if there's a work around, but using the user interface will be the fastest way to address this in the meantime.

Thanks,
Josh, AdWords API Team

Hazar Hayat

unread,
Aug 11, 2015, 5:09:36 AM8/11/15
to AdWords API Forum
Hi Josh,

Thanks for clarifying this.

We have an automated tagging process that append tracking code to the ads destination URLs once ads are created by the marketing team and it is difficult for to handle the tracking codes manually.

We found this issue in the Gmail Sponsored Promotions ads that are now integrated in the Adwords I think we need to handle it manually until the API issue is fixed.

One other thing that I want you to help me is that how the conversion tracking works when the form action URL is used instead of final URL when used submit the html form in the Gmail custom HTML ad because no gclid is appended to the landing URL and also the ValueTrack parameters like {device}, {matchtype} are not populated in the landing URL and we need this information in the Landing URL.

Thanks

Josh Radcliff (AdWords API Team)

unread,
Aug 11, 2015, 3:25:02 PM8/11/15
to AdWords API Forum
Hi Hazar,

Regarding your second question, since that's not specific to the API, I'd recommend posting to the AdWords Community. The product experts there should be able to help.

Thanks,
Josh, AdWords API Team

Josh Radcliff (AdWords API Team)

unread,
Sep 14, 2015, 11:35:30 AM9/14/15
to AdWords API Forum
Hi Hazar,

I heard back from the template ads team, and it turns out that template ID 486 is not fully supported by the API at the moment. Therefore, for now you'll have to use the user interface to create ads for that template.

Cheers,
Josh, AdWords API Team
Reply all
Reply to author
Forward
0 new messages