Forum Discussion
Incremental Refresh with API
- Anonymous1 year ago
Hi PedroModa,
Power BI won’t let your report refresh online if your Web.Contents uses a URL that’s built using text joined together while the report is running. That’s because Power BI doesn’t know in advance what websites or addresses it might try to access.
To fix this, you should separate the main part of the URL (the base) from the parts that change (like dates or filters). You can do that by using the Query and RelativePath options in Web.Contents, like below.
(DataInicio as text, DataFim as text) => let Fonte = Json.Document( Web.Contents( "https://api.example.com", // Static base URL [ RelativePath = "endpoint", // Static relative path Query = [ DATAINICIO_D = DataInicio, DATAFINAL_D = DataFim], Headers = [ #"Authorization" = "Bearer YOUR_TOKEN" // Or whatever is required ]])) in Fonte
DataNinja777 Could you help me, please?
I created the query as you mentioned, but it's giving me an error that I can't resolve. It says that the DATA_CRIACAO column was not found, but it is in the table, I'm confused.
This is my funcion:
(DataInicio as text, DataFim as text) =>
let
Fonte = Json.Document(
Web.Contents(
"URLDAMINHAAPI",
[
RelativePath = "RELATIVEPATHDAMINHAAPI",
Query = [
parameters = "DATAINICIO_D=" & DataInicio & ";DATAFINAL_D=" & DataFim
]
]
)
)
in
Fonte
This is my query M:
let
StartDateText = DateTime.ToText(RangeStart, "yyyy-MM-dd"),
EndDateText = DateTime.ToText(RangeEnd, "yyyy-MM-dd"),
Fonte = fx_fPartida(StartDateText, EndDateText),
#"Convertido em Tabela" = Table.FromRecords(Fonte),
#"Tipo Alterado1" = Table.TransformColumnTypes(#"Convertido em Tabela", {{"DATA_CRIACAO", type datetimezone}}),
#"Tipo Alterado" = Table.TransformColumnTypes(#"Tipo Alterado1", {
{"CODCOLIGADA", type text},
{"COLI-CODLOTE", type text},
{"COLI-IDPARTIDA", type text},
{"DATA", type datetimezone},
{"IDPARTIDA", type text},
{"COLI-CREDITO", type text},
{"COLI-DEBITO", type text},
{"DATA_CRIACAO", type datetime}
}),
#"DATA como Date" = Table.TransformColumnTypes(#"Tipo Alterado", {{"DATA", type date}}),
#"Linhas Válidas" = Table.SelectRows(#"DATA como Date", each ([IDPARTIDA] <> null))
in
#"Linhas Válidas"