Can CampaignPerformanceReportRequest return for all campaigns?

484 views Asked by At

Trying to use the Bing Ads API to duplicate what I see on the Hourly report.

enter image description here

Unfortunately, even though I'm properly authenticated, the data I'm getting back is only for One Campaign (one which has like 1 impression per day). I can see the data in the UI just fine, but authenticated as the same user via the API, I can only seem to get back the smaller data set. I'm using https://github.com/BingAds/BingAds-Python-SDK and basing my code on the example:

def get_hourly_report(
        account_id,
        report_file_format,
        return_only_complete_data,
        time):
    report_request = reporting_service.factory.create('CampaignPerformanceReportRequest')
    report_request.Aggregation = 'Hourly'
    report_request.Format = report_file_format
    report_request.ReturnOnlyCompleteData = return_only_complete_data
    report_request.Time = time
    report_request.ReportName = "Hourly Bing Report"
    scope = reporting_service.factory.create('AccountThroughCampaignReportScope')
    scope.AccountIds = {'long': [account_id]}
    # scope.Campaigns = reporting_service.factory.create('ArrayOfCampaignReportScope');
    # scope.Campaigns.CampaignReportScope.append();
    report_request.Scope = scope

    report_columns = reporting_service.factory.create('ArrayOfCampaignPerformanceReportColumn')
    report_columns.CampaignPerformanceReportColumn.append([
        'TimePeriod',
        'CampaignId',
        'CampaignName',
        'DeviceType',
        'Network',
        'Impressions',
        'Clicks',
        'Spend'
    ])
    report_request.Columns = report_columns

    return report_request

I'm not super familiar with these ad data APIs, so any insight will be helpful, even if you don't have a solution.

1

There are 1 answers

0
deltree On BEST ANSWER

I spent weeks back and forth with Microsoft Support. Here's the result:

  1. You can get logs out of the examples by adding this code:
import logging

logging.basicConfig(level=logging.INFO)
logging.getLogger('suds.client').setLevel(logging.DEBUG)
logging.getLogger('suds.transport').setLevel(logging.DEBUG)
  1. The issue was related to the way the example is built. In the auth_helper.py file there is a method named authenticate that looks like this:
def authenticate(authorization_data):
    # import logging
    # logging.basicConfig(level=logging.INFO)
    # logging.getLogger('suds.client').setLevel(logging.DEBUG)
    # logging.getLogger('suds.transport.http').setLevel(logging.DEBUG)

    customer_service = ServiceClient(
        service='CustomerManagementService',
        version=13,
        authorization_data=authorization_data,
        environment=ENVIRONMENT,
    )

    # You should authenticate for Bing Ads services with a Microsoft Account.
    authenticate_with_oauth(authorization_data)

    # Set to an empty user identifier to get the current authenticated Bing Ads user,
    # and then search for all accounts the user can access.
    user = get_user_response = customer_service.GetUser(
        UserId=None
    ).User
    accounts = search_accounts_by_user_id(customer_service, user.Id)

    # For this example we'll use the first account.
    authorization_data.account_id = accounts['AdvertiserAccount'][0].Id
    authorization_data.customer_id = accounts['AdvertiserAccount'][0].ParentCustomerId

As you can see, at the very bottom, it says "For this example, we'll use the first account." It turns out that my company had 2 accounts. This was not configurable anywhere and I had no idea this code was here, but you can add a breakpoint here to see your full list of accounts. We only had 2, so I flipped the 0 to a 1 and everything started working.