Script not finding Campaign ID

128 views
Skip to first unread message

Bautista Triulzi

unread,
Jun 13, 2023, 2:28:14 PM6/13/23
to Google Ads Scripts Forum
Hi! i am trying to turn on and off a campaign when temperature is below 12 degrees. Everything seems to work but google can't find the campaign id (even though it exists).

This is the script:

function main() {
  var apiKey = 'e68ee8d48db6ada4fee39223b2c7b4a4';
  var cityId = '3433955';
  var campaignId = 20275597918;
  var response = UrlFetchApp.fetch('https://api.openweathermap.org/data/2.5/weather?id=' + cityId + '&appid=' + apiKey);
  var weatherData = JSON.parse(response.getContentText());
  var temperatureKelvin = weatherData.main.temp;
  var temperatureCelsius = temperatureKelvin - 273.15; // Convert to Celsius
 
  Logger.log('Temperature in Celsius: ' + temperatureCelsius);
 
  var campaignIterator = AdsApp.campaigns().withIds([campaignId]).get();
 
  // Check if the campaign with the given ID exists
  if (campaignIterator.hasNext()) {
    var campaign = campaignIterator.next();
   
    if (temperatureCelsius <= 12) {
      campaign.enable();
      Logger.log('Campaign enabled');
    }
   
    if (temperatureCelsius > 12) {
      campaign.pause();
      Logger.log('Campaign paused');
    }
  } else {
    Logger.log('No campaign found with the ID: ' + campaignId);
  }
}


Thanks!!!!

Sigurd Fabrin

unread,
Jun 14, 2023, 5:46:14 AM6/14/23
to Google Ads Scripts Forum
Note that AdsApp.campaigns() only returns standard text and display campaigns.

Example: if it's a shopping campaign, you need to use AdsApp.​ShoppingCampaign() etc



Sigurd

Google Ads Scripts Forum

unread,
Jul 11, 2023, 1:54:36 AM7/11/23
to Google Ads Scripts Forum
Reposting the last inquiry (https://groups.google.com/g/adwords-scripts/c/6DMpGxsAlsA) from the forum as it wasn't routed to our support queue.

Regards,
Google Ads Scripts Team

Google Ads Scripts Forum

unread,
Jul 11, 2023, 1:59:15 AM7/11/23
to Google Ads Scripts Forum
Hi All,

Thank you for reaching out to the Google Ads Scripts Team. Please excuse us for only getting back now as your message failed to be routed to our support queue.

@Sigurd - Thank you for your insights.

@Bautista - I would agree with Sigurd's response. Kindly note that there are specific selectors to use when accessing campaigns that are supported in Google Ads Scripts. Currently, only display, search, video, shopping and performance max campaigns are supported. You may refer to the documentation <https://developers.google.com/google-ads/scripts/docs/reference/adsapp/adsapp> for their respective selectors.

Let us know how it goes on your end. In the event that you still encounter any issues, kindly provide your Google Ads account ID and the name of your script so we're able to further investigate.

Best regards,
Google Ads Scripts Team
Reply all
Reply to author
Forward
0 new messages