How do I properly set AdType when calling GetAdsByAdGroupId?

Vonk, Wessel 0 Reputation points
2024-04-05T11:45:57.1466667+00:00

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!

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.
386 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Vonk, Wessel 0 Reputation points
    2024-04-08T19:28:20.57+00:00

    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!

    0 comments No comments