Posts tagged with google-apps-script

I wanna get out campaigns reports using Google Rest API and it does'nt work in Google ads Apps script.

My code:

function main() {    const API_VERSION = "12"; const CUSTOMER_ID = "***"; //contais real custommer ID const DEVELOPER_TOKEN = "***"; //contais real developper ID const MANAGER_CUSTOMER_ID = "***"; //contais real manager ID const OAUTH2_ACCESS_TOKEN = ""; //contais real ACCES TOKEN const data = {   "pageSize": 10000,   "query": "SELECT ad_group_criterion.keyword.text, ad_group_criterion.status FROM ad_group_criterion WHERE ad_group_criterion.type = 'KEYWORD' AND ad_group_criterion.status = 'ENABLED'" }; const url = `https://googleads.googleapis.com/v${API_VERSION}/customers/${CUSTOMER_ID}/googleAds:search`; const options = {   method: "POST",   headers: {     "Content-Type": "application/json",     "developer-token": DEVELOPER_TOKEN,     "login-customer-id": MANAGER_CUSTOMER_ID,     "Authorization": `Bearer ${OAUTH2_ACCESS_TOKEN}`   },   body:  JSON.stringify(data),    "muteHttpExceptions": true }; Logger.log(UrlFetchApp.fetch(url, options)); } 

Result error: { "error": { "code": 400, "message": "Request contains an invalid argument.", "status": "INVALID_ARGUMENT", "details": [ { "@type": "type.googleapis.com/google.ads.googleads.v12.errors.GoogleAdsFailure", "errors": [ { "errorCode": { "queryError": "UNEXPECTED_END_OF_QUERY" }, "message": "Error in query: unexpected end of query." } ], "requestId": "zKBR9-dJoG9NWAx3iJea2g" } ] } }

But query is valid https://developers.google.com/google-ads/api/fields/v11/query_validator enter image description here

Could you plese help?

Thanks

I wanna get out campaigns reports using Google Rest API and it does'nt work. My code and result is above.

I'm simply trying to construct a test script that can change/mutate a specific campaign budget using the REST interface of the Google Ads API on Google Apps Scripts but I keep on running into the following error:

Exception: Request failed for https://googleads.googleapis.com returned code 400. Truncated server response: { "error": { "code": 400, "message": "Invalid JSON payload received. Unexpected token.\nvalidateOnly=true&pa\n^", "status": "INVALID_... (use muteHttpExceptions option to examine full response)

The relevant function code is as follows:

//API specific variables const developer_token = {DEVELOPER TOKEN}; const parent_mcc_id = "xxxxxxxxxx"; //Temporary placeholder values var child_customer_id = "xxxxxxxxxx"; var budget_id = "xxxxxxxxxx";   let headers = {      Authorization: "Bearer " + ScriptApp.getOAuthToken(),      "developer-token": developer_token,      "login-customer-id": parent_mcc_id   };   //Make API call to retrieve each Google Ads account   try{     let requestParams = {      method: "POST",      contentType: "application/json",      headers: headers,      payload: {        operations:        [         {           updateMask: "amount_micros",           update:{             resourceName: "customers/" + child_customer_id + "/campaignBudgets/" + budget_id,             amountMicros: "60000000"           }         }        ],       "partialFailure": true,       "validateOnly": true,       "responseContentType": "RESOURCE_NAME_ONLY"       }     }          var url = ("https://googleads.googleapis.com/v11/customers/{CHILD ACCOUNT ID}/campaignBudgets:mutate");     Logger.log(requestParams.payload);     var postChange = UrlFetchApp.fetch(url, requestParams);   }   catch(e) {    Logger.log(e);   } 

I have used similar functions with queries in the payload portion to get data through the Google Ads API, place the data in an array and dump it into a spreadsheet, so I know that my developer token, mcc ids, and child account ids are correct. Any help would be greatly appreciated!

Meta recently released the cloud api to send messages from Whatsapp business, but I can't send it from the google app script.

I have this code, it runs fine... but it doesn't reach the user

    function SendToUser() {       var headers = {         'Authorization' : 'Bearer ACCESS_TOKEN',         'Content-Type': 'application/json'         };                   var payload = {         "messaging_product": "whatsapp",         "recipient_type": "individual",         "to": "PHONE_NUMBER",         "type": "text",         "text": { // the text object            "preview_url": false,            "body": "MESSAGE_CONTENT"         }        }               var options = {         method: "POST",         headers: headers,         payload: JSON.stringify(payload) // <--- Modified       }            let response = UrlFetchApp.fetch("https://graph.facebook.com/v13.0/FROM_PHONE_NUMBER_ID/messages", options);       Logger.log(response)                  } 

Really sorry if this is the basic question.

I have been searching for two days to find the documentation/sample function to use in apps script that fetches google ads accounts, reports, etc. what I have found all, is the documentation for languages like PHP, python, c, etc and they are giving me tough time understanding them. I know integrating google ads in google sheets is possible as google itself has published an add-on to fetch the reports but can't find any hint either in this platform or in the official documentation. any help will be highly appreciated.

Note: I am seeking help for integrating google ads in google sheets through apps script not ads script. I know there are functions available for ads script even in the documentation but none I found for apps script to the best of my research.

Thanks.

I have this GAQL:

  var query = 'SELECT \     customer.id,\     customer.descriptive_name,\     group_placement_view.placement_type,\     group_placement_view.display_name,\     metrics.average_cpm\  FROM group_placement_view\  WHERE\     group_placement_view.placement_type IN ("YOUTUBE_CHANNEL")\     AND campaign.advertising_channel_type = "VIDEO"\     AND segments.date BETWEEN "'+ fromDate.query_date + '" AND "' + toDate.query_date + '"\     AND metrics.impressions >= 100\     AND metrics.average_cpm > 1000000' 

IIUC it segments data by days. Correct? segments.date

But the metrics.impressions >= 100 relates to the aggregated data of the whole period. Right?