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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

can we refresh access token while using Graph API in power query

Access token got expired after 60 minutes, need to refresh it to fetch the information from GRAPH API.

Below is the power query code  using :

 

let
token_uri = "https://login.windows.net/" & #"Azure AD Tenant ID" & "/oauth2/token",
resource = "https://graph.microsoft.com",
tokenResponse = Json.Document(Web.Contents(token_uri,
[
Content = Text.ToBinary(Uri.BuildQueryString(
[
client_id = #"Azure Application Client ID",
resource = resource,
grant_type = "client_credentials",
client_secret = #"Azure Application Client Secret"
]
)),
Headers = [Accept = "application/json"], ManualStatusHandling = {400}
])),
access_token = tokenResponse[access_token],
Source = OData.Feed("https://graph.microsoft.com/v1.0/devices?$select=id, accountEnabled, approximateLastSignInDateTime, deviceId, displayName, isCompliant, isManaged, mdmAppId, onPremisesLastSyncDateTime, onPremisesSyncEnabled, operatingSystem, operatingSystemVersion, trustType, registeredOwners, registeredUsers", [ Authorization = "Bearer " & access_token ], [ ExcludedFromCacheKey = {"Authorization"}, ODataVersion = 4, Implementation = "2.0" ]),
#"Expanded registeredOwners" = Table.ExpandTableColumn(Source, "registeredOwners", {"id"}, {"id.1"}),
#"Remove columns" = Table.RemoveColumns(#"Expanded registeredOwners", Table.ColumnsOfType(#"Expanded registeredOwners", {type table, type record, type list, type nullable binary, type binary, type function}))
in
#"Remove columns"

2 REPLIES 2
v-angzheng-msft
Community Support
Community Support

Hi, @Anonymous 

We can still customize the lifetime of the access token by configuring the token lifetime policy.

$policy = New-AzureADPolicy -Definition @('{"TokenLifetimePolicy":{"Version":1,"AccessTokenLifetime":"00:15:00"}}') -DisplayName "WebPolicyScenario" -IsOrganizationDefault $false -Type "TokenLifetimePolicy"

Hope this helps.

 

 

Best Regards,
Community Support Team _ Zeon Zheng


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

Anonymous
Not applicable

@v-angzheng-msft  Thanks of the reply, I will check this and confirm to you.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.