Bing Ads API - Can not authenticate - Authentication challenge in Python SDK

1.6k Views Asked by At

I am facing the challenge to request the Bing Ads API to get a couple of metrics from it. I am using Apache Airflow DAGs hosted on a remote Kubernetes cluster to do so. It is a nice way to automate and schedule tasks.

Now, the documentation is rather light on the point of gaining access to the API.

I have followed this https://learn.microsoft.com/en-us/advertising/guides/authentication-oauth-identity-platform?view=bingads-13#registerapplication and the official SDK docs https://github.com/BingAds/BingAds-Python-SDK/.

I am failing at authenticating when querying, since I am lacking a couple of pieces of information.

When authenticating using the "refresh token" and "redirect URI", I do not have either. (Class OAuthWebAuthCodeGrant here: https://github.com/BingAds/BingAds-Python-SDK/blob/294d01eea57d80ba381a42cde8d006fc318af056/bingads/authorization.py#L566)

When using a different method (Class OAuthDesktopMobileAuthCodeGrant here: https://github.com/BingAds/BingAds-Python-SDK/blob/294d01eea57d80ba381a42cde8d006fc318af056/bingads/authorization.py#L532), I fail w/

AADSTS700016: Application with identifier '<someidentifier>' was not found in the directory '<somethingelse>'. This can happen if the application has not been installed by the administrator of the tenant or consented to by any user in the tenant. You may have sent your authentication request to the wrong tenant.

Thank you very much in advance! If you need more details, let me know!

Also great documentation in general, if I can make it more "newb"-friendly, let me know!

Edit1:
Sadly, while there has been some traffic to this question, nobody seems to be able to answer.
I will specify the set up a bit further.

We use Airflow DAGs to request daily updates from the API. For this, we need to authenticate. The authentication comes from a "new device" every time, since the code runs on a k8s cluster which allocates the jobs dynamically to it's pods.
For authentication, we ventured into different solutions, but all require some form of human interaction to get the refresh token into the DAG.

Is there any solution which allows for a hands-free deamon like many-server-to-server communication?
This link sheds some light on what we are looking for: https://learn.microsoft.com/en-us/azure/active-directory/develop/scenario-daemon-app-registration#api-permissions---app-permissions-and-admin-consent Sadly, the Bing Ads API does not show up there.

What key piece of information are we missing?

1

There are 1 best solutions below

0
On

Bing Ads, like Google Ads, uses OAuth for its API.

If you reference the Getting Started page, it mentions that you need a developer token, complete with links.

You can follow these steps to get a developer token for production.

  1. Sign in with Super Admin credentials at the Microsoft Advertising Developer Portal account tab.

  2. Choose the user that you want associated with the developer token. Typically an application only needs one universal token regardless how many users will be supported.

  3. Click on the Request Token button.

Regarding your specific scenario--an application running in the cloud without an interface--you should know that OAuth requires you to interact with it to set things up. So run your app locally ONCE, or at least the getting_started code from your language's walkthrough: https://learn.microsoft.com/en-us/advertising/guides/walkthrough-desktop-application-python?view=bingads-13

Running it locally will go through the authentication process with your browser and generate a refresh token (in the file refresh.txt by default). Store this file with your code. It will have to be on the server that's making the request, and since it's in Kubernetes, you'll have to keep it with your container file.