power bi desktop data loading using graph API error
M query:
let
// Function to get a new access token using the refresh token
GetNewAccessToken = () =>
let
tokenUrl = "https://login.microsoftonline.com/" & tenant_id & "/oauth2/v2.0/token",
tokenBody = Text.ToBinary(
"grant_type=refresh_token" &
"&client_id=" & client_id &
"&client_secret=" & Uri.EscapeDataString(client_secrets) &
"&refresh_token=" & Uri.EscapeDataString(RefreshToken) &
"&scope=openid profile offline_access https://graph.microsoft.com/.default"
),
tokenResponse = Web.Contents(tokenUrl, [
Headers = [#"Content-Type"="application/x-www-form-urlencoded"],
Content = tokenBody
]),
tokenJson = Json.Document(tokenResponse),
new_access_token = tokenJson[access_token]
in
new_access_token,
// Check if the access token is valid (this is an assumption; replace with your logic if possible)
// For demonstration purposes, let's assume we always refresh the token for simplicity.
access_token = GetNewAccessToken(),
// Create a query string with the new access token
authQuery = "?access_token=" & access_token,
// Append the query string to the API URL
urlWithAuth = apiURL & authQuery,
// Make the API request
response = Web.Contents(urlWithAuth, [
Headers = [
#"Content-Type" = "application/json"
]
]),
// Parse the JSON response to extract the data
data = Json.Document(response)
in
data
ERROR
DataSource.Error: Web.Contents failed to get contents from 'https://graph.microsoft.com/v1.0/security/alerts?access_token="myaccesstoken" (404): Not Found
Details:
DataSourceKind=Web
0
0 comments
Sai Vignesh J
1
power bi desktop data loading using graph API error
Learn Microsoft Fabric
skool.com/microsoft-fabric
Helping passionate analysts, data engineers, data scientists (& more) to advance their careers on the Microsoft Fabric platform.
Leaderboard (30-day)
Powered by