I am trying to automate enabling and pausing the Demand Gen ad (not campaign, not ad group) based on a criteria that I set. The script worked to identify based on the criteria but it failed to do the actual job, which is to pause and enable the ad.
For the pause and enabling command, I tried some different approach and everything failed.
1. Direct Action (.pause()/.enable()): This failed because the script couldn't find the ad objects ("Could not find ad object").
2. Bulk Upload (Resource Name): This failed because the system accepted the job but made "No changes".
3. Bulk Upload (Ad ID): This failed because the system rejected the file with a "system error".
Is it currently not possible to use ads script to pause/enable Demand Gen ad? Thank you for your help.
This is the code for example:
// --- TEST SCRIPT ---
// This script will find ONE specific Demand Gen ad by its name and pause it.
function main() {
// 1. The exact name of the ad you want to pause
const AD_NAME_TO_PAUSE = "ad name example";
Logger.log(`Starting test to pause ad: ${AD_NAME_TO_PAUSE}`);
// 2. Find the ad's Resource Name using a GAQL query
// We only want to find it if it's currently ENABLED
const query = `
SELECT
ad_group_ad.resource_name,
ad_group_ad.ad.name,
ad_group_ad.status
FROM ad_group_ad
WHERE
ad_group_ad.ad.name = "${AD_NAME_TO_PAUSE}"
AND ad_group_ad.status = 'ENABLED'
`;
const report = AdsApp.search(query);
const changesToUpload = [];
// 3. Get the ad's resource name
if (report.hasNext()) {
const row = report.next();
const resourceName = row.adGroupAd.resourceName;
Logger.log(`Found enabled ad. Resource Name: ${resourceName}`);
changesToUpload.push({
resource: resourceName,
status: "PAUSED"
});
} else {
Logger.log("Ad not found. It might be already paused, removed, or the name is incorrect.");
return; // Stop the script
}
// 4. Apply the change using Bulk Upload
if (changesToUpload.length > 0) {
Logger.log("Submitting 1 change (pause) via Bulk Upload...");
const bulkUpload = AdsApp.bulkUploads().newCsvUpload([
"Ad Group Ad Resource Name", "Status"
]);
bulkUpload.append({
"Ad Group Ad Resource Name": changesToUpload[0].resource,
"Status": changesToUpload[0].status
});
// Apply() is LIVE mode. This actually makes the change.
bulkUpload.apply();
Logger.log("--- TEST SUCCESSFUL ---");
Logger.log("Change has been applied. Please check the Google Ads UI in 1-2 minutes.");
} else {
Logger.log("--- TEST FAILED ---");
Logger.log("Could not find the specified ad while it was 'ENABLED'.");
}
}