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).
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!!!!