Bing Ads API Python Error Code 123 WorkIdentityNotAvailable

Julia Ikaue 1 Reputation point
2022-07-15T14:02:31.553+00:00

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)

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.
387 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Bryce Balbon 1 Reputation point
    2022-11-03T22:42:46.597+00:00

    Also had this issue. You need to authenticate to your app, from oauth_web_auth_code_grant.get_authorization_endpoint(), with your personal email account that is the base for your work account. I.E select the non-work ("Created by your Work or IT department") account (assuming they have the same email alias) and then copy paste the URI from that consent link into self.oauth_web_auth_code_grant.request_oauth_tokens_by_response_uri(RESPONSE_URI) which will give you your oauth_web_auth_code_grant.oauth_tokens.refresh_token. This will be a personal refresh token ending in '$$' -- you MUST REMOVE THIS '$$' from the end of the refresh token for it to work. Then you authenticate with the code you have.

    Took me a long time to figure out, wish the documentation was more clear on this.

    0 comments No comments