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.
418 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hi! I'm currently trying to call GetAdsByAdGroupId
as follows:
[...]
def get_ads_by_ad_group_id(customer_id: str, account_id: str, ad_group_id: str) -> Any:
"""See https://learn.microsoft.com/en-us/advertising/campaign-management-service/getadsbyadgroupid?view=bingads-13"""
client = ServiceClient(
service="CampaignManagementService",
version=13,
authorization_data=AuthorizationDataHelper(customer_id=customer_id, account_id=account_id)
)
return client.GetAdsByAdGroupId(
AdGroupId=ad_group_id,
AdTypes=["Text"],
ReturnAdditionalFields=[]
)
ads = get_ads_by_ad_group_id(CUSTOMER_ID, CUSTOMER_ACCOUNT_ID, 789)
[...]
However, I bump into this exception:
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 2800. Expecting state 'Element'.. Encountered 'Text' with name '', namespace ''.'. Please see InnerException for more details.'
Given
I expect an AdType array
to be provided as, e.g., ["Text"]
. However, this is not the case.
How do I properly set an AdType array
in this particular call?
Thanks!
You should set AdTypes
as follows:
[..]
client = ServiceClient(
service="CampaignManagementService",
version=13,
authorization_data=AuthorizationDataHelper(customer_id=customer_id, account_id=account_id)
)
ad_types = client.factory.create("ArrayOfAdType")
ad_types.AdType = [
"Text",
"Image",
"Product",
"AppInstall",
"ExpandedText",
"DynamicSearch",
"ResponsiveAd",
"ResponsiveSearch",
"Hotel"
]
return client.GetAdsByAdGroupId(
AdGroupId=ad_group_id,
AdTypes=ad_types,
ReturnAdditionalFields=[]
)
That should do the trick!