BingAds / BingAds-Python-SDK

Other
116 stars 162 forks source link

BULK API Python - specify only the type of ads to download? #199

Closed Greta991 closed 2 years ago

Greta991 commented 2 years ago

Hello. I'm trying to use the Bulk API in Python to download all the Ads of a Bing Ads Account. The account has many ads, and the downloaded file is too large. Is it possible to specify only the type of ads to download? I am using this code:

bulk_service_manager = BulkServiceManager( authorization_data=authorization_data, poll_interval_in_milliseconds=5000, environment=environment, )

entities = ['Ads']

submit_download_parameters = SubmitDownloadParameters( campaign_ids=None, data_scope=['EntityData'], download_entities=entities, file_type=FILE_TYPE, last_sync_time_in_utc=None )

If i also specify the Campaign in entities list and the last_sync_time_in_utc = last_14_days parameter, will it return only the Ads that have been modified in the last 14 days or also the campaigns modified in the last 14 days?

qitia commented 2 years ago

Per the doc , you can get ads by type instead of requesting all types of ads, you can include one or more of the AppInstallAds, DynamicSearchAds, ExpandedTextAds, ProductAds, ResponsiveAds, and TextAds values in the download request.

rishaab commented 2 years ago

How do we pass adtypes in GetAdsbyAdgroupId? Passing them as a list of string doesnt work.

xinyuwen2 commented 2 years ago

You can set one or more ad types with string"Text", "Image", "Product", "AppInstall", "ExpandedText", "DynamicSearch", "ResponsiveAd" and "ResponsiveSearch". If you set a invalid string, it won't work.

rishaab commented 2 years ago

@xinyuwen2 I've tried passing the adtypes as a string but still facing an error.

for ad_grp_id in ad_grp_id_list:
    ad_response = campaignmanagement_service.GetAdsByAdGroupId(
        AdGroupId=ad_grp_id,
        AdTypes="DynamicSearch"
    )

Executing the code above raises the following error:

Server raised fault: 'The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter https://bingads.microsoft.com/CampaignManagement/v13:AdTypes. The InnerException message was 'Error in line 1 position 2541. Expecting state 'Element'.. Encountered 'Text'  with name '', namespace ''.'.  Please see InnerException for more details.'
MICROSOFT_ADVERTISING_MAIN : data extraction processing Failed: (<class 'suds.WebFault'>, WebFault("Server raised fault: 'The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter https://bingads.microsoft.com/CampaignManagement/v13:AdTypes. The InnerException message was 'Error in line 1 position 2541. Expecting state 'Element'.. Encountered 'Text'  with name '', namespace ''.'.  Please see InnerException for more details.'"), <traceback object at 0x000002338F9F8F88>)
qitia commented 2 years ago

This should work. let us know otherwise.

        adTypes=campaign_service.factory.create('ArrayOfAdType')
        adTypes.AdType.append('Text')
        adTypes.AdType.append('ResponsiveSearch')

        response=campaign_service.GetAdsByAdGroupId(
            AdGroupId=ad_group_ids['long'][0],
            AdTypes=adTypes
        )