Error when trying to obtain Access Token and Refresh Token - BING ADS API

DIEGO JOSE ACEVEDO YAMASHIRO 1 Reputation point
2021-10-16T00:57:25.64+00:00

Hello everyone:

i am trying to get my company's campaing spends and other custom reports via The Bing Ads Api. I've already registered an App in Azure and already have my developer Token. I've followed the steps mentioned in [1]: https://learn.microsoft.com/en-us/advertising/guides/authentication-oauth-get-tokens?view=bingads-13. I've exectued the powershell code from my console and once i grant consent, i recieve an URL like this:

https://login.microsoftonline.com/common/oauth2/nativeclient?code=0.ATQANGymxLcrH0WL4bLCakMBWHbeMWemFK5Jl7xuumkUOR40AOg.AQABAAIAAAD--DLA3VO7QrddgJg7WevrExYXaUN4eFYjPnhHhfoj-tfVcXu0_3-cmcm8rJumnkIcRcXKeIrb9KxGm5VuHqx9KK4yB5bYKsFjeUJe1moDb3h-nt7ixLb0cFg6Em8ZgpUMsC4iC6kKmYVM2b5uFMr8n1Wa9rcvdtBjF4E6neUFCYCbaeLXhODMdnjvPs36Pu_SSGr3nAAWKj2WVUpmP2TZmudOUMZa-66fW-Cu_yMspcgjJ7iJjqkzCImsGtXwbUnNba88K9gdyCaKsD0F06vKjTAZZFxDGEcUirk_O7oYZyzHm-FzDDnCpPAAND43stNfXSIEz7vsWDR2R_oxad12hqMBDehnBTg3Ee5MAYT-YFwBnJXSBVFhOe8RJUbnu72OYy8cfePRTIQg695O-DVCNvCVyTYM2d_05e817CFIEPRRpJCcXEIcDjdZnkxWfpHL001l2kkdMJSElJNzrsPi2YcVeX7hRMBJFa3gWIKccYXgbaKIArZCXktAI7p-QdiKmffg5wKVVgZ1GlWQ1dvaRZwPfs7RClemKmOVK2BW8xmeJMzW5N4IPezhe8l-_2iyLGOILmWONmP_zImS7xbAO2Jcwjg5A45s9qgENmH29aWKsVcp84ZrYxQviEcYNK3GPhE8rp3sTh6u2D2oR7iUBU9hulqCvYBmA-Z7Rru068cd6zal2BdQ8CR-JMzwQ_pzEEj2LcQUeX_OoLSu-fFkZg8zwbRM62Yh_3KCMo76ECAA&state=ClientStateGoesHere&session_state=0d4bd09d-efe8-4135-b399-e4df8288f682

I've read that the console returns the access token, access token duration and refresh token once i enter a code contained in the previous URL. i've tried with every part of the previous URL, but my console only returns error messages like this
"... Invoke-WebRequest : {"error":"invalid_grant","error_description":"AADSTS9002313: Invalid request. Request is malformed
or invalid.\r\nTrace ID: 77da3239-cf4a-4a39-bbbb-079cdbce9f00\r\nCorrelation ID:
5bab9c16-d200-4048-9f1b-7e0942cc4abf\r\nTimestamp: 2021-10-16
00:33:12Z","error_codes":[9002313],"timestamp":"2021-10-16 00:33:12Z","trace_id":"77da3239-cf4a-4a39-bbbb-079cdbce9f00"
,"correlation_id":"5bab9c16-d200-4048-9f1b-7e0942cc4abf","error_uri":"https://login.microsoftonline.com/error?code=9002
313"}...".
i don't really know what could i be doing wrong.

please help me.

Diego Acevedo

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

1 answer

Sort by: Most helpful
  1. Eric Urban - MSFT 626 Reputation points Microsoft Employee
    2021-10-24T14:09:34.273+00:00

    It looks like you've modified the PowerShell script to some degree. For example, client state is different. I suggest start with this script exactly as documented. Does that work? If so please try substituting with the sample client ID with your own. Does that work? And go from there.

    0 comments No comments