Posts tagged with google-ads-api

I have this script set up but I am getting a 404 what do I need to do to make sure I can call the API?

const scriptProperties = PropertiesService.getScriptProperties(); function GIdea(keywords = "Demo") {     var accessToken = getOAuthToken();      var CLIENTID = scriptProperties.getProperty('CLIENTID');     var endpoint = 'https://googleads.googleapis.com/v10/customers/' + CLIENTID +'/keywordPlans:generateKeywordIdeas';     var requestBody = {       "customerId": CLIENTID,       "language": "ENGLISH",       "geo_target_constants": [],       "include_adult_keywords": false,       "page_size": 10,       "keyword_plan_network": "GOOGLE_SEARCH_AND_PARTNERS",       "keyword_seed": keywords     };     var options = {       'method': 'post',       'contentType': 'application/json',       'headers': {         'Authorization': 'Bearer ' + accessToken       },       'payload': JSON.stringify(requestBody)     };     var response = UrlFetchApp.fetch(endpoint, options);     var ideas = JSON.parse(response.getContentText());     return ideas; } function getOAuthToken() {   var CLIENTID = scriptProperties.getProperty('CLIENTID');   var SECRETFORADS = scriptProperties.getProperty('SECRETFORADS');   var service = OAuth2.createService('GoogleAds')     .setAuthorizationBaseUrl('https://accounts.google.com/o/oauth2/auth')     .setTokenUrl('https://accounts.google.com/o/oauth2/token')     .setClientId(CLIENTID)     .setClientSecret(SECRETFORADS)     .setScope('https://www.googleapis.com/auth/adwords');   if (!service.hasAccess()) {     return 'No access to Google Ads API';   }   var url = API_URL;   var headers = {     "Authorization": "Bearer " + service.getAccessToken(),     "Content-Type": "application/json",     "muteHttpExceptions": false   };   var options = {     "method": "get",     "headers": headers,   };   var response = UrlFetchApp.fetch(url, options);   var jsonResponse = JSON.parse(response.getContentText());   return jsonResponse } 

Exception: Request failed for https://googleads.googleapis.com returned code 404. Truncated server response: <titl... (use muteHttpExceptions option to examine full response) (line 70).

I call the function in a Google Sheets cell and get a 404 instead of the results of the API call.

I am following Google Ads documentation to fetch a refresh token. I have got to this step: https://developers.google.com/google-ads/api/docs/get-started/make-first-call#fetch_a_refresh_token

oauth2l fetch --credentials credentials.json --scope adwords \     --output_format refresh_token 

When I run the above command I get the error missing 'type' field in credentials

I found answers similar to this: https://github.com/GeneralElectric/GABeat/issues/2

So I tried adding "type": "service_account" to the json file but then I get this error instead: "private key should be a PEM or plain PKCS1 or PKCS8; parse error: asn1: syntax error: sequence truncated"

Below is the credentials.json file (after I added the "type" field). The original was downloaded during this step of the Google Ads documentation: https://developers.google.com/google-ads/api/docs/get-started/oauth-cloud-project#id-secret

{   "type": "service_account",   "web": {     "client_id": "XXXXXXXXXX.apps.googleusercontent.com",     "project_id": "XXXXXXXXXX",     "auth_uri": "https://accounts.google.com/o/oauth2/auth",     "token_uri": "https://oauth2.googleapis.com/token",     "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",     "client_secret": "XXXXXXXXXX",     "javascript_origins": [       "https://XXXXXXXXXX.co.uk"     ]   } } 

The goal is to take data we have and create google ads' Customer List with it automatically, using NodeJS, specifically this:

https://developers.google.com/google-ads/api/docs/remarketing/audience-segments/customer-match/get-started#create-customer

I looked into documentation for google-ads-api, googleapi and a couple of other libraries but found nothing helpful. I'm also pretty new with Google Ads API, so I might be missing something obvious.

There seems to be no good examples or documentation on this (except the PHP, C# etc ones in the above link), so if it's not possible in NodeJS I would love to have a concrete confirmation and/or explanation as to why.

I'm using the Google Ads API to retrieve information from Google Ads campaigns. Initially, I manually generated a new refresh token by following specific steps to obtain an authorization code using a designated Google ID. Subsequently, I sent a CURL request with that code to generate a refresh token. Now, I aim to automate the entire process to convert the script, responsible for fetching Google Ads campaign data, into a full-time scheduler by automating the generation and renewal of the refresh token. Unfortunately, I'm encountering difficulties in achieving this. Is there a specific code or method available to accomplish the aforementioned task?

I would like to obtain the process and code for the aforementioned issue.