How to get data from Microsoft Bing Ads API

3.5k views Asked by At

I'm trying to get Bing ads spends from my firm. According to the Microsoft documentation, I understood that it's mandatory to use Microsoft Azure portal, get developer_token, client_id, tenant_id, client_secret, and access/refresh token to download the csv files with the data I want.

So, this is what I did:

  1. I've received an invitation from my firm to Microsoft advertising onto this email adress: [email protected], and I've generated my developer token.

  2. With this email address, I've created a web application onto Microsoft Azure portal, which allow all king of users. Getting client_id, tenant_id, and generated a client_secret.

  3. The redirect URL that I have chosen is http://localhost (according to the documentation but not sure this is the good URL to choose).

  4. With Postman, I have tried with this endpoint: https://login.microsoftonline.com/common/oauth2/v2.0/authorize and the params (previously obtained) needed for the OAuth 2.0 authentication to get my access token. Without success.

The issue is here.

When I request the access token, a new browser window opens, and asks for an email address on which to authenticate. I'm using my email address [email protected] and I received authentication completed onto Postman but into the response body I have access_token: invalid.

The role of my account is super admin.

So I'm trying to authenticate with a professional Microsoft Azure Account and this time I received into the browser Invalid redirect url.

I have also tried to start all over again with different email address, like my personal email address, or with the email address of the creator of the Microsoft Advertising account, and I get the error contact your system Admin into the browser.

I have also tried with the Python SDK project given in the documentation, with the error message.

I must have forgotten or misunderstood something.

Should we use the same email address (or same account) on Microsoft Advertising, on Microsoft Azure, and when obtaining the access token?

Do you have to pay and take an Azure subscription? (Already done but without success)

Thanks in advance, sorry for my English.

EDIT:

Thank for ypur reply. The full request is: https://login.microsoftonline.com/common/oauth2/v2.0/authorize with the following params:

-type: OAuth 2.0

-Header Prefix: Bearer

-Grant Type: Authorization Code

-Callback URL: https://localhost

-Auth URL: https://login.microsoftonline.com/{my-tenant_id}/oauth2/v2.0/authorize

-Access Token URL: https://login.microsoftonline.com/{my-tenant_id}/oauth2/v2.0/token

-my client id

-my client secret

-scope: https://ads.microsoft.com/ads.manage OR also testing with https://graph.microsoft.com/User.Read

-State: None

-Client authentication: send client credentials in body

Give me an access_token but when I click on use token and send the request, I'm not getting an refresh token

1

There are 1 answers

1
Allen Wu On

Once a user provides consent, you can get an access token and act on behalf of the user.

So when the browser session starts, you should enter your Microsoft Advertising credentials.

Remember to set scope=https://ads.microsoft.com/ads.manage in the request for acquiring the authorization code.

If you prefer to automate this process, you can refer to this script and steps to obtain an access token.