Hi, my daily scheduled script is suddenly getting the following error:
5/23/2024 11:08:03 AM
Exception: You do not have permission to access the requested document.
at main (Code:9:36)
at Object.<anonymous> (adsapp_compiled:20513:54)
The script has worked for months up until this point. below is the script. Would you be able to offer any insight as to what might be happening?
function main() {
// Define the custom date range
var today = new Date();
var firstDayOfMonth = new Date(today.getFullYear(), today.getMonth(), 1);
var startDate = Utilities.formatDate(firstDayOfMonth, 'GMT', 'yyyyMMdd'); // first day of current month
var endDate = Utilities.formatDate(new Date(), 'GMT', 'yyyyMMdd'); // today's date
// Open the spreadsheet
var spreadsheet = SpreadsheetApp.openById('XXXXXXXXXXXXXXXXXXX'); // Worksheet Id
var sheet = spreadsheet.getSheetByName('DL_PMAX'); // Sheet name
// Clear the existing content
sheet.clearContents();
// Set the headers
sheet.appendRow(['Account Name','Account ID','Campaign Name', 'Campaign ID', 'IsPaused?', 'Budget Amount', 'Cost','Monthly Budget', 'Cost/Conv']);
// Select the account
var mccAccount = AdsApp.currentAccount();
var accountIterator = AdsManagerApp.accounts().get();
while (accountIterator.hasNext()) {
var account = accountIterator.next();
// Select the client account to operate on.
AdsManagerApp.select(account);
// Get all PMAX campaigns
var performanceMaxCampaignIterator = AdsApp.performanceMaxCampaigns()
//.withCondition('Status = ENABLED') // only include running campaigns
.get();
while (performanceMaxCampaignIterator.hasNext()) {
var campaign = performanceMaxCampaignIterator.next();
// Get the budget
var budget = campaign.getBudget();
var budgetAmount = budget.getAmount();
var monthlyBudget = budgetAmount * 30.4; // assuming 30.4 days in a month
// Get the cost for the custom date range
var report = AdsApp.report(
'SELECT CampaignName, CampaignId, Amount, Cost, CostPerConversion ' +
'FROM CAMPAIGN_PERFORMANCE_REPORT ' +
'WHERE CampaignId = ' + campaign.getId() +
' DURING ' + startDate + ',' + endDate
);
// Add the budget information to the sheet
var rows = report.rows();
while (rows.hasNext()) {
var row = rows.next();
sheet.appendRow([account.getName(), account.getCustomerId(), row['CampaignName'], campaign.getId(), campaign.isPaused(), budgetAmount, row['Cost'], monthlyBudget, row['CostPerConversion']]);
}
}
// Select the MCC account again
AdsManagerApp.select(mccAccount);
}
}