BingAds API Python SDK - How to update existing Audience Customer Match List

Ron D 0 Reputation points
2025-01-22T17:10:13.5233333+00:00

Hi

Im trying to use the python SDK for BingAds to update an existing Audience with new hashed emails. I have managed to authenticate and read the Audience using its ID. However when i try to update the Audience using a list of hashed emails it errors with

TypeNotFound: Type not found: 'CustomerList'

Below is my function to update the Audience members:

def sync_bing_audience(hashed_emails, audience_id):
     # get auth
    authorization_data = bing_ads_auth()
    # Initialize the CampaignManagementService
    campaign_service = ServiceClient(
        service='CampaignManagementService',
        version=13,
        authorization_data=authorization_data
    )
    
    # Create a CustomerList object
    customer_list = campaign_service.factory.create("CustomerList")
    customer_list.Id = audience_id
    customer_list.Members = {"Emails": hashed_emails}
    
    # Create an Audience object for updating
    audience_update = campaign_service.factory.create("Audience")
    audience_update.Id = audience_id
    audience_update.Type = "CustomerList"
    audience_update.CustomerList = customer_list
    
    # Call UpdateAudiences with the correct object types
    try:
        response = campaign_service.UpdateAudiences(
            Audiences={"Audience": [audience_update]}
        )
        print(f"Audience {audience_id} updated successfully.")
        return response
    except Exception as e:
        print(f"An error occurred: {e}")
        raise

audience_id = 821708509
response = sync_bing_audience(hashed_emails, audience_id)

I tried looking for examples on github but there are none. Could someone kindly help me correct my code or provide example code of how to do it please. Many Thanks in advance

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

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.