Hide
AdWords scripts

Bulk upload

  1. Bulk upload from Google Drive
  2. Bulk upload from remote server
  3. Bulk upload from Google Sheets
  4. Bulk upload from AdWords reports
  5. Create/update campaigns
  6. Retrieve column names in reports

Bulk upload from Google Drive

function bulkUploadFromGoogleDrive() {
  // See https://developers.google.com/adwords/scripts/docs/features/bulk-upload
  // for the list of supported bulk upload templates.
  // You can upload a CSV file, or an EXCEL sheet.
  var file = DriveApp.getFilesByName('BulkCampaignUpload.csv').next();
  var upload = AdWordsApp.bulkUploads().newFileUpload(file);
  upload.forCampaignManagement();

  // Use upload.apply() to make changes without previewing.
  upload.preview();
}

Back to top

Bulk upload from remote server

function bulkUploadFromRemoteServer() {
  // See https://developers.google.com/adwords/scripts/docs/features/bulk-upload
  // for the list of supported bulk upload templates.
  var dataUrl = 'INSERT_CSV_FILE_URL_HERE';

  var blob = UrlFetchApp.fetch(dataUrl)
      .getBlob()
      .getAs(MimeType.CSV);

  var upload = AdWordsApp.bulkUploads().newFileUpload(blob);
  upload.forCampaignManagement();

  // Use upload.apply() to make changes without previewing.
  upload.preview();
}

Back to top

Bulk upload from Google Sheets

function bulkUploadFromGoogleSpreadsheet() {
  // The format of this spreadsheet should match a valid bulk upload template.
  // See https://developers.google.com/adwords/scripts/docs/features/bulk-upload
  // for the list of supported bulk upload templates.
  var SPREADSHEET_URL = 'INSERT_SPREADSHEET_URL_HERE';
  var spreadSheet = SpreadsheetApp.openByUrl(SPREADSHEET_URL);
  var sheet = spreadSheet.getActiveSheet();

  var upload = AdWordsApp.bulkUploads().newFileUpload(sheet);
  upload.forCampaignManagement();

  // Use upload.apply() to make changes without previewing.
  upload.preview();
}

Back to top

Bulk upload from AdWords reports

function bulkUploadFromAdWordsReports() {
  // Run a report to fetch all campaigns that spent more than $1000
  // this month.
  var query = 'SELECT CampaignId,CampaignName,CampaignStatus,Amount ' +
      'FROM CAMPAIGN_PERFORMANCE_REPORT ' +
      'WHERE Amount > 1000000000 ' +
      'DURING THIS_MONTH';
  var report = AdWordsApp.report(query);

  // Create an upload with the report columns.
  var upload = AdWordsApp.bulkUploads().newCsvUpload([
      report.getColumnHeader('CampaignId').getBulkUploadColumnName(),
      report.getColumnHeader('CampaignName').getBulkUploadColumnName(),
      report.getColumnHeader('CampaignStatus').getBulkUploadColumnName()]);
  upload.forCampaignManagement();

  var rows = report.rows();
  while (rows.hasNext()) {
    var row = rows.next();
    // Pause the campaigns.
    row.CampaignStatus = 'paused';

    // Convert the report row into an upload row.
    upload.append(row.formatForUpload());
  }

  // Use upload.apply() to make changes without previewing.
  upload.preview();
}

Back to top

Create/update campaigns

function createOrUpdateCampaigns() {
  // See https://developers.google.com/adwords/scripts/docs/features/bulk-upload
  // for the list of supported bulk upload templates and their column names.
  var columns = [
    'Campaign', 'Budget', 'Bid Strategy type', 'Campaign type'
  ];

  var upload = AdWordsApp.bulkUploads().newCsvUpload(columns,
      {moneyInMicros: false});

  // AdWords identify existing campaigns using its name. To create a new
  // campaign, use a campaign name that doesn't exist in your account.
  upload.append({
    'Campaign': 'Test Campaign 1',
    'Budget': 234,
    'Bid Strategy type': 'cpc',
    'Campaign type': 'Search Only'
  });
  // Use upload.apply() to make changes without previewing.
  upload.preview();
}

Back to top

Retrieve column names in reports

function getColumnsFromReport() {
  var report = AdWordsApp.report('SELECT CampaignName, CampaignStatus ' +
      'FROM CAMPAIGN_PERFORMANCE_REPORT ' +
      'DURING TODAY');
  Logger.log('%s, %s',
    report.getColumnHeader('CampaignName').getBulkUploadColumnName(),
    report.getColumnHeader('CampaignStatus').getBulkUploadColumnName()
  );
}

Back to top