google-ads-api icon indicating copy to clipboard operation
google-ads-api copied to clipboard

Last field of a query is corrupted in a response if there're newlines in the query

Open evil-shrike opened this issue 1 year ago • 1 comments

In v19 a bug was introduced. A last field in a query is corrupted.

For instance, given a query from the following sample, the last field is 'metrics.conversions_value'. In a response we'll: metrics: { conversions_valuefromasset_group_assetwherecampaign: null } (conversions_valuefromasset_group_assetwherecampaign instead just conversions_value)

If I add another metric:

const query = `SELECT asset_group.id,  metrics.conversions_value, metrics.conversions
FROM asset_group_asset WHERE campaign.advertising_channel_type = 'PERFORMANCE_MAX' 

then the result will be:

metrics: {
  conversions_value: 67.98,
  conversionsfromasset_group_assetwherecampaign: null
}

Something is wrong with newlines. If I put all query in one line, it works as expected: const query = SELECT asset_group.id, metrics.conversions_value, metrics.conversions FROM asset_group_asset WHERE campaign.advertising_channel_type = 'PERFORMANCE_MAX' ;

import fs from 'fs';
import {Customer, errors, GoogleAdsApi} from 'google-ads-api';
import yaml from 'js-yaml';

const query = `SELECT asset_group.id,  metrics.conversions_value
FROM asset_group_asset WHERE campaign.advertising_channel_type = 'PERFORMANCE_MAX' 
AND campaign.status = 'ENABLED'
AND asset_group.status = 'ENABLED'
AND asset_group_asset.status = 'ENABLED'
AND asset_group_asset.source = 'ADVERTISER'`;

function getCustomer(config, customerId) {
  const client = new GoogleAdsApi({
    client_id: config.client_id,
    client_secret: config.client_secret,
    developer_token: config.developer_token,
  });
  const customer = client.Customer({
    customer_id: customerId,
    login_customer_id: config.login_customer_id,
    refresh_token: config.refresh_token,
  });
  return customer;
}

async function main() {
  const content = fs.readFileSync('google-ads.yaml')
  const config = yaml.load(content)
  const customerId = 8986667998
  const customer = getCustomer(config, customerId);

  const res = await customer.query(query);
  console.log(res);
}

main().catch(console.error);

evil-shrike avatar Apr 15 '25 13:04 evil-shrike

Hello there,

We looked into this and couldn't reproduce this behaviour with the queries you have in the example. Could you please provide a failing test as a PR or a reproduction so we can look into this further?

FidelElie avatar Apr 28 '25 10:04 FidelElie