Last month, we announced  the ability to create both custom  and template creatives  using the DFP API. Today we’ll show you can use these premium-only features to create richer creatives with custom HTML.Custom or template HTML snippet  set within them, while template creatives are instantiated from system or user defined HTML snippets. Deciding which one to use depends on your network’s needs. If your network deals primarily with traffickers using the DFP UI, it may be beneficial for them to use creative templates in their workflow. The API could be used to retrieve these templates and report on them, but your traffickers would most likely want to create the creatives from templates in the UI.Creating custom creatives   String htmlSnippet = "<a href='%%CLICK_URL_UNESC%%%%DEST_URL%%'>"
      + "<img src='%%FILE:IMAGE_ASSET%%'/></a><br>Click for great deals!");
  CustomCreative customCreative = new CustomCreative();
      customCreative.setHtmlSnippet(htmlSnippet);
 
Notice here that the CLICK_URL_UNESC, DEST_URL, and FILE macros are used to customize the creative at serving time. CLICK_URL_UNESC will insert the clickthrough URL while DEST_URL inserts the URL that the ad points to. The FILE macro will reference any attached assets to the creative, in this case one named IMAGE_ASSET.   // Set the custom creative image asset.
  CustomCreativeAsset customCreativeAsset = new CustomCreativeAsset();
  customCreativeAsset.setMacroName("IMAGE_ASSET");
  customCreativeAsset.setAssetByteArray(/* Byte array from image. */);
  customCreativeAsset.setFileName(
      String.format("image%s.jpg", System.currentTimeMillis()));
  customCreative.setCustomCreativeAssets(
      new CustomCreativeAsset[] {customCreativeAsset});
 
You would then call CreativeService.createCreative  on customCreative to instantiate on the server. After creating the creative, you can then review it using the creative’s previewUrl  attribute or the newly added getPreviewUrl  method. When updating custom creatives, you don’t need to pass the asset byte array each time. Instead, you can leave it null with assetId  set to what it was assigned to when created. The full example  can be found on the Java client library page, as well as in our other libraries .Google+ +1 button  and customize the +1’s destination URL with the DEST_URL macro.Discover DFP API v201111 series , but if there’s any other topics you’d like to see, please let us know on the forum .Adam Rogal , DFP API Team