Forum Discussion

Wiatt's avatar
Wiatt
Regular Visitor
2 years ago

Powerbi and intune api connect

I am an Intune administrator and I want to create a dashboard with Powerbi, for this we have registered an app, I have managed to consult some data but I am not able to consult the remediations.

After several tests I have come to build this query:

let
// Define the necessary variables
tenantId="xxxxxxxxxxxx",
clientId = "xxxxxxxxxxxxxxxx",
clientSecret = "xxxxxxxxxxxx",
tokenUrl = "https://login.microsoftonline.com/" & tenantId & "/oauth2/v2.0/token",
tokenBody = "grant_type=client_credentials&client_id=" & clientId & "&client_secret=" & clientSecret & "&scope=https://graph.microsoft.com/.default",

// Get the access token
TokenResponse = Json.Document(Web.Contents(tokenUrl, [Content = Text.ToBinary(tokenBody), Headers = [#"Content-Type"="application/x-www-form-urlencoded"]])),
accessToken = TokenResponse[access_token],

// Define the Microsoft Graph endpoint to get the remediation scripts using the beta version
graphUrl = "https://graph.microsoft.com/beta/deviceManagement/deviceManagementScripts",

// Create a function to use the token in the request
GetWithToken = (url as text, token as text) as record =>
let
response = Web.Contents(url, [Headers=[Authorization="Bearer " & token]])
in
Json.Document(response),

// Call the function with the URL and token
Source = GetWithToken(graphUrl, accessToken),

// Convert the JSON to a table
value = Source[value],
ScriptsTable = Table.FromList(value, Splitter.SplitByNothing(), null, null, ExtraValues.Error),

// Expand table records to inspect all fields
ExpandedScriptsTable = Table.ExpandRecordColumn(ScriptsTable, "Column1", {"id", "displayName", "description"}, {"ID", "Display Name", "Description"})
in
ExpandedScriptsTable

but it gives me this error and I am not able to solve it

Expression.Error: The 'Authorization' header is only supported when connecting anonymously. These headers can be used with all authentication types: Accept, Accept-Charset, Accept-Encoding, Accept-Language, Cache-Control, Content-Type, If-Modified-Since, Prefer, Range, Referer

2 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Wiatt ,
    Based on your description, when attempting to connect to the Microsoft Graphics API to obtain data from a Power BI dashboard, you receive an error message indicating that there are limitations in the way Power Query handles certain types of headers, especially when using authentication methods other than anonymous. You can try using functions with options to bypass the limitations of the "Authorization" header. You can add ManualStatusHandling = {400, 401, 403, 404, 500} to make Power Query manually handle HTTP status codes to allow the use of "authorization" headers even if the connection is not anonymous.

    // Get the access token
        TokenResponse = Json.Document(Web.Contents(tokenUrl, [
            Content = Text.ToBinary(tokenBody), 
            Headers = [#"Content-Type"="application/x-www-form-urlencoded"],
            ManualStatusHandling = {400, 401, 403, 404, 500}
        ])),
        accessToken = TokenResponse[access_token],
     // Create a function to use the token in the request
        GetWithToken = (url as text, token as text) as record =>
        let
            response = Web.Contents(url, [
                Headers=[Authorization="Bearer " & token],
                ManualStatusHandling = {400, 401, 403, 404, 500}
            ])
        in
            Json.Document(response),

    You can also check out the following documentation for more guidance on using the api
    Microsoft Graph overview - Microsoft Graph | Microsoft Learn

    Best regards,
    Albert He

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi Wiatt ,

      Did the above answer solve your problem and if so, you can mark it as an answer so it's easier for other users to find.

      Best regards,
      Albert He


      If this post helps, then please consider Accept it as the solution to help the other members find it more quickly