Ad display assets

Add a Quick link asset
Set a Quick link asset
Add a Call asset
Set a Call asset
Add a callout asset
Set a callout asset
Add a Category snippet asset
Set a Category snippet asset
Add an Image asset from Google Drive
Get all assets

function addQuicklinkAsset() {
  const accountId = AdsUtilities.getCurrentAccountId();
  const assetArray = [
    {
      accountId: accountId,
      assetData: {
        type: 'QUICKLINK',
        quickLinkAsset: {
          linkText: 'linkText AAA',
          description1: 'description1 BBB',
          description2: 'description2 CCC',
        }
      },
      finalUrl: 'http://xxxxx.co.jp/aaaaa/bbbbb',
    }
  ];//Multiple selections are possible
  const assets = Search.AssetService.add({
    accountId: accountId,
    operand: assetArray,
  }).rval;
  for (let i = 0; i < assets.values.length; i++) {
    if (assets.values[i].operationSucceeded) {
      let asset = assets.values[i].asset;
      Logger.log('assetId-> ' + asset.assetId + ' has been added.');
    } else {
      Logger.log('linkText-> ' + assetArray[i].assetData.quickLinkAsset.linkText + 
      ', description1-> ' + assetArray[i].assetData.quickLinkAsset.description1 + 
      ', description2-> ' + assetArray[i].assetData.quickLinkAsset.description2 + ' could not be added.');
    }
  } 
}

function setQuicklinkAsset() {
  const accountId = AdsUtilities.getCurrentAccountId();
  const assetArray = [
    {
      accountId: accountId,
      assetId: 1111111,
      assetData: {
        type: 'QUICKLINK',
        quickLinkAsset: {
          linkText: 'New linkText DDD',
          description1: 'New description1 EEE',
          description2: 'New description2 FFF',
        }
      },
      finalUrl: 'http://yyyyy.co.jp/ccccc/ddddd',
    }
  ];//Multiple selections are possible
  const assets = Search.AssetService.set({
    accountId: accountId,
    operand: assetArray,
  }).rval;
  for (let i = 0; i < assets.values.length; i++) {
    if (assets.values[i].operationSucceeded) {
      let asset = assets.values[i].asset;
      Logger.log('assetId-> ' + asset.assetId + ' has been updated.');
    } else {
      Logger.log('assetId-> ' + assetArray[i].assetId + ' could not be updated.');
    }
  } 
}

Add a Call asset


function addCallAsset() {
  const accountId = AdsUtilities.getCurrentAccountId();
  const assetArray = [
    {
      accountId: accountId,
      assetData: {
        type: 'CALL',
        callAsset: {
          phoneNumber: '00-0000-0000',
        }
      }
    }
  ];//Multiple selections are possible
  const assets = Search.AssetService.add({
    accountId: accountId,
    operand: assetArray,
  }).rval;
  for (let i = 0; i < assets.values.length; i++) {
    if (assets.values[i].operationSucceeded) {
      let asset = assets.values[i].asset;
      Logger.log('assetId-> ' + asset.assetId + ' has been added.');
    } else {
      Logger.log('phoneNumber-> ' + assetArray[i].assetData.callAsset.phoneNumber + ' could not be added.');
    }
  } 
}

Set a Call asset


function setCallAsset() {
  const accountId = AdsUtilities.getCurrentAccountId();
  const assetArray = [
    {
      accountId: accountId,
      assetId: 1111111,
      assetData: {
        type: 'CALL',
        callAsset: {
          phoneNumber: '00-0000-0000',
        }
      }
    }
  ];//Multiple selections are possible
  const assets = Search.AssetService.set({
    accountId: accountId,
    operand: assetArray,
  }).rval;
  for (let i = 0; i < assets.values.length; i++) {
    if (assets.values[i].operationSucceeded) {
      let asset = assets.values[i].asset;
      Logger.log('assetId-> ' + asset.assetId + ' has been updated.');
    } else {
      Logger.log('assetId-> ' + assetArray[i].assetId + ' could not be updated.');
    }
  } 
}

Add a Callout asset


function addCalloutAsset() {
  const accountId = AdsUtilities.getCurrentAccountId();
  const assetArray = [
    {
      accountId: accountId,
      assetData: {
        type: 'CALLOUT',
        calloutAsset: {
          calloutText: 'New calloutText AAA',
        }
      }
    }
  ];//Multiple selections are possible
  const assets = Search.AssetService.add({
    accountId: accountId,
    operand: assetArray,
  }).rval;
  for (let i = 0; i < assets.values.length; i++) {
    if (assets.values[i].operationSucceeded) {
      let asset = assets.values[i].asset;
      Logger.log('assetId-> ' + asset.assetId + ' has been added.');
    } else {
      Logger.log('calloutText-> ' + assetArray[i].assetData.calloutAsset.calloutText + ' could not be added.');
    }
  } 
}

Set a Callout asset


function setCalloutAsset() {
  const accountId = AdsUtilities.getCurrentAccountId();
  const assetArray = [
    {
      accountId: accountId,
      assetId: 2222222,
      assetData: {
        type: 'CALLOUT',
        calloutAsset: {
          calloutText: 'New calloutText BBB',
        }
      }
    }
  ];//Multiple selections are possible
  const assets = Search.AssetService.set({
    accountId: accountId,
    operand: assetArray,
  }).rval;
  for (let i = 0; i < assets.values.length; i++) {
    if (assets.values[i].operationSucceeded) {
      let asset = assets.values[i].asset;
      Logger.log('assetId-> ' + asset.assetId + ' has been updated.');
    } else {
      Logger.log('assetId-> ' + assetArray[i].assetId + ' could not be updated.');
    }
  } 
}

Add a Category snippet asset


function addCategorySnippetAsset() {
  const accountId = AdsUtilities.getCurrentAccountId();
  const assetArray = [
    {
      accountId: accountId,
      assetData: {
        type: 'STRUCTURED_SNIPPET',
        structuredSnippetAsset: {
          header: 'タイプ', //指定できる値は次のヘルプページの「補足カテゴリー」列をご覧ください。:https://ads-help.yahoo-net.jp/s/article/H000044718?language=ja
          values: ['sample1','sample2','sample3']
        }
      }
    }
  ];//Multiple selections are possible
  const assets = Search.AssetService.add({
    accountId: accountId,
    operand: assetArray,
  }).rval;
  for (let i = 0; i < assets.values.length; i++) {
    if (assets.values[i].operationSucceeded) {
      let asset = assets.values[i].asset;
      Logger.log('assetId-> ' + asset.assetId + ' has been added.');
    } else {
      Logger.log('header-> ' + assetArray[i].assetData.structuredSnippetAsset.header + ' could not be added.');
    }
  } 
}

Set a Category snippet asset


function setCategorySnippetAsset() {
  const accountId = AdsUtilities.getCurrentAccountId();
  const assetArray = [
    {
      accountId: accountId,
      assetId: 222222,
      assetData: {
        type: 'STRUCTURED_SNIPPET',
        structuredSnippetAsset: {
          header: 'タイプ', //指定できる値は次のヘルプページの「補足カテゴリー」列をご覧ください。:https://ads-help.yahoo-net.jp/s/article/H000044718?language=ja
          values: ['sample A','sample B','sample C']
        }
      }
    }
  ];//Multiple selections are possible
  const assets = Search.AssetService.set({
    accountId: accountId,
    operand: assetArray,
  }).rval;
  for (let i = 0; i < assets.values.length; i++) {
    if (assets.values[i].operationSucceeded) {
      let asset = assets.values[i].asset;
      Logger.log('assetId-> ' + asset.assetId + ' has been updated.');
    } else {
      Logger.log('assetId-> ' + assetArray[i].assetId + ' could not be updated.');
    }
  } 
}

Add an Image asset from Google Drive


function addImageAsset() {
  const accountId = AdsUtilities.getCurrentAccountId();
  const fileId = '12345abcde';
  const fileBytes = DriveApp.getFileById(fileId).getBlob().getBytes();
  const encoded = Utilities.base64Encode(fileBytes);
  const assetArray = [
    {
      accountId: accountId,
      assetData: {
        type: 'IMAGE',
        imageAsset: {
          imageName: 'New image AAA',
          data: encoded,
        }
      }
    }
  ];//Multiple selections are possible
  const assets = Search.AssetService.add({
    accountId: accountId,
    operand: assetArray,
  }).rval;
  for (let i = 0; i < assets.values.length; i++) {
    if (assets.values[i].operationSucceeded) {
      let asset = assets.values[i].asset;
      Logger.log('assetId-> ' + asset.assetId + ' has been added.');
    } else {
      Logger.log('imageName-> ' + assetArray[i].assetData.imageAsset.imageName + ' could not be added.');
    }
  }
}

Get all assets


function getAsset() {
  const accountId = AdsUtilities.getCurrentAccountId();
  const assets = Search.AssetService.get({
    accountId: accountId,
  }).rval;
  if (assets.totalNumEntries == 0) {
    Logger.log('Target ID does not exist.');
    return;
  }
  for (let i = 0; i < assets.values.length; i++){
    let asset = assets.values[i].asset;
    Logger.log('assetId-> ' + asset.assetId + ', type-> ' + asset.assetData.type);
  }
}