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.
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:
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:'<null>']</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:'<null>']</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><null></trigger><errorString>AdError.EMPTY_FIELD</errorString><ApiError.Type>AdError</ApiError.Type><reason>EMPTY_FIELD</reason></errors></ApiExceptionFault></detail></soap:Fault></soap:Body></soap:Envelope>