C# AdWords Reporting API returning wrong data

328 views
Skip to first unread message

Chris Oh

unread,
Apr 26, 2016, 12:48:21 PM4/26/16
to AdWords API Forum
Hello, I am trying to pull in report data with the C# AdWords API in order to process it for internal use. I am using AWQL to achieve this purpose. For some reason, the cost data I am getting back from the API is incorrect, which I think is messing up other fields I need such as CPC and CPM. Following is query and the method I am using the pull in the data...


String query = "SELECT AccountDescriptiveName, CampaignName, AdGroupName, ExternalCustomerId, AdGroupStatus, " +
                "Clicks, Impressions, Ctr, AverageCpc, AverageCpm, Cost, AveragePosition FROM ADGROUP_PERFORMANCE_REPORT " +
                "WHERE Impressions > 0 DURING YESTERDAY";


Here, I am passing in the client that I want to pull the report from, the DataTable I am trying to store my results in, and the query string defined above as my parameters in the AppendToDataTable method. 


private static void AppendToDataTable(AdWordsUser user, DataTable data, String query)
        {
            ReportUtilities reportUtilities = new ReportUtilities(user, "v201601", query,
                DownloadFormat.GZIPPED_XML.ToString());


            try
            {
                using (ReportResponse response = reportUtilities.GetResponse())
                {
                    using (GZipStream gzipStream = new GZipStream(response.Stream,
                        CompressionMode.Decompress))
                    {
                        using (XmlTextReader reader = new XmlTextReader(gzipStream))
                        {
                            while (reader.Read())
                            {
                                switch (reader.NodeType)
                                {
                                    case XmlNodeType.Element: // The node is an Element.
                                        if (reader.Name == "row")
                                        {
                                            // put the row into data table
                                            DataRow row = data.NewRow();
                                            while (reader.MoveToNextAttribute())
                                            {
                                                //Console.Write(reader.Name + ":" + reader.Value + ", ");
                                                row[reader.Name] = reader.Value;
                                            }
                                            data.Rows.Add(row);
                                        }
                                        break;
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                throw new System.ApplicationException("Failed to download report.", e);
            }

        }

 For some reason, the data I pull tells me that my cost is in the hundreds of thousands just for yesterday, which can't be true, because on the AdWords Console, the total cost all time is only in the thousands for that client... The clicks and impression data looks correct though, it's just the cost and cost related fields that are messed up for some reason. I am using client library v201601 to do this. Any ideas to troubleshoot this problem would be appreciated, thank you.

Chris Oh

unread,
Apr 26, 2016, 3:30:23 PM4/26/16
to AdWords API Forum
So I found out that the Cost, CPC, and CPM are for some reason just being multiplied by a million for some reason... As a temp solution, I just decided to simply convert the fields into decimal (they were originally strings) and and divide them by 1 million, and the numbers seem to check out now... I'm wondering if the numbers are coming out that way because it's missing the decimal point for whatever reason? I would still like figure out if there is a way for me to get the data in the most pure way possible.. Or at least know for sure if it is safe to just simply divide the numbers by 1 million... I'm still fairly new to C#, so I'm a bit lost on how I should go about doing this... Any help would be appreciated.

Shwetha Vastrad (AdWords API Team)

unread,
Apr 26, 2016, 3:45:18 PM4/26/16
to AdWords API Forum
Hi Chris,

You are right. The Cost, CPC, CPM and other currency related fields are of the type Money, which is represented in micros; one million is equal to one unit. There isn't any error in the report. 

I hope this helps.

Regards,
Shwetha, AdWords API Team.

Jonathan Mallia

unread,
Apr 12, 2018, 6:09:11 AM4/12/18
to AdWords API Forum
Hello Chris,

Do you mind posting the code where you defined the data table? I am having trouble inserting data in the data table particularly in this step:
row[reader.Name] = reader.Value;

Would be great if you can help me.

Thanks.

Milind Sankeshware (AdWords API Team)

unread,
Apr 12, 2018, 2:56:08 PM4/12/18
to AdWords API Forum
Hi Jonathan,

Could you please share the client customer id for which you ran the report? Also please share the error which you are facing. You could use Reply privately to author option when responding.

Thanks,
Milind, AdWords API Team.
Reply all
Reply to author
Forward
0 new messages