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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

0

Power Query Advanced Editor Update Access Token with Refresh Token

Is it possible to update an access token that has expired with a refresh token using the advanced editor/ Power Query M? I ask the following because every time I go in, it asks you to revalidate the credentials and expires. I would like to know if the general idea would work or if I'd run into a dead end. Thanks in advance!

 

Scenario:

 

I have an access token from a 3rd party (Caspio) and they have it expire every 24 hours. They give you a refresh token to get a new access token when you'd like to refresh your data.

 

Can I use an if statement in the advanced editor where I see the general code below (I'm learning Power Query M so I'm kinda pseudo coding):

 

let

 

Check = Json.Document(Web.Contents("https://mycaspiodatabase/restapi/", [Headers=[Authorization="bearer myaccesstoken"]])),

Response = Check["Response"],

 

if Response <> "Active" then myNEWaccesstoken = Json.Document(Web.Contents("https://mycaspiodatabase/restapi/updateToken", [Headers=[Authorization="bearer myrefreshtoken"]])) else Source=Check,

 

if Response <> "Active" then Source=Json.Document(Web.Contents("https://mycaspiodatabase/restapi/", [Headers=[Authorization="bearer myNEWaccesstoken"]])),

 

in

   Source

Status: Delivered
Comments
v-yuezhe-msft
Employee

@ntaylor_carollo,

It is not a easy task to automatically get refresh token and use the token in Power Query. I would recommend you check Robert's reply in the similar thread below to create functions to implement the process.

https://stackoverflow.com/questions/40753188/google-oauth-refresh-tokens-in-power-query

Regards,
Lydia

v-yuezhe-msft
Employee
Status changed to: Delivered