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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
gbernardes
Frequent Visitor

New bearer token for each call

Hello 🙂 Can someone help me with this API call?

 

gbernardes_0-1652998302081.png

 

I need a NEW token for each line. When I refresh the function getToken it's refreshes ok, but when I invoke in the date tables it still the same for all rows.

 

Function:

 

() =>
let
  bodyToken = "{#(lf)    ""Usuario"":""xxxxxx"",#(lf)    ""Senha"":""xxxxxx"",#(lf)    ""NumeroSerialLoja"":""xxxxxx"",#(lf)    ""Chave"":""Serial Number""#(lf)    }",
  getToken = Json.Document(Web.Contents (
    "http://chefweb.chef.totvs.com.br/", [RelativePath="chefwebapi/api/Token/GerarToken",
    Headers=[#"Content-Type"="application/json"],
    Content=Text.ToBinary(bodyToken)
    ]
    )),
  token = getToken[Token]
  in
  token

 

 

Table with dates:

 

let
  days = Duration.Days(endDate - startDate),
  listDates = List.Generate(
() => 0,
each _<= days,
each _ +1,
each Date.AddDays(startDate,_)
),
  #"Converter em tabela" = Table.FromValue(listDates),
  #"Tipo de coluna alterado" = Table.TransformColumnTypes(#"Converter em tabela", {{"Value", type date}}),
  #"Função personalizada invocada" = Table.AddColumn(#"Tipo de coluna alterado", "Função personalizada invocada", each getToken())
in
  #"Função personalizada invocada"

 

4 REPLIES 4
gbernardes
Frequent Visitor

Description updated. Can someone help me?

Hi @gbernardes ,

Please review the following links, hope they can help you.

Refresh token api call

I stumbled over a similar problem as you last year. I solved my api connection by buidling a custom data connector.

https://github.com/Microsoft/DataConnectors

 

With the connector you have a lot of possibilitys for authentication handling:

see: https://docs.microsoft.com/en-us/power-query/handlingauthentication

 

The custom Connector can be attached to the data gatway from there the api calls are made.

 

This is not a really easy way for sure but may be a solution.


Power Query Advanced Editor Update Access Token with Refresh Token

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

Best Regards

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
dhruvinushah
Responsive Resident
Responsive Resident

How are you updating the value in the parameter? Does it refresh/update to show the new token value every time you make a new call?









@dhruvinushah Every time I refresh the table "getDados" the token refreshes. But only 1 time. I need the refresh for every row in the table.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.