Copy creative from existing creative template (PHP)

73 views
Skip to first unread message

Rory Willis

unread,
May 29, 2018, 3:25:43 PM5/29/18
to Google's DoubleClick for Publishers API Forum
Hello,

I am trying to copy creatives that are built with a template via the API. My process so far is this:

1) Get the old creative, which returns a template creative object
2) Remove the existing ID from the object and remove all asset IDs from the creative template variable values
3) Create a new creative with the template creative object that was modified

This all works fine until I get to step 3, and then it tells me that I am missing required creative template variable values. I am able to see that the required value are filled inside of the template creative object though.

My soap error log provides the following:

[2018-05-29 19:21:51] DFP_SOAP.WARNING: networkCode=43459271 service=CreativeService method=createCreatives responseTime=146 requestId=f4cff9e13f5a130b2afbd44c7cf2bcd9 server=ads.google.com isFault=1 faultMessage=[RequiredError.REQUIRED @ [0].creativeTemplateVariableValues.PortraitImage, RequiredError.REQUIRED @ [0].creativeTemplateVariableValues.LandscapeImage]  

With this in mind, am I going about this the wrong way? Thanks for any guidance you can provide.

Vincent Racaza (DFP API Team)

unread,
May 30, 2018, 6:13:39 AM5/30/18
to Google's DoubleClick for Publishers API Forum
Hi Rory,

The RequiredError means that you have not set a required field in your request, on your scenario, the creativeTemplateVariableValues for those two images. It seems that this is due to your step 2 on which you removed all the asset IDs from the creative template variable values. If the creative template that you are using in your creative creation requires these two images, and you removed them, then that's the cause of the error message.

You need to retain these assets or set new assets/values for the creativeTemplateVariableValues field. You can also check via the DFP UI or via the API's CreativeTemplateService for the required creativeTemplateVariableValues that you need to set based on your specific creative template.

Kindly do this suggestion on your end and let me know how it goes. If the issue still persists, please provide your complete SOAP request and response logs. You may use the Reply privately to author option.

Thanks,
Vincent Racaza, DFP API Team

Rory Willis

unread,
May 30, 2018, 9:22:02 AM5/30/18
to Google's DoubleClick for Publishers API Forum
Thank you for your help! I solved the problem by passing a byte array to the creative asset contained in my template variable values.

For anyone that may run into this in the future, it's as simple as running file_get_contents() to store your image, passing the data as the byte array, and then providing a unique filename. 

Here's an example that assumes you have an existing creative asset that you want to copy:

$imageURL = $creative->getCreativeTemplateVariableValues()[$x]->getAsset()->getAssetUrl(); //creative URL
$image = file_get_contents($imageURL); //download the URL
$creative->creativeTemplateVariableValues()[$x]->getAsset()->setAssetByteArray($image); //set byte array to downloaded image
$filename = $creative->getCreativeTemplateVariableValues()[$x]->getAsset()->getFileName(); //get file name
$creative->creativeTemplateVariableValues()[$x]->getAsset()->setFileName(uniqid().'_'.$filename); //create a unique filename

//then proceed with creating the new creative using the old creative object


Reply all
Reply to author
Forward
0 new messages