Forum Discussion
Bokazoit
1 year agoContinued Contributor
Need help API with refresh token
Hi I am new to API and tried searching but did not get anything I could understand. I am trying to get data from a product called HR-On and it needs to retrieve a new token every hour or so: ...
- 1 year ago
I wrote this script:
let #"HR-On employees" = let // Parametre client_id = "xxx", client_secret = "yyy", api_url = "url", token_url = "token", // Obtain Authorization Credentials ObtainAuthorizationCredentials = Json.Document( Web.Contents(token_url, [ Content = Text.ToBinary("grant_type=client_credentials&client_id=" & client_id & "&client_secret=" & client_secret), Headers = [#"Content-Type" = "application/x-www-form-urlencoded"] ] ) ), refresh_token = ObtainAuthorizationCredentials[refresh_token], access_token = ObtainAuthorizationCredentials[access_token], // Brug token til at hente data Kilde = Json.Document( Web.Contents( api_url, [ Headers = [Authorization = "Bearer " & access_token] ] ) ), items = Kilde[items] in Kilde, items = #"HR-On employees"[items], #"Konverteret til tabel" = Table.FromList(items, Splitter.SplitByNothing(), null, null, ExtraValues.Error), #"Udvidet Column1" = Table.ExpandRecordColumn(#"Konverteret til tabel", "Column1", {"id", "companyAdmin", "leader", "systemUser", "archived", "picture", "systemFields", "customFields", "departments", "roles", "createdAt", "updatedAt", "customId"}, {"id", "companyAdmin", "leader", "systemUser", "archived", "picture", "systemFields", "customFields", "departments", "roles", "createdAt", "updatedAt", "customId"}) in #"Udvidet Column1"And now I get the data.
Bokazoit
1 year agoContinued Contributor
I wrote this script:
let
#"HR-On employees" = let
// Parametre
client_id = "xxx",
client_secret = "yyy",
api_url = "url",
token_url = "token",
// Obtain Authorization Credentials
ObtainAuthorizationCredentials = Json.Document(
Web.Contents(token_url,
[
Content = Text.ToBinary("grant_type=client_credentials&client_id=" & client_id & "&client_secret=" & client_secret),
Headers = [#"Content-Type" = "application/x-www-form-urlencoded"]
]
)
),
refresh_token = ObtainAuthorizationCredentials[refresh_token],
access_token = ObtainAuthorizationCredentials[access_token],
// Brug token til at hente data
Kilde = Json.Document(
Web.Contents(
api_url,
[
Headers = [Authorization = "Bearer " & access_token]
]
)
),
items = Kilde[items]
in
Kilde,
items = #"HR-On employees"[items],
#"Konverteret til tabel" = Table.FromList(items, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
#"Udvidet Column1" = Table.ExpandRecordColumn(#"Konverteret til tabel", "Column1", {"id", "companyAdmin", "leader", "systemUser", "archived", "picture", "systemFields", "customFields", "departments", "roles", "createdAt", "updatedAt", "customId"}, {"id", "companyAdmin", "leader", "systemUser", "archived", "picture", "systemFields", "customFields", "departments", "roles", "createdAt", "updatedAt", "customId"})
in
#"Udvidet Column1"
And now I get the data.