I'm new to the Bing Ads API and I'm trying to connect to it with Python:
oauth_web_auth_code_grant = OAuthWebAuthCodeGrant(
client_id=MY_CLIENT_ID,
client_secret = MY_CLIENT_SECRET,
redirection_uri=None,
)
oauth_tokens = oauth_web_auth_code_grant.request_oauth_tokens_by_refresh_token(
MY_REFRESH_TOKEN
)
authorization_data = AuthorizationData(
account_id= MY_ACCOUNT_ID,
customer_id= MY_CUSTOMER_ID,
developer_token= MY_DEVELOPER_TOKEN,
authentication=OAuthAuthorization(
client_id=oauth_web_auth_code_grant.client_id,
oauth_tokens=oauth_tokens,
),
)
I can connect to any service. For example:
customer_service = ServiceClient(
service = 'CustomerManagementService',
version = 13,
authorization_data=authorization_data,
environment='production'
)
print (customer_service.soap_client)
However, I get suds.WebFault: Server raised fault: 'Invalid client data. Check the SOAP fault details for more information when trying to fetch some data from any service. For example:
get_user_response = customer_service.GetUser(UserId=None)
user = get_user_response.User
Then I debugged by means of:
import logging
logging.basicConfig(level=logging.INFO)
logging.getLogger('suds.client').setLevel(logging.DEBUG)
and get Error Code 123 WorkIdentityNotAvailable Yo must use a personal Microsoft account to login to Bing Ads (https://learn.microsoft.com/en-us/advertising/guides/operation-error-codes?view=bingads-13)
The Microsoft account that built the app and manages Bing Ads is the same. The app, the refresh token and the developer token were generated according to the API documentation. (https://learn.microsoft.com/en-us/advertising/guides/?view=bingads-13)