Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Learn from the best! Meet the four finalists headed to the FINALS of the Power BI Dataviz World Championships! Register now

Reply
megel
Regular Visitor

Setup Web Credentials for Application Insights by API

Hi All,

I want to setup the Web Credentials for my Dataset by API from a service:

megel_0-1659792360013.png

The Datasource is an Application Insights component. To do this manual, I have to use my organizational account.

But I want to do this automatically and for this I want to uses this API:

PATCH https://api.powerbi.com/v1.0/myorg/gateways/{gatewayId}/datasources/{datasourceId}

Authorization: Bearer {token}
Content-Type: application/json

{
  "credentialDetails": {
    "credentialType": "OAuth2",
    "credentials": "{\"credentialData\":[{\"name\":\"accessToken\", \"value\":\"{access_token}\"}]}",
    "encryptedConnection": "Encrypted",
    "encryptionAlgorithm": "None",
    "privacyLevel": "Organizational"
  }
}

Here are my questions:
1) How do I get the correct access_token for my account?
2) Is it possible to use a Service Account?
3) Which Permissions do I need for an Azure AD AppRegistration, to get the access_token within a client credential flow?
4) Which Scope / Resource do I need client credential flow?

1 REPLY 1
Anonymous
Not applicable

HI @megel,

You can try to use the following M query code if help with your scenario:

let
    secretId = xxxxx,
    authKey = "Basic " & secretId,
    url = "https://api.xxxxx.com/oauth2/token",
    GetJson =
        Web.Contents(
            url,
            [
                Headers = [
                    #"Authorization" = authKey,
                    #"Content-Type" = "application/x-www-form-urlencoded;charset=UTF-8"
                ],
                Content = Text.ToBinary("grant_type=client_credentials")
            ]
        ),
    token = Json.Document(GetJson)[access_token],
    Result =
        Web.Contents(
            "https://xxxxx.xxx.com",
            [
                Headers = [
                    #"Content-Type" = "application/json",
                    Authorization = "Bearer " + token
                ],
                    RelativePath = "/xxxxx/xxxxx"
            ]
        )
in
    Result

Regards,

Xiaoxin Sheng

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

February Power BI Update Carousel

Power BI Monthly Update - February 2026

Check out the February 2026 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.