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


Parse XML

function parseXml() {
  // Load an XML representation of your campaigns.
  var xml = [
      '<?xml version="1.0" encoding="UTF-8"?>',
        '<campaign id="28632346">Placement Campaign 1</campaign>',
        '<campaign id="28780216">Campaign #14</campaign>',
        '<campaign id="29606506">LotsOfExclusion</campaign>',

  var document = XmlService.parse(xml);
  var root = document.getRootElement();

  var entries = document.getRootElement().getChildren('campaign');
  for (var i = 0; i < entries.length; i++) {
    var id = entries[i].getAttribute('id').getValue();
    var name = entries[i].getText();
    Logger.log('%s) %s (%s)', (i + 1).toFixed(), name, id);

Create XML

function createXml() {
  // Create and log an XML representation of your campaigns.
  var root = XmlService.createElement('campaigns');
  var campaignIterator = AdsApp.campaigns().get();

  while (campaignIterator.hasNext()) {
    var campaign =;

    var child = XmlService.createElement('campaign')
        .setAttribute('id', campaign.getId().toFixed(0))
  var document = XmlService.createDocument(root);
  var xml = XmlService.getPrettyFormat().format(document);