Posts tagged with google-ads-script

I have a script that shows 10 most clicked keywords, their average CPC and conversions. While previewing the script it works fine. But when I send it to my email, only last row of the 10 rows shows. What is wrong here?

function main() {   var keywords = AdsApp.keywords()       .orderBy("Clicks DESC")   //  .orderBy("Impressions DESC")       .forDateRange("THIS_MONTH")       .withLimit(10)       .get(); Logger.log("10 most clicked keywords");   while (keywords.hasNext()) {     var keyword = keywords.next();     content = keyword.getText() + " | Clicks: " + keyword.getStatsFor("THIS_MONTH").getClicks() + " | CPC: " + keyword.getStatsFor("THIS_MONTH").getAverageCpc().toFixed(2) +      " | Conversions: " + keyword.getStatsFor("THIS_MONTH").getConversions();   }    MailApp.sendEmail({             to: 'myemail@myemail.com',             subject: "10 most clicked keywords",             htmlBody: content });      }

I have created a script in GoogleAds to fetch this report: https://developers.google.com/adwords/api/docs/appendix/reports/product-partition-report from GoogleAds and insert the result as a table in BigQuery using the AdvanceAPI in GoogeAds.

The script I am running is built according to this sample code: https://developers.google.com/adwords/api/docs/appendix/reports/product-partition-report, provided by the Google Ads Script Team and they have also tried to help me in this matter.

The issue I am facing is that the first run of the script runs perfectly and creates a table in BQ and inserts the data as intended. However, when the script runs again (as sheduled 3 PM everyday) to get updated data from GoogleAds I get the following error message: API call to bigquery.tables.insert failed with error: Already Exists

The error message also provides the information that the issue is somewhere in this code:

table.tableReference = BigQuery.newTableReference(); table.tableReference.datasetId = CONFIG.BIGQUERY_DATASET_ID; table.tableReference.projectId = CONFIG.BIGQUERY_PROJECT_ID; table.tableReference.tableId = reportConfig.NAME; table = BigQuery.Tables.insert(table, CONFIG.BIGQUERY_PROJECT_ID,     CONFIG.BIGQUERY_DATASET_ID); 

But all this chunk of code is provided from the Google Ads Script Team so there should not be any problem with this?

So happy if someone could give me any guidance how to solve this!

Thanks in advance.

When I run an ads-script to call the app-script::spreadsheet API, I get the following error:

var sheet = SpreadsheetApp.openByUrl(SPREADSHEET_URL); var rangeValues = sheet.getRange(1, 1, sheet.getLastRow(), sheet.getLastColumn()).getValues(); ==> Cannot find method getRange(number,number,number,number) 

How can it be? Only a subset of the app-script sheet api is available from ads-script?