0

I'm using the BingAds Python API to access an account with several clients under it. After retrieving the accounts from CustomerService.SearchAccounts(), I pass the Account.Id field to a BulkService client:

accounts = basic.search_accounts_by_user_id(customer_service, user.Id)
    
    bulk_service = ServiceClient(
        service='BulkService',
        version=13,
        authorization_data=authorization_data,
        environment=ENVIRONMENT
    )
    
    download_entities = bulk_service.factory.create('ArrayOfDownloadEntity')
    download_entities.DownloadEntity = ['Campaigns','AdGroups']
    

    for account in accounts['AdvertiserAccount']:
        #print(account)
        response = bulk_service.DownloadCampaignsByAccountIds(
            AccountIds={'long':[account.Id]},
            DataScope=['EntityData'],
            #DownloadFileType=FILE_TYPE,
            DownloadEntities=download_entities,
            FormatVersion="6.0"
        )

This throws the following error:

Traceback (most recent call last):
  File "main.py", line 144, in <module>
    main(authorization_data)
  File "main.py", line 73, in main
    FormatVersion="6.0"
  File "C:\Users\Bob\Anaconda3\envs\waterbear\lib\site-packages\bingads\service_client.py", line 273, in __call__
    raise ex
  File "C:\Users\Bob\Anaconda3\envs\waterbear\lib\site-packages\bingads\service_client.py", line 265, in __call__
    response = self.service_client.soap_client.service.__getattr__(self.name)(*args, **kwargs)
  File "C:\Users\Bob\Anaconda3\envs\waterbear\lib\site-packages\suds\client.py", line 521, in __call__
    return client.invoke(args, kwargs)
  File "C:\Users\Bob\Anaconda3\envs\waterbear\lib\site-packages\suds\client.py", line 581, in invoke
    result = self.send(soapenv)
  File "C:\Users\Bob\Anaconda3\envs\waterbear\lib\site-packages\suds\client.py", line 619, in send
    description=tostr(e), original_soapenv=original_soapenv)
  File "C:\Users\Bob\Anaconda3\envs\waterbear\lib\site-packages\suds\client.py", line 670, in process_reply
    raise WebFault(fault, replyroot)
suds.WebFault: Server raised fault: 'Invalid client data. Check the SOAP fault details for more information. TrackingId: xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxx.'

Is this the wrong ID to pass to the BulkService?

OR: I can use the BulkServiceManager on the whole account, but it appears to return 5-10 rows for a random client each time; not the full data, and I can't find a way to pass it a client ID so I could iterate. If anyone has a simpler solution using BulkServiceManager, I'm open to that, too.

EDIT: Actual SOAP response during failure:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
    <s:Body>
        <s:Fault>
            <faultcode>s:Server</faultcode>
            <faultstring xml:lang="en-US">Invalid client data. Check the SOAP fault details for more information. TrackingId: 5e8cbcb6-2d29-49e9-83e3-b91d94c712b7.</faultstring>
            <detail>
                <AdApiFaultDetail xmlns="https://adapi.microsoft.com" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
                    <TrackingId>xxxxxxxxxxx</TrackingId>
                    <Errors>
                        <AdApiError>
                            <Code>105</Code>
                            <Detail i:nil="true" />
                            <ErrorCode>InvalidCredentials</ErrorCode>
                            <Message>Authentication failed. Either supplied credentials are invalid or the account is inactive</Message>
                        </AdApiError>
                    </Errors>
                </AdApiFaultDetail>
            </detail>
        </s:Fault>
    </s:Body>
</s:Envelope>
BobRz
  • 470
  • 5
  • 11

1 Answers1

1

To get details about the error I suggest logging: https://github.com/BingAds/BingAds-Python-SDK/blob/master/examples/v13/auth_helper.py#L32

Did you set the required customer and account IDs via authorization_data? Here is an example using BulkServiceManager: https://github.com/BingAds/BingAds-Python-SDK/blob/master/examples/v13/bulk_service_manager_demo.py#L11

The account ID is set here in auth_helper.py: https://github.com/BingAds/BingAds-Python-SDK/blob/master/examples/v13/auth_helper.py#L54

To download multiple accounts, update authorization_data for BulkServiceManager and download the next account.

I hope this helps!

Eric Urban
  • 582
  • 2
  • 7
  • The logging is helpful, and this is the first time I've seen setting account and parent IDs on the authorization_data -- thanks for both. Not sure what you mean with the BulkServiceManagerExample though; the portion that sets up authorization_data and sets both those fields to None? Anyway, same result. Edited original with the full SOAP fault. – BobRz Jul 01 '20 at 02:58
  • Initially the example sets authentication to None, but then authenticate(authorization_data) is called. If the user credentials are valid, the 105 error is likely due to mismatched environment (Sandbox vs Production). https://learn.microsoft.com/en-us/advertising/guides/handle-service-errors-exceptions?view=bingads-13#code-105 – Eric Urban Jul 01 '20 at 18:01