Posts tagged with javascript

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.

Does anybody have some sample code that shows how to get the daily, total billed cost (across all campaigns) of a google ads account?

I have been looking for a sample for a while but could not find where you can get the total cost/billed cost for the day (or for a certain period of time).

I am doing this in Js but a sample in any language is okay. I would like to send this data to an airtable base, so if you have any suggestions on how that can be done too, that would be great!

Thanks in advance!

Recently I have been trying to create a script to retrieve either an accounts or individual campaigns optimisation scores and subsequently send a email including this. My problem is that I cannot find optimisation score in stats or metrics anyway I try.

Does anyone know if this is even a retrievable variable in scripts?

I’m building a custom Zap to integrate Google Local Service Ads API with our CRM. It appears everything is functioning properly however, I noticed several new leads are not coming through, which appears to be due to the API request sending nested data using the values nested under the same field .

Here is an example response:

    {     "leadId": "000000000",     "accountId": "000000000",     "businessName": "Acme, Inc",     "leadCreationTimestamp": "2022-08-09T16:21:14Z",     "leadType": "PHONE_CALL",     "leadCategory": "roofer",     "geo": "Miami,Florida,United States",     "phoneLead": {       "consumerPhoneNumber": "+15555555678"     },     "chargeStatus": "NOT_CHARGED",     "currencyCode": "USD",     "timezone": {       "id": "America/New_York"     },     "id": "0000000000"   },   {     "leadId": "000000000",     "accountId": "000000000",     "businessName": "Acme, Inc",     "leadCreationTimestamp": "2022-08-09T16:39:38Z",     "leadType": "MESSAGE",     "leadCategory": "roofer",     "geo": "Miami,Florida,United States",     "messageLead": {       "customerName": "Jane Doe",       "jobType": "attic_venting",       "postalCode": "33066",       "consumerPhoneNumber": "+15555555789"     },     "chargeStatus": "CHARGED",     "currencyCode": "USD",     "timezone": {       "id": "America/New_York"     },     "id": "1111111111"   },   {     "leadId": "000000000",     "accountId": "000000000",     "businessName": "Acme, Inc",     "leadCreationTimestamp": "2022-08-10T19:12:28Z",     "leadType": "PHONE_CALL",     "leadCategory": "window_repair",     "geo": "Miami,Florida,United States",     "phoneLead": {       "chargedCallTimestamp": "2022-08-10T19:12:28Z",       "chargedConnectedCallDurationSeconds": "280s",       "consumerPhoneNumber": "+15555555890"     },     "chargeStatus": "CHARGED",     "currencyCode": "USD",     "timezone": {       "id": "America/New_York"     },     "id": "2222222222"   }, 

The issue I’m running into is when mapping the data to our CRM, the trigger test data is providing multiple fields for ‘consumerPhoneNumber’ ( based on whether it is a message/phone lead and whether the call connected ). so we are unable to map phoneLead__consumerPhoneNumber and messageLead___consumerPhoneNumber to the same field.

duplicate fields example

How can I parse the API response to properly map the consumerPhoneNumber when the value changes based on messageLead_consumerPhoneNumber versus phoneLead_consumerPhoneNumber?

I understand some basic Javascript but parsing API data is new to me. Any help would be truly appreciated!

Here is the JavaScript code for our API request.

    const options = {   url: 'https://localservices.googleapis.com/v1/detailedLeadReports:search',   method: 'GET',   headers: {     'Authorization': `Bearer ${bundle.authData.access_token}`,     'X-QUERY': bundle.authData.query   },   params: {     'query': 'manager_customer_id:XXXXXXXXX',     'pageSize': '1000'   } } return z.request(options).then((response) => {   response.throwForStatus();   const results = response.json;   const lists = results["detailedLeadReports"].map((item) => {     return Object.assign(item, {       id: item["leadId"],     });   });   return lists; }); 

I am trying to implement Google ads enhanced conversions. I have the option of doing it using the gtag, google tag manager or using the Ads api. However, On the Ads api I don't see any documentation related to Node Js. I am not able to figure out how I can make use of the Ads api to implement enhanced conversions with Node Js.

This is the official documentation for enhanced conversion using Ads api and i don't see anything related to Node Js

https://developers.google.com/google-ads/api/docs/conversions/enhance-conversions