This is the legacy documentation for Google Ads scripts. Go to the current docs.

Bulk upload

Stay organized with collections Save and categorize content based on your preferences.

Bulk upload from Google Drive

function bulkUploadFromGoogleDrive() {
  // See https://developers.google.com/google-ads/scripts-legacy/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 = AdsApp.bulkUploads().newFileUpload(file);
  upload.forCampaignManagement();

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

Bulk upload from remote server

function bulkUploadFromRemoteServer() {
  // See https://developers.google.com/google-ads/scripts-legacy/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 = AdsApp.bulkUploads().newFileUpload(blob);
  upload.forCampaignManagement();

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

Bulk upload from Google Sheets

function bulkUploadFromGoogleSpreadsheet() {
  // The format of this spreadsheet should match a valid bulk upload template.
  // See https://developers.google.com/google-ads/scripts-legacy/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 = AdsApp.bulkUploads().newFileUpload(sheet);
  upload.forCampaignManagement();

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

Bulk upload from Google Ads reports

function bulkUploadFromGoogleAdsReports() {
  // 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 = AdsApp.report(query);

  // Create an upload with the report columns.
  var upload = AdsApp.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();
}

Create/update campaigns

function createOrUpdateCampaigns() {
  // See https://developers.google.com/google-ads/scripts-legacy/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 = AdsApp.bulkUploads().newCsvUpload(
      columns, {moneyInMicros: false});

  // Google Ads 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();
}

Retrieve column names in reports

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