none
Bing Content api Access token using Microsoft Identity Platform RRS feed

  • Question

  • I need to send product feed to our merchant account catalog.

    I am following guide from https://docs.microsoft.com/en-us/advertising/shopping-content/get-started to send Product Feed.
    I have server side application that runs in background without any human involvement.

    I have followed the instruction from below link and registered new app on Azure AD
    https://docs.microsoft.com/en-us/advertising/guides/authentication-oauth-identity-platform?view=bingads-13

    In App permissions I searched for Bings Ads or Content Api to add permissions but could not find the required Permission.

    I have followed the code sample for deamon app to get access. I have got the Access token with scopes(https://graph.microsoft.com/.default and api://tenant-id/.default) but when I used this Access Token to post Product Feed using the endpoint https://content.api.bingads.microsoft.com/shopping/v9.1/bmc/{merchant-Id}/products/batch?bmc-catalog-id={CatalogId}&alt=json I get response "401 Unathorised"

    I have following questions

    • Is it possible to get Access Token without prompting user consent as my application is only server side and no human involvement?
    • Could you please help me understand this Access Token Access for Bing Ad Api using Microsoft Identity Platform?
    • How I can add scope for Content Ads Api in Azure App?

    Any sample code for .NET or integration documentation will be helpful to understand how Microsoft Identity Platform works with Content api.

    Thank You

    Wednesday, April 22, 2020 12:59 PM

All replies

  • If you registered an app exactly as described here, then you should only need to use the https://ads.microsoft.com/ads.manage and offline_access scopes when requesting the access token (and you don't need to add them in the  portal). I suggest please try the PowerShell Quick Start here, since a Client Id is already provided. Then try replacing it with your Client Id.

    We will also look into updating this sample (or you can modify it), otherwise the concept is the same as Bing Ads API documentation with respect to the Microsoft Identity endpoint. 

     

    Also note, per FAQ:

    To programmatically manage a Microsoft Advertising account, you must provide consent at least once through the web application consent flow. For repeat or long term authentication, you should follow the authorization code grant flow for obtaining an access token and refresh token. Thereafter you can use the latest refresh token to request new access and refresh tokens without any further user interaction.


    Please let me know if you have any follow up questions.

    Best,

    Eric

    Wednesday, April 22, 2020 8:35 PM
    Owner
  • Thank You Eric for update

    Instead of using authorization code grant flow Can I use Microsoft Identity Client nuget package for Authentication of Content Api and get valid access token?

    I have tried to add https://ads.microsoft.com/ads.manage and offline_access scopes but I get Invalid Scope exception. My code is below.

     var authority = "https://login.microsoftonline.com/{tenant}"; 
    var scopeUrl = "https://ads.microsoft.com/ads.manage%20offline_access";
    string[] scopes = new string[] { scopeUrl };
    IConfidentialClientApplication app = ConfidentialClientApplicationBuilder.Create(clientId)
                        .WithClientSecret(clientSecret)
                        .WithAuthority(new Uri(authority))
                        .Build();
    try
    {
        var result = await app.AcquireTokenForClient(scopes)
                         .ExecuteAsync();
        if (result != null)
        {
            UpdateAccessTokenAndExpiry(result);
        }
    }
    catch (Exception exc)
    {
        _logger.LogError("Bing feed Auth exception", exc);
    }

    Thursday, April 23, 2020 10:15 AM
  • Last I checked there were some challenges / obstacles to using Microsoft Identity Client nuget package for Bing Ads API and Content API. I recommend installing Microsoft.BingAds.SDK, which has custom classes to handle the required scopes automatically. Some internal details are here, and example usage is here

    Please let me know if you have any follow up questions. 

    Thanks,

    Eric

    Thursday, April 23, 2020 2:51 PM
    Owner