Bing Ads API report request (Python)

Stalse 1 Reputation point
2022-08-17T15:40:13.757+00:00

Hello everyone,

I am facing some problems in the data extraction process using the Bing API with Python. I followed the Overview, but I still don't understand exactly how to request and extract the report for the following metrics:

Metrics:

Investment (Cost)
Impressions
Clicks
Conversions

Can anyone suggest me some solution or path to follow ?

Microsoft Advertising API
Microsoft Advertising API
A Microsoft API that provides programmatic access to Microsoft Advertising to manage large campaigns or to integrate your marketing with other in-house systems.
388 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Thiel Philipp 1 Reputation point
    2022-12-20T15:42:17.087+00:00

    I was faced with the same question and here is what finally fixed it for me:

    (Note that I assume that you have a working authentication and that you know what I mean when I refer to certain authentication constructs. If your problem lies there consult the official documentation)

    The API you want to use is the reporting api so you have to

    import bingads
    from bingads.v13 import reporting
    rep_man = reporting.ReportingServiceManager(authorization_data=authorization_data, working_directory="tmp")

    I don't know if the working_directory parameter is strictly necessary, I set it just to be safe

    Now you need to construct your report request you can do this like this:

    rep_serv = bingads.ServiceClient(service = 'ReportingService',
    version=13,
    authorization_data=authorization_data)

    rep_req = rep_serv.factory.create("CampaignPerformanceReportRequest")
    rep_req.Aggregation = 'Daily'
    time = rep_serv.factory.create('ReportTime')
    time.PredefinedTime='ThisMonth'
    time.CustomDateRangeStart = None
    time.CustomDateRangeEnd = None
    rep_req.Time = time
    rep_req.Filter=None
    scope = rep_serv.factory.create('AccountThroughCampaignReportScope')
    scope.AccountIds = {'long': [account_id]}
    scope.Campaigns = None
    rep_req.Scope=scope
    rep_col = rep_serv.factory.create('ArrayOfCampaignPerformanceReportColumn')
    rep_col.CampaignPerformanceReportColumn.append(['TimePeriod', 'CampaignName', 'Clicks', 'Conversions', 'Impressions', 'Spend'])
    rep_req.Columns = rep_col
    rep_req.Format = "Csv"
    rep_param = reporting.ReportingDownloadParameters(report_request = rep_req, result_file_directory = None, result_file_name = 'report.csv')
    rep_man.download_report(rep_param)

    with this very ugly function I finally got a result. I hope this is not too late to be useful

    0 comments No comments