BingAds / BingAds-Python-SDK

Other
116 stars 162 forks source link

Impression Share Percentage and Click Share Percentage not pulling #113

Closed kavisek closed 5 years ago

kavisek commented 5 years ago

Hi Team,

I was able to pull the majority of the metrics under your CampaignPerformanceReportColumn documentation using the example CampaignPerformanceReports code within the Python SDK Examples Folder.

But I was not able to pull the "ImpressionSharePercent" or "ClickSharePercent". When attempting to pull these metrics via the CampaignPerformanceReport or AdGroupPerformanceReport I receive a "Server raised fault: 'Invalid client data. Check the SOAP fault details for more information' " error.

impression_share_example_in_python.txt

kavisek commented 5 years ago

Insert the following code in the top of your script to get more detailed log of how your Python script is interacting with the SDK.

import logging
logging.basicConfig(level=logging.INFO)
logging.getLogger('suds.client').setLevel(logging.DEBUG)

I found some python cold online that made the SOAP request errors more explicit. I was able to resolve my issue my making sure that "Impressions" where included in the same request as a required performance metrics and removing the columns that conflicted with the ImpressionSharePercent attribute after reading over the documentation

Link: https://docs.microsoft.com/en-us/bingads/guides/reports?view=bingads-12#columnrestrictions

The final working report code can be found below.

# Campaign Performance Report Request
def get_campaign_performance_report_request(
        account_id,
        aggregation,
        exclude_column_headers,
        exclude_report_footer,
        exclude_report_header,
        report_file_format,
        return_only_complete_data,
        time):

    report_request=reporting_service.factory.create('CampaignPerformanceReportRequest')
    report_request.Language='English'
    report_request.Aggregation=aggregation
    report_request.ExcludeColumnHeaders=exclude_column_headers
    report_request.ExcludeReportFooter=exclude_report_footer
    report_request.ExcludeReportHeader=exclude_report_header
    report_request.Format=report_file_format
    report_request.ReturnOnlyCompleteData=return_only_complete_data
    report_request.Time=time    
    report_request.ReportName="My Campaign Performance Report"
    scope=reporting_service.factory.create('AccountThroughCampaignReportScope')
    scope.AccountIds={'long': [account_id] }
    scope.Campaigns=None
    report_request.Scope=scope     

    report_columns=reporting_service.factory.create('ArrayOfCampaignPerformanceReportColumn')
    report_columns.CampaignPerformanceReportColumn.append([
        'TimePeriod',
        'CampaignId',
        'Impressions',
        'ImpressionSharePercent'
    ])
    report_request.Columns=report_columns

    return report_request

Thank you for your time.